List of usage examples for org.apache.http.client CircularRedirectException CircularRedirectException
public CircularRedirectException()
From source file:com.klarna.checkout.stubs.HttpClientStub.java
/** * Stubbed Execute implementation.//ww w .jav a2 s . c o m * * @param <T> The class ResponseHandler operates on * @param hur HttpUriRequest object * @param rh ResponseHandler object * @param hc HttpContext holder * * @return ResponseHandler result * * @throws IOException never */ @Override public <T> T execute(final HttpUriRequest hur, final ResponseHandler<? extends T> rh, final HttpContext hc) throws IOException { this.httpUriReq = hur; List<Integer> redirects = new ArrayList(); redirects.add(301); redirects.add(302); redirects.add(303); this.visited.clear(); if (this.httpUriReq instanceof HttpEntityEnclosingRequest) { try { this.httpUriReq = new EntityEnclosingRequestWrapper((HttpEntityEnclosingRequest) hur); } catch (ProtocolException ex) { throw new IOException(ex); } } int status; do { try { for (HttpRequestInterceptor hri : requestInterceptors) { hri.process(this.httpUriReq, hc); } } catch (HttpException ex) { throw new ClientProtocolException(ex); } if (!this.visited.add(this.httpUriReq.getURI())) { throw new ClientProtocolException(new CircularRedirectException()); } this.lastResponse = this.getResponse(); if (this.lastResponse.getStatusLine().getStatusCode() < 400) { fixData(); } try { for (HttpResponseInterceptor hri : responseInterceptors) { hri.process(this.lastResponse, hc); } } catch (HttpException ex) { throw new ClientProtocolException(ex); } status = this.lastResponse.getStatusLine().getStatusCode(); Header location = this.lastResponse.getLastHeader("Location"); if (location != null) { this.httpUriReq = new HttpGet(location.getValue()); } } while (redirects.contains(status)); if (this.data.containsKey("test")) { ByteArrayInputStream bis = new ByteArrayInputStream(JSONObject.toJSONString(data).getBytes()); this.lastResponse.setEntity(new InputStreamEntity(bis, bis.available())); } return rh.handleResponse(this.lastResponse); }