From a9011c55c2590fc456d4b11f9933163ca4871ade Mon Sep 17 00:00:00 2001 From: SidneyAllen Date: Tue, 8 May 2018 15:34:46 -0700 Subject: [PATCH] Fix token refresh in oAuthAccessToken Build method 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 --- README.md | 2 +- pom.xml | 2 +- src/main/java/com/xero/api/JsonConfig.java | 2 +- .../java/com/xero/api/OAuthAccessToken.java | 52 ++++++++++++------- 4 files changed, 35 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 6114c020..62de0ffb 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ Add this dependency and repository to your POM.xml com.xero xero-java-sdk - 1.0.3 + 1.0.4 diff --git a/pom.xml b/pom.xml index e48e6de6..91cbbe5d 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.xero xero-java-sdk jar - 1.0.3 + 1.0.4 Xero-Java SDK http://maven.apache.org diff --git a/src/main/java/com/xero/api/JsonConfig.java b/src/main/java/com/xero/api/JsonConfig.java index 1e089815..9b1d3b8a 100644 --- a/src/main/java/com/xero/api/JsonConfig.java +++ b/src/main/java/com/xero/api/JsonConfig.java @@ -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 diff --git a/src/main/java/com/xero/api/OAuthAccessToken.java b/src/main/java/com/xero/api/OAuthAccessToken.java index d82ff776..39405147 100644 --- a/src/main/java/com/xero/api/OAuthAccessToken.java +++ b/src/main/java/com/xero/api/OAuthAccessToken.java @@ -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)); @@ -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 {