Skip to content

Commit a9011c5

Browse files
committed
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
1 parent 49f70a4 commit a9011c5

File tree

4 files changed

+35
-23
lines changed

4 files changed

+35
-23
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Add this dependency and repository to your POM.xml
1616
<dependency>
1717
<groupId>com.xero</groupId>
1818
<artifactId>xero-java-sdk</artifactId>
19-
<version>1.0.3</version>
19+
<version>1.0.4</version>
2020
</dependency>
2121

2222
<repositories>

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<groupId>com.xero</groupId>
55
<artifactId>xero-java-sdk</artifactId>
66
<packaging>jar</packaging>
7-
<version>1.0.3</version>
7+
<version>1.0.4</version>
88
<name>Xero-Java SDK</name>
99
<url>http://maven.apache.org</url>
1010
<dependencies>

src/main/java/com/xero/api/JsonConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public String getAccessTokenUrl() {
114114

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

120120
@Override

src/main/java/com/xero/api/OAuthAccessToken.java

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ public class OAuthAccessToken {
3535
private String tempTokenSecret;
3636
private int connectTimeout = 20;
3737
private int readTimeout = 20;
38+
private GenericUrl requestUrl;
39+
private HttpGet httpget;
3840

3941
public OAuthAccessToken(Config config) {
4042
this(config, new ConfigBasedSignerFactory(config));
@@ -50,36 +52,46 @@ public OAuthAccessToken build(String verifier, String tempToken, String tempToke
5052
this.tempToken = tempToken;
5153
this.tempTokenSecret = tempTokenSecret;
5254
this.connectTimeout = config.getConnectTimeout() * 1000;
53-
this.readTimeout = config.getReadTimeout() * 1000;
55+
this.readTimeout = config.getReadTimeout() * 1000;
5456

55-
httpclient = new XeroHttpContext(config).getHttpClient();
56-
57+
httpclient = new XeroHttpContext(config).getHttpClient();
58+
59+
requestUrl = new GenericUrl(this.config.getAccessTokenUrl());
60+
httpget = new HttpGet(this.config.getAccessTokenUrl());
61+
62+
this.createParameters().intercept(httpget,requestUrl);
63+
5764
return this;
5865
}
5966

6067
public OAuthAccessToken build() throws IOException {
68+
this.connectTimeout = config.getConnectTimeout() * 1000;
69+
this.readTimeout = config.getReadTimeout() * 1000;
6170
httpclient = new XeroHttpContext(config).getHttpClient();
71+
72+
requestUrl = new GenericUrl(this.config.getAccessTokenUrl());
73+
httpget = new HttpGet(this.config.getAccessTokenUrl());
74+
75+
this.createRefreshParameters().intercept(httpget,requestUrl);
76+
6277
return this;
6378
}
6479

6580
public boolean execute() throws IOException {
66-
GenericUrl requestUrl = new GenericUrl(this.config.getAccessTokenUrl());
67-
68-
HttpGet httpget = new HttpGet(this.config.getAccessTokenUrl());
69-
70-
RequestConfig.Builder requestConfig = RequestConfig.custom()
71-
.setConnectTimeout(connectTimeout)
72-
.setConnectionRequestTimeout(readTimeout)
73-
.setSocketTimeout(connectTimeout);
74-
75-
//Proxy Service Setup - unable to fully test as we don't have a proxy
76-
// server to test against.
77-
if(!"".equals(config.getProxyHost()) && config.getProxyHost() != null) {
78-
int port = (int) (config.getProxyPort() == 80 && config.getProxyHttpsEnabled() ? 443 : config.getProxyPort());
79-
HttpHost proxy = new HttpHost(config.getProxyHost(), port, config.getProxyHttpsEnabled() ? "https" : "http");
80-
requestConfig.setProxy(proxy);
81-
}
82-
this.createParameters().intercept(httpget,requestUrl);
81+
82+
RequestConfig.Builder requestConfig = RequestConfig.custom()
83+
.setConnectTimeout(connectTimeout)
84+
.setConnectionRequestTimeout(readTimeout)
85+
.setSocketTimeout(connectTimeout);
86+
87+
//Proxy Service Setup - unable to fully test as we don't have a proxy
88+
// server to test against.
89+
if(!"".equals(config.getProxyHost()) && config.getProxyHost() != null) {
90+
int port = (int) (config.getProxyPort() == 80 && config.getProxyHttpsEnabled() ? 443 : config.getProxyPort());
91+
HttpHost proxy = new HttpHost(config.getProxyHost(), port, config.getProxyHttpsEnabled() ? "https" : "http");
92+
requestConfig.setProxy(proxy);
93+
}
94+
8395
httpget.setConfig(requestConfig.build());
8496

8597
try {

0 commit comments

Comments
 (0)