Skip to content

Commit 6af821d

Browse files
committed
[fix] Configure the DefaultAsyncHttpClient to follow redirects
It seems that Zendesk started to emit some redirects when iterating on multi-pages results. Maybe because we use a custom domain? The problem started yesterday. ``` Exception in thread "main" org.zendesk.client.v2.ZendeskResponseException: HTTP/302: Found - You are being redirected to https://foo.zendesk.com/access/return_to?challenge=XXXXXXX&locale=en-US-x-1&return_to=https%3A%2F%2Fsupport.foo.com%2Fapi%2Fv2%2Ftickets%2F210487%2Fcomments.json%3Fsort_order%3Dasc at org.zendesk.client.v2.Zendesk.complete(Zendesk.java:2539) at org.zendesk.client.v2.Zendesk.access$1400(Zendesk.java:100) at org.zendesk.client.v2.Zendesk$PagedIterable$PagedIterator.hasNext(Zendesk.java:2805) ```
1 parent d80090b commit 6af821d

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/main/java/org/zendesk/client/v2/Zendesk.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import org.asynchttpclient.AsyncCompletionHandler;
1212
import org.asynchttpclient.AsyncHttpClient;
1313
import org.asynchttpclient.DefaultAsyncHttpClient;
14+
import org.asynchttpclient.DefaultAsyncHttpClientConfig;
1415
import org.asynchttpclient.ListenableFuture;
1516
import org.asynchttpclient.Realm;
1617
import org.asynchttpclient.Request;
@@ -102,6 +103,8 @@
102103
*/
103104
public class Zendesk implements Closeable {
104105
private static final String JSON = "application/json; charset=UTF-8";
106+
private static final DefaultAsyncHttpClientConfig DEFAULT_ASYNC_HTTP_CLIENT_CONFIG =
107+
new DefaultAsyncHttpClientConfig.Builder().setFollowRedirect(true).build();
105108
private final boolean closeClient;
106109
private final AsyncHttpClient client;
107110
private final Realm realm;
@@ -147,7 +150,7 @@ private Zendesk(AsyncHttpClient client, String url, String username, String pass
147150
this.logger = LoggerFactory.getLogger(Zendesk.class);
148151
this.closeClient = client == null;
149152
this.oauthToken = null;
150-
this.client = client == null ? new DefaultAsyncHttpClient() : client;
153+
this.client = client == null ? new DefaultAsyncHttpClient(DEFAULT_ASYNC_HTTP_CLIENT_CONFIG) : client;
151154
this.url = url.endsWith("/") ? url + "api/v2" : url + "/api/v2";
152155
if (username != null) {
153156
this.realm = new Realm.Builder(username, password)
@@ -169,7 +172,7 @@ private Zendesk(AsyncHttpClient client, String url, String oauthToken, Map<Strin
169172
this.logger = LoggerFactory.getLogger(Zendesk.class);
170173
this.closeClient = client == null;
171174
this.realm = null;
172-
this.client = client == null ? new DefaultAsyncHttpClient() : client;
175+
this.client = client == null ? new DefaultAsyncHttpClient(DEFAULT_ASYNC_HTTP_CLIENT_CONFIG) : client;
173176
this.url = url.endsWith("/") ? url + "api/v2" : url + "/api/v2";
174177
if (oauthToken != null) {
175178
this.oauthToken = oauthToken;

0 commit comments

Comments
 (0)