domo-java-sdk icon indicating copy to clipboard operation
domo-java-sdk copied to clipboard

API did not work since 28 Nov 2018

Open TokitsuMaitsuru opened this issue 7 years ago • 1 comments

Hi. My codes for exporting dataset as csv file were performing correctly until since 28 Nov 2018. But now it is in trouble with the follow error message:


Exception in thread "main" com.domo.sdk.request.RequestException: Error making request url:https://api.domo.com/v1/datasets/b56ef383-cbb4-4b94-bb14-06c89b0b193c/data?includeHeader=true responseBody:<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>Error 406 Not Acceptable</title>
</head>
<body><h2>HTTP ERROR 406</h2>
<p>Problem accessing /error. Reason:
<pre>    Not Acceptable</pre></p><h3>Caused by:</h3><pre>com.domo.bedrock.service.exception.UnauthorizedException: Full authentication is required to access this resource
	at com.domo.gateway.config.security.OAuthAuthenticationProvider.values(OAuthAuthenticationProvider.java:39)
	at com.domo.gateway.config.security.OAuthAuthenticationProvider.getCustomer(OAuthAuthenticationProvider.java:48)
	at com.domo.gateway.config.security.OAuthLoggingRequestFilter.doFilterInternal(OAuthLoggingRequestFilter.java:50)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
	at org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationProcessingFilter.doFilter(OAuth2AuthenticationProcessingFilter.java:176)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
	at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:116)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
	at org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:66)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
	at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:105)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
	at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:56)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
	at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:214)
	at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:177)
	at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:347)
	at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:263)
	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652)
	at com.domo.bedrock.maestro.web.ServiceLogFilter.doFilterInternal(ServiceLogFilter.java:158)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652)
	at com.domo.gateway.config.security.HttpRedirectionDetectionFilter.doFilterInternal(HttpRedirectionDetectionFilter.java:61)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652)
	at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652)
	at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:109)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652)
	at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:93)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652)
	at org.springframework.boot.actuate.autoconfigure.MetricsFilter.doFilterInternal(MetricsFilter.java:106)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652)
	at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652)
	at org.springframework.web.filter.CorsFilter.doFilterInternal(CorsFilter.java:96)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652)
	at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:585)
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
	at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:577)
	at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:223)
	at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1127)
	at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515)
	at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)
	at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1061)
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
	at org.eclipse.jetty.server.handler.StatisticsHandler.handle(StatisticsHandler.java:159)
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
	at org.eclipse.jetty.server.Server.handle(Server.java:499)
	at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:311)
	at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:258)
	at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:544)
	at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635)
	at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555)
	at java.lang.Thread.run(Thread.java:748)
</pre>
<hr><i><small>Powered by Jetty://</small></i><hr/>

</body>
</html>

	at com.domo.sdk.request.Transport.getCsv(Transport.java:110)
	at com.domo.sdk.datasets.DataSetClient.exportData(DataSetClient.java:151)
	at ExportDataExample.dataSetClient_smokeTest(ExportDataExample.java:96)
	at test.main(test.java:17)

Since I did not do any change to the code, I suppose there may be some changes in the api. Do you have any suggetions?

Thank you.

TokitsuMaitsuru avatar Nov 29 '18 01:11 TokitsuMaitsuru

Here are my codes. It worked well till 28th Nov. 2018, but now it throw the error message above. Thank you very much for checking it.

test.java

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;

public class test {

	public static void main(String[] args) throws IOException{

		OutputStream outputStream = null;
		int errorFlag = 1;

		ExportDataExample exData = new ExportDataExample();
		try{
			exData.dataSetClient_smokeTest();
		}catch(IOException e){
			System.out.println(e.toString());
			outputStream = new FileOutputStream("error_in_jar" + ".txt");		
			outputStream.write(e.toString().getBytes("SJIS"));
			outputStream.close();
			errorFlag =0;
		}
		if(errorFlag ==1){
			
//			File file2 = new File("jar_is_finished.txt");
			outputStream = new FileOutputStream("jar_is_finished" + ".txt");		
			outputStream.write("Work finished.".getBytes("SJIS"));
			outputStream.close();
			errorFlag =0;
		}
		System.out.println("Finish");
	}
}

ExampleBase.java

import static com.domo.sdk.request.Scope.*;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;

import org.junit.Before;

import com.domo.sdk.DomoClient;
import com.domo.sdk.request.Config;

import okhttp3.logging.HttpLoggingInterceptor;

public class ExampleBase {

  public DomoClient client;

  public static final String MY_CLIENT_ID = "***";
  public static final String MY_CLIENT_SECRET = "***";

  public static final String MY_DOMO_PAGE = "api.domo.com";

  @Before
  public void setup() {
    Config config = Config.with()
            .clientId(MY_CLIENT_ID)
            .clientSecret(MY_CLIENT_SECRET)
            .apiHost(MY_DOMO_PAGE)
            .useHttps(true)
            .scope(USER, DATA)
            .httpLoggingLevel(HttpLoggingInterceptor.Level.BODY)
            .build();

    client = DomoClient.create(config);

  }


  public static String convertStreamToString(java.io.InputStream is) throws UnsupportedEncodingException {

	  /**
	   * Method 2
	   */
	  ByteArrayOutputStream baos = new ByteArrayOutputStream();
	  int i;
	  try {
		while ((i = is.read()) != -1) {
		      baos.write(i);
		  }
	  } catch (IOException e) {
		// TODO 自動生成された catch ブロック
		e.printStackTrace();
	  }
	  String x = null;
	  return baos.toString("UTF-8");
  }
}

ExportDataExample.java

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Calendar;

import com.domo.sdk.datasets.DataSetClient;
import com.domo.sdk.datasets.model.DataSet;

public class ExportDataExample extends ExampleBase{

	static String[] workLines = new String[500];
	static String[] dataSetInfo = new String[8]; // 0: flag; 1: -; 2: file name, 3: URL, 4: dataset Id, 5: resource, 6: save route 7: -


	public void dataSetClient_smokeTest() throws IOException {
		String flag = null;
		String dataSetId = null;
		String dataSetName = null;
		String saveRoute = null;
		InputStream inputStream = null;
		OutputStream outputStream = null;

		setup();
		DataSetClient dsClient = client.dataSetClient();

		for (int i = 1; i <= 1; i++)
		{

			System.out.println("----------------------------------");
			dataSetId = "ab97ef4a-b3e6-4ff9-9ec9-fba53921e5e9";
			dataSetName = "ronzan_yomi_update_other";
//			TODO: change the saving route
			saveRoute = "\\\\172.16.0.232\\CoffeeCrazy3\\その他\\受け渡し用\\RS顧問設定・成約数\\";
			flag = dataSetInfo[0];

			if(dataSetId.length() == 62){
				System.out.println("Download is finished");
				return ;
			} else{
				System.out.println(dataSetId.length());

			}

	    File file = new File(saveRoute.substring(0,saveRoute.length()-1));
            if (!file.exists()) {
            	file.mkdirs();
            	}

			//Export DS
			inputStream = dsClient.exportData(dataSetId,true);
			String data = convertStreamToString(inputStream);
			inputStream.close();


			outputStream = new FileOutputStream(saveRoute + dataSetName + ".csv");

			System.out.print(saveRoute + dataSetName + ".csv" + "\n");
			outputStream.write(data.getBytes("SJIS"));
			outputStream.close();

		}

	}


	private String setupDataSet(DataSetClient dsClient) {
		//Create DS
		DataSet ds = CreateExample.create(dsClient);
		System.out.println("Created:"+ds);

		//Import DS
		String csvInput = "\"Pythagoras\"\n" +
						"\"Alan Turing\"\n" +
						"\"George Boole\"";
		dsClient.importData(ds.getId(), csvInput);

		return ds.getId();
	}

	private void getDataSetRows(DataSetClient dsClient) throws IOException{
		String dataSetId = "2d30dee7-ff43-43c0-b3ad-9ed855198586";
		dsClient.get(dataSetId);

		//Export DS
		InputStream stream = dsClient.exportData(dataSetId,true);
		String data = convertStreamToString(stream);
		stream.close();
		workLines = data.split("\n");
		System.out.println(workLines.length);
	}

	private void getDataSetInfo(String dataSetRow){
		dataSetInfo = dataSetRow.split(",");
	}


	/**
	 * Judge whether the data set is updated
	 * @param data data from csv
	 * @return true -> updated in this month
	 */
	private boolean isUpdated(String data){
		String updateYear = null;
		String updateMonth = null;
		Calendar cal = Calendar.getInstance();

		updateYear = data.substring(data.length() - 20, data.length() - 16);
		updateMonth = data.substring(data.length() - 15, data.length() - 13);
		System.out.println("Latest update date: " + updateYear+"-"+ updateMonth);
		System.out.println("Date now: " + String.valueOf(cal.get(Calendar.YEAR)+"-"+ String.valueOf(cal.get(Calendar.MONTH)+1)));
		if(Integer.parseInt(updateYear) == cal.get(Calendar.YEAR) && Integer.parseInt(updateMonth) == cal.get(Calendar.MONTH)+1){
			return true;
		} else{
			return false;
		}
	}
}

TokitsuMaitsuru avatar Dec 09 '18 23:12 TokitsuMaitsuru