Skip to content

Commit

Permalink
Fix token refresh in oAuthAccessToken Build method
Browse files Browse the repository at this point in the history
declarie requestUrl and httpget as private variables

initiailize in each build method with the correct "createParamters" method to set oauth params depending on if it's the first time you get a token or when refreshing a token.

bumped to version 1.0.4
  • Loading branch information
SidneyAllen committed May 8, 2018
1 parent 49f70a4 commit a9011c5
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 23 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Add this dependency and repository to your POM.xml
<dependency>
<groupId>com.xero</groupId>
<artifactId>xero-java-sdk</artifactId>
<version>1.0.3</version>
<version>1.0.4</version>
</dependency>

<repositories>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>com.xero</groupId>
<artifactId>xero-java-sdk</artifactId>
<packaging>jar</packaging>
<version>1.0.3</version>
<version>1.0.4</version>
<name>Xero-Java SDK</name>
<url>http://maven.apache.org</url>
<dependencies>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/xero/api/JsonConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public String getAccessTokenUrl() {

@Override
public String getUserAgent() {
return USER_AGENT + " " + CONSUMER_KEY + " [Xero-Java-1.0.3]";
return USER_AGENT + " " + CONSUMER_KEY + " [Xero-Java-1.0.4]";
}

@Override
Expand Down
52 changes: 32 additions & 20 deletions src/main/java/com/xero/api/OAuthAccessToken.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public class OAuthAccessToken {
private String tempTokenSecret;
private int connectTimeout = 20;
private int readTimeout = 20;
private GenericUrl requestUrl;
private HttpGet httpget;

public OAuthAccessToken(Config config) {
this(config, new ConfigBasedSignerFactory(config));
Expand All @@ -50,36 +52,46 @@ public OAuthAccessToken build(String verifier, String tempToken, String tempToke
this.tempToken = tempToken;
this.tempTokenSecret = tempTokenSecret;
this.connectTimeout = config.getConnectTimeout() * 1000;
this.readTimeout = config.getReadTimeout() * 1000;
this.readTimeout = config.getReadTimeout() * 1000;

httpclient = new XeroHttpContext(config).getHttpClient();

httpclient = new XeroHttpContext(config).getHttpClient();

requestUrl = new GenericUrl(this.config.getAccessTokenUrl());
httpget = new HttpGet(this.config.getAccessTokenUrl());

this.createParameters().intercept(httpget,requestUrl);

return this;
}

public OAuthAccessToken build() throws IOException {
this.connectTimeout = config.getConnectTimeout() * 1000;
this.readTimeout = config.getReadTimeout() * 1000;
httpclient = new XeroHttpContext(config).getHttpClient();

requestUrl = new GenericUrl(this.config.getAccessTokenUrl());
httpget = new HttpGet(this.config.getAccessTokenUrl());

this.createRefreshParameters().intercept(httpget,requestUrl);

return this;
}

public boolean execute() throws IOException {
GenericUrl requestUrl = new GenericUrl(this.config.getAccessTokenUrl());

HttpGet httpget = new HttpGet(this.config.getAccessTokenUrl());

RequestConfig.Builder requestConfig = RequestConfig.custom()
.setConnectTimeout(connectTimeout)
.setConnectionRequestTimeout(readTimeout)
.setSocketTimeout(connectTimeout);

//Proxy Service Setup - unable to fully test as we don't have a proxy
// server to test against.
if(!"".equals(config.getProxyHost()) && config.getProxyHost() != null) {
int port = (int) (config.getProxyPort() == 80 && config.getProxyHttpsEnabled() ? 443 : config.getProxyPort());
HttpHost proxy = new HttpHost(config.getProxyHost(), port, config.getProxyHttpsEnabled() ? "https" : "http");
requestConfig.setProxy(proxy);
}
this.createParameters().intercept(httpget,requestUrl);

RequestConfig.Builder requestConfig = RequestConfig.custom()
.setConnectTimeout(connectTimeout)
.setConnectionRequestTimeout(readTimeout)
.setSocketTimeout(connectTimeout);

//Proxy Service Setup - unable to fully test as we don't have a proxy
// server to test against.
if(!"".equals(config.getProxyHost()) && config.getProxyHost() != null) {
int port = (int) (config.getProxyPort() == 80 && config.getProxyHttpsEnabled() ? 443 : config.getProxyPort());
HttpHost proxy = new HttpHost(config.getProxyHost(), port, config.getProxyHttpsEnabled() ? "https" : "http");
requestConfig.setProxy(proxy);
}

httpget.setConfig(requestConfig.build());

try {
Expand Down

0 comments on commit a9011c5

Please sign in to comment.