List of usage examples for org.apache.http.client HttpResponseException HttpResponseException
public HttpResponseException(final int statusCode, final String s)
From source file:com.cognifide.aet.common.JsonResponseHandler.java
@Override public T handleResponse(HttpResponse httpResponse) throws IOException { StatusLine statusLine = httpResponse.getStatusLine(); if (statusLine.getStatusCode() == 200) { String result = EntityUtils.toString(httpResponse.getEntity(), MIME.UTF8_CHARSET); Gson gson = new Gson(); return gson.fromJson(result, resultClass); } else {/*from w w w .ja v a 2 s . co m*/ throw new HttpResponseException(statusLine.getStatusCode(), statusLine.getReasonPhrase()); } }
From source file:ch.cyberduck.core.onedrive.OneDriveExceptionMappingService.java
@Override public BackgroundException map(final OneDriveAPIException failure) { if (failure.getResponseCode() > 0) { final StringAppender buffer = new StringAppender(); buffer.append(failure.getMessage()); buffer.append(failure.getErrorMessage()); return new HttpResponseExceptionMappingService() .map(new HttpResponseException(failure.getResponseCode(), buffer.toString())); }/*from ww w.j a v a 2 s.c o m*/ if (ExceptionUtils.getRootCause(failure) instanceof IOException) { return new DefaultIOExceptionMappingService().map((IOException) ExceptionUtils.getRootCause(failure)); } return new InteroperabilityException(failure.getMessage(), failure); }
From source file:me.xiaopan.android.gohttp.StringHttpResponseHandler.java
@Override public Object handleResponse(HttpRequest httpRequest, HttpResponse httpResponse) throws Throwable { if (!(httpResponse.getStatusLine().getStatusCode() > 100 && httpResponse.getStatusLine().getStatusCode() < 300)) { throw new HttpResponseException(httpResponse.getStatusLine().getStatusCode(), httpResponse.getStatusLine().getStatusCode() + "" + httpRequest.getUrl()); }//from www. j av a2 s . c o m HttpEntity httpEntity = httpResponse.getEntity(); if (httpEntity == null) { throw new HttpResponseException(httpResponse.getStatusLine().getStatusCode(), "HttpEntity is null"); } return toString(httpRequest, httpEntity, "UTF-8"); }
From source file:org.cvasilak.jboss.mobile.admin.net.JBossResponseHandler.java
public String handleResponse(final HttpResponse response) throws HttpResponseException, IOException { StatusLine statusLine = response.getStatusLine(); if (statusLine.getStatusCode() >= 300 && statusLine.getStatusCode() < 500) { throw new HttpResponseException(statusLine.getStatusCode(), statusLine.getReasonPhrase()); }/*from ww w . j av a2 s . c o m*/ HttpEntity entity = response.getEntity(); return entity == null ? null : EntityUtils.toString(entity); }
From source file:org.apache.droids.protocol.http.AdvancedHttpProtocol.java
@Override public AdvancedManagedContentEntity load(URI uri) throws IOException { HttpGet httpget = new HttpGet(uri); HttpResponse response = getHttpClient().execute(httpget); StatusLine statusline = response.getStatusLine(); if (statusline.getStatusCode() >= HttpStatus.SC_BAD_REQUEST) { httpget.abort();/*from w ww . j a v a2 s . c o m*/ throw new HttpResponseException(statusline.getStatusCode(), statusline.getReasonPhrase()); } HttpEntity entity = response.getEntity(); if (entity == null) { // Should _almost_ never happen with HTTP GET requests. throw new ClientProtocolException("Empty entity"); } long maxlen = getHttpClient().getParams().getLongParameter(DroidsHttpClient.MAX_BODY_LENGTH, 0); return new AdvancedHttpContentEntity(entity, response.getAllHeaders(), maxlen); }
From source file:com.github.mfriedenhagen.artifactorygo.StatusCodeCodeLessThanScMultipleChoicesResponseHandler.java
/** * Checks that the returncode is in the range of 200 < rc < 300. * * @param response whose rc is validated. * @return the entity of the response.//from w w w . jav a 2 s .c o m * @throws IOException when the rc > 300 and swallowing the response body has a problem.. */ protected final HttpEntity returnEntityWhenStatusValid(HttpResponse response) throws IOException { final StatusLine statusLine = response.getStatusLine(); final HttpEntity entity = response.getEntity(); if (statusLine.getStatusCode() >= HttpStatus.SC_MULTIPLE_CHOICES) { EntityUtils.consume(entity); throw new HttpResponseException(statusLine.getStatusCode(), statusLine.getReasonPhrase()); } return entity; }
From source file:org.bonitasoft.engine.http.BonitaResponseHandler.java
/** * Returns the response body as a String if the response was successful (a * 2xx status code). If no response body exists, this returns null. If the * response was unsuccessful (>= 300 status code), throws an {@link org.apache.http.client.HttpResponseException}. *///from w w w . j av a 2 s.c o m @Override public String handleResponse(final HttpResponse response) throws HttpResponseException, IOException { final HttpEntity entity = response.getEntity(); final StatusLine statusLine = response.getStatusLine(); if (statusLine.getStatusCode() >= 300) { throw new HttpResponseException(statusLine.getStatusCode(), statusLine.getReasonPhrase()); } return entity == null ? null : EntityUtils.toString(entity); }
From source file:com.vmware.bdd.plugin.clouderamgr.poller.host.handler.DefaultResponseHandler.java
@Override public ParseResult handleResponse(HttpResponse response) throws IOException { StatusLine statusLine = response.getStatusLine(); HttpEntity entity = response.getEntity(); if (statusLine.getStatusCode() >= 300) { throw new HttpResponseException(statusLine.getStatusCode(), statusLine.getReasonPhrase()); }//from www . ja v a2 s . c o m if (entity == null) { throw new ClientProtocolException("Response contains no content"); } return contentParser.parse(EntityUtils.toString(entity)); }
From source file:me.xiaopan.android.gohttp.DownloadHttpResponseHandler.java
@Override public Object handleResponse(HttpRequest httpRequest, HttpResponse httpResponse) throws Throwable { if (!(httpResponse.getStatusLine().getStatusCode() > 100 && httpResponse.getStatusLine().getStatusCode() < 300)) { throw new HttpResponseException(httpResponse.getStatusLine().getStatusCode(), httpResponse.getStatusLine().getStatusCode() + "" + httpRequest.getUrl()); }/*from w w w . j a v a 2 s .co m*/ HttpEntity httpEntity = httpResponse.getEntity(); if (httpEntity == null) { throw new HttpResponseException(httpResponse.getStatusLine().getStatusCode(), "HttpEntity is null"); } if (createFile(file) == null) { throw new IllegalArgumentException("" + file.getPath()); } OutputStream outputStream = null; try { outputStream = new BufferedOutputStream(new FileOutputStream(file), 8 * 1024); read(httpRequest, httpEntity, outputStream); try { outputStream.flush(); } catch (IOException e) { e.printStackTrace(); } try { outputStream.close(); } catch (IOException e) { e.printStackTrace(); } } catch (IOException e) { e.printStackTrace(); if (outputStream != null) { try { outputStream.flush(); } catch (IOException e1) { e1.printStackTrace(); } try { outputStream.close(); } catch (IOException e2) { e2.printStackTrace(); } } if (file.exists()) { file.delete(); } throw e; } if (httpRequest.isCanceled()) { if (file.exists()) { file.delete(); } return null; } else { return file; } }
From source file:ca.sqlpower.http.HttpResponseHandler.java
public String handleResponse(HttpResponse response) throws ClientProtocolException, IOException { StatusLine statusLine = response.getStatusLine(); HttpEntity entity = response.getEntity(); String entityString = EntityUtils.toString(entity); // Attempt to get the Server stacktrace and display that if (statusLine.getStatusCode() == 500) { throw new HttpResponseException(statusLine.getStatusCode(), entityString); } else if (statusLine.getStatusCode() >= 300) { throw new HttpResponseException(statusLine.getStatusCode(), statusLine.getReasonPhrase()); }/*from w ww . ja v a 2 s . co m*/ return entity == null ? null : entityString; }