Xero - beautiful accounting software

Xero Developer Help Center

Xero Developer Community

Community > Wrapper libraries >

Getting REFRESH EXCEPTION from xero java sdk

Started by raga d -   in Wrapper libraries

I have implemented new Xero java sdk. It was working fine till yesterday. Now i am getting "REFRESH EXCEPTION" with the following code. Please let me know what was the issue. I am using xero-java-sdk-0.4.7 version.


// Swap your temp token for 30 oauth token
OAuthAccessToken accessToken = new OAuthAccessToken(config);
String tempToken = storage.get(request, "tempToken");
String tempTokenSecret = storage.get(request, "tempTokenSecret");

accessToken.build(verifier, tempToken, tempTokenSecret).execute();

accessToken.isSuccess() // Always returning false.
Hi Raga,

If you are getting a refresh exception - can you get the problem and advice and post them here?



API Team (Not monitored)  

// Swap your temp token for 30 oauth token
OAuthAccessToken accessToken = new OAuthAccessToken(config);
String tempToken = storage.get(request, "tempToken");
String tempTokenSecret = storage.get(request, "tempTokenSecret");

accessToken.build(verifier, tempToken, tempTokenSecret).execute();
System.out.println("Access Token Success : " + accessToken.isSuccess());
System.out.println("getProblem : " + accessToken.getProblem());
System.out.println("getAdvice : " + accessToken.getAdvice());

---------------- Output --------------------------
Access Token Success : false
getProblem : null
getAdvice : null

raga d  


Sounds like you'll need to do some digging on your own with this one.

Update your pom.xml to get SDK version ""

I've uncommented the line in the catch block for System.out.println("HttpException" + e.toString());

Let's see what that tells us.


Sidney Maestre (Community Manager)  

Hi Sid,

We are just running you example which was given in the github(https://github.com/XeroAPI/Xero-Java).
After running with latest version of xero java sdk. we got the following exceptions

Console output:
Saving tokensAug 18, 2017 12:17:35 PM org.apache.coyote.http11.AbstractHttp11Processor process
INFO: Error parsing HTTP request header
Note: further occurrences of HTTP header parsing errors will be logged at DEBUG level.
java.lang.IllegalArgumentException: Invalid character found in method name. HTTP method names must be tokens
at org.apache.coyote.http11.InternalInputBuffer.parseRequestLine(InternalInputBuffer.java:136)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1028)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
HttpExceptioncom.google.api.client.http.HttpResponseException: 400 Bad Request

if you want to check my sample app. You can download from following link

raga d  

Hi Raga,

Thanks for sharing your code - Looking at your sample app - you have not set your ConsumerKey, ConsumerSecret, CallbackURL, etc.

File located in the /resources/config.json

I suggest watching the video where I explain how to setup the sample app.

You can jump 4 minutes into the video to see how I create a config.json

If you are setting the key and secret (and just removed them before sharing your code) - then please let me know the following .....

1. What type of App are you working with in this demo (Public, Private or Partner)
2. At what point you're hitting the error. Is it during the RequestToken call? Or are you hitting an error on the callback from Xero?



Sidney Maestre (Community Manager)  

Hi Sid,

Yes, I have removed the client and secret keys before sharing the code.

1) Right now i am working public type.
2) I got issue with the following code which is in CallbackServlet. Here accessToken.isSuccess() is always returning false.

// Swap your temp token for 30 oauth token
OAuthAccessToken accessToken = new OAuthAccessToken(config);

request.getRequestDispatcher("index.jsp").forward(request, response);
}else {
// DEMONSTRATION ONLY - Store in Cookie - you can extend TokenStorage
// and implement the save() method for your database
request.getRequestDispatcher("callback.jsp").forward(request, response);

raga d  

Hi Raga,

Very strange - I found that changing User-Agent in the config.json file and removing the dashes - something like "XeroJavaSidExample" and changing my callbackURL to be http (not https) as you had it allowed me to run your code successfully.

The User-Agent appeared to be the cause of the HttpResponseException - HTTP Error 400. The request is badly formed in the oAuthAccessToken class.

Let me know if this helps solve your issue.

Sidney Maestre (Community Manager)  

Hi Sid,
We have upgraded new sdk. Everything working fine. But we are unable to get Organisations. Following is the code what i am using.
XeroClient xeroClient = new XeroClient();
List<Organisation> organisationList = xeroClient.getOrganisations();

I have checked both access token and secret are active. But still i am getting the following exception.
It trows error: com.xero.api.XeroApiException: token_rejected - Token has not been provided with root cause com.xero.api.XeroApiException: token_rejected - Token has not been provided at com.xero.api.XeroClient.newApiException(XeroClient.java:146) at com.xero.api.XeroClient.convertException(XeroClient.java:165) at com.xero.api.XeroClient.get(XeroClient.java:192) at com.xero.api.XeroClient.get(XeroClient.java:174) at com.xero.api.XeroClient.getOrganisations(XeroClient.java:1059)

raga d  

Hi Raga,

It's been a while .... Looks like you sorted out the Refresh Token issue.

First thing I'd recommend is wrapping your API calls in a try/catch block so you can log or display the error code and message.

try {
List<Organisation> newOrganisation = client.getOrganisations();
System.out.println("Organisation - Name : " + newOrganisation.get(0).getName());
} catch (XeroApiException e) {

Second, I'd recommend Logging you access token to make sure you are in passing a token.

From our dev center ....

Token has not been provided ......

oauth_problem=token_rejected&oauth_problem_advice=Token has not been provided

If for some reason, the access_token value is not being received by the API. The value may be empty or the access_token parameter may not be passed in at all.

Resolution: Validate you are storing and handling access tokens correctly. If you are using a wrapper library or code sample, try to debug the access_token values as they are being sent to the API.


Sidney Maestre (Community Manager)  

Hi Sid,

I am unable to get recently updated contacts please help me out. I am sending the (modifiedAfter) date as input to the getContacts method for me it was returning list as empty. please look at the code what I have used.

Date modifiedAfter = new Date(1511429587000L);
String pageNo = "1";
xeroClient.getContacts(modifiedAfter, null, "updatedDateUTC DESC", pageNo);

raga d