List of usage examples for org.apache.http.client HttpResponseException HttpResponseException
public HttpResponseException(final int statusCode, final String s)
From source file:net.oneandone.shared.artifactory.SearchLatestVersionTest.java
/** * Test of search method, of class SearchLatestVersion. *///from w w w.j av a 2 s . com @Test public void testSearchNotfound() throws NotFoundException, IOException { final HttpResponseException notFound = new HttpResponseException(HttpStatus.SC_NOT_FOUND, "Not found"); setupSearchWithException(notFound); thrown.expect(NotFoundException.class); thrown.expectMessage("No results found"); sut.search("repo1", "commons-logging", "commons-logging"); }
From source file:com.jaspersoft.studio.server.protocol.restv2.RESTv2ExceptionHandler.java
public void handleException(Response res, IProgressMonitor monitor) throws ClientProtocolException { String msg = ""; int status = res.getStatus(); switch (status) { case 400://ww w.j a va2 s. c om if (res.getHeaderString("Content-Type").equals("application/xml")) handleErrorDescriptor(res, monitor, status); case 401: throw new HttpResponseException(status, res.getStatusInfo().getReasonPhrase()); case 403: case 409: case 404: case 500: if (res.getHeaderString("Content-Type").contains("xml")) handleErrorDescriptor(res, monitor, status); else if (res.getHeaderString("Content-Type").contains("text/html")) { System.out.println(res.readEntity(String.class)); msg = res.getStatusInfo().getReasonPhrase() + "\n"; throw new HttpResponseException(status, msg); } default: String cnt = res.readEntity(String.class); if (cnt.length() > 100) cnt = ""; msg = res.getStatusInfo().getReasonPhrase() + "\n" + cnt; throw new HttpResponseException(status, msg); } }
From source file:azkaban.executor.ExecutorApiClient.java
/**Implementing the parseResponse function to return de-serialized Json object. * @param response the returned response from the HttpClient. * @return de-serialized object from Json or null if the response doesn't have a body. * *//*from ww w . ja v a 2s .com*/ @Override protected String parseResponse(HttpResponse response) throws HttpResponseException, IOException { final StatusLine statusLine = response.getStatusLine(); String responseBody = response.getEntity() != null ? EntityUtils.toString(response.getEntity()) : ""; if (statusLine.getStatusCode() >= 300) { logger.error(String.format("unable to parse response as the response status is %s", statusLine.getStatusCode())); throw new HttpResponseException(statusLine.getStatusCode(), responseBody); } return responseBody; }
From source file:org.dasein.cloud.utils.requester.DaseinResponseHandlerWithMapper.java
@Override public V handleResponse(HttpResponse httpResponse) throws ClientProtocolException, IOException { if (httpResponse.getStatusLine().getStatusCode() != HttpStatus.SC_OK && httpResponse.getStatusLine().getStatusCode() != HttpStatus.SC_NO_CONTENT && httpResponse.getStatusLine().getStatusCode() != HttpStatus.SC_CREATED && httpResponse.getStatusLine().getStatusCode() != HttpStatus.SC_ACCEPTED) { throw new HttpResponseException(httpResponse.getStatusLine().getStatusCode(), EntityUtils.toString(httpResponse.getEntity())); } else {//from w ww .java2 s . c o m if (httpResponse.getEntity() == null) return null; T responseObject = processor.read(httpResponse.getEntity().getContent(), classType); if (responseObject == null) return null; return mapper.mapFrom(responseObject); } }
From source file:au.csiro.casda.sodalint.Validator.java
/** * Retrieve the content from an address using a GET request. * //from w w w . j a v a2s . com * @param address The address to be queried. * @return The content, or null if no content could be read. * @throws HttpResponseException If a non 200 response code is returned. * @throws UnsupportedEncodingException If the content does not have an XML format. * @throws IOException If the content could not be read. */ protected String getXmlContentFromUrl(String address) throws HttpResponseException, UnsupportedEncodingException, IOException { Response response = Request.Get(address).execute(); HttpResponse httpResponse = response.returnResponse(); StatusLine statusLine = httpResponse.getStatusLine(); final int statusCodeOk = 200; if (statusLine.getStatusCode() != statusCodeOk) { throw new HttpResponseException(statusLine.getStatusCode(), statusLine.getReasonPhrase()); } HttpEntity entity = httpResponse.getEntity(); if (entity == null) { return null; } ContentType contentType = ContentType.getOrDefault(entity); if (!ContentType.APPLICATION_XML.getMimeType().equals(contentType.getMimeType()) && !ContentType.TEXT_XML.getMimeType().equals(contentType.getMimeType())) { throw new UnsupportedEncodingException(contentType.toString()); } String content = readTextContent(entity); if (StringUtils.isBlank(content)) { return null; } return content; }
From source file:org.apache.droids.protocol.http.HttpClientContentLoader.java
public InputStream load(URI uri) throws IOException { HttpGet httpget = new HttpGet(uri); HttpResponse response = httpclient.execute(httpget); StatusLine statusline = response.getStatusLine(); if (statusline.getStatusCode() == HttpStatus.SC_NOT_FOUND) { return null; }// w w w .j a v a 2s . c o m if (statusline.getStatusCode() != HttpStatus.SC_OK) { throw new HttpResponseException(statusline.getStatusCode(), statusline.getReasonPhrase()); } HttpEntity entity = response.getEntity(); if (entity != null) { return entity.getContent(); } else { return null; } }
From source file:com.lurencun.cfuture09.androidkit.http.async.EntityHttpResponseHandler.java
void sendResponseMessage(HttpResponse response) { StatusLine status = response.getStatusLine(); String responseBody = null;//from w w w .j av a 2 s .co m try { HttpEntity entity = null; HttpEntity temp = response.getEntity(); if (temp != null) { entity = new BufferedHttpEntity(temp); responseBody = EntityUtils.toString(entity, "UTF-8"); } } catch (IOException e) { sendFailureMessage(e, (String) null); } if (status.getStatusCode() >= 300) { sendFailureMessage(new HttpResponseException(status.getStatusCode(), status.getReasonPhrase()), responseBody); } else { sendSuccessMessage(status.getStatusCode(), response.getAllHeaders(), response.getEntity()); } }
From source file:com.liferay.sync.engine.documentlibrary.handler.BaseJSONHandler.java
@Override public Void handleResponse(HttpResponse httpResponse) { try {//from w w w .j a va 2 s.c o m StatusLine statusLine = httpResponse.getStatusLine(); if (statusLine.getStatusCode() != HttpStatus.SC_OK) { String response = getResponseString(httpResponse); if (handlePortalException(getException(response))) { return null; } _logger.error("Status code {}", statusLine.getStatusCode()); throw new HttpResponseException(statusLine.getStatusCode(), statusLine.getReasonPhrase()); } doHandleResponse(httpResponse); } catch (Exception e) { handleException(e); } return null; }
From source file:cn.com.loopj.android.http.RangeFileAsyncHttpResponseHandler.java
@Override public void sendResponseMessage(HttpResponse response) throws IOException { if (!Thread.currentThread().isInterrupted()) { StatusLine status = response.getStatusLine(); if (status.getStatusCode() == HttpStatus.SC_REQUESTED_RANGE_NOT_SATISFIABLE) { //already finished if (!Thread.currentThread().isInterrupted()) sendSuccessMessage(status.getStatusCode(), response.getAllHeaders(), null); } else if (status.getStatusCode() >= 300) { if (!Thread.currentThread().isInterrupted()) sendFailureMessage(status.getStatusCode(), response.getAllHeaders(), null, new HttpResponseException(status.getStatusCode(), status.getReasonPhrase())); } else {//from w ww . j a va2 s . c o m if (!Thread.currentThread().isInterrupted()) { Header header = response.getFirstHeader(AsyncHttpClient.HEADER_CONTENT_RANGE); if (header == null) { append = false; current = 0; } else { AsyncHttpClient.log.v(LOG_TAG, AsyncHttpClient.HEADER_CONTENT_RANGE + ": " + header.getValue()); } sendSuccessMessage(status.getStatusCode(), response.getAllHeaders(), getResponseData(response.getEntity())); } } } }
From source file:com.android.yijiang.kzx.http.RangeFileAsyncHttpResponseHandler.java
@Override public void sendResponseMessage(HttpResponse response) throws IOException { if (!Thread.currentThread().isInterrupted()) { StatusLine status = response.getStatusLine(); if (status.getStatusCode() == HttpStatus.SC_REQUESTED_RANGE_NOT_SATISFIABLE) { //already finished if (!Thread.currentThread().isInterrupted()) sendSuccessMessage(status.getStatusCode(), response.getAllHeaders(), null); } else if (status.getStatusCode() >= 300) { if (!Thread.currentThread().isInterrupted()) sendFailureMessage(status.getStatusCode(), response.getAllHeaders(), null, new HttpResponseException(status.getStatusCode(), status.getReasonPhrase())); } else {/*from ww w .ja va2 s. c o m*/ if (!Thread.currentThread().isInterrupted()) { Header header = response.getFirstHeader(AsyncHttpClient.HEADER_CONTENT_RANGE); if (header == null) { append = false; current = 0; } else Log.v(LOG_TAG, AsyncHttpClient.HEADER_CONTENT_RANGE + ": " + header.getValue()); sendSuccessMessage(status.getStatusCode(), response.getAllHeaders(), getResponseData(response.getEntity())); } } } }