List of usage examples for org.apache.http.client HttpResponseException HttpResponseException
public HttpResponseException(final int statusCode, final String s)
From source file:org.eclipse.aether.transport.http.HttpTransporter.java
private void handleStatus(HttpResponse response) throws HttpResponseException { int status = response.getStatusLine().getStatusCode(); if (status >= 300) { throw new HttpResponseException(status, response.getStatusLine().getReasonPhrase() + " (" + status + ")"); }/* w w w. j a va2 s. co m*/ }
From source file:cn.com.loopj.android.http.AsyncHttpResponseHandler.java
@Override public void sendResponseMessage(HttpResponse response) throws IOException { // do not process if request has been cancelled if (!Thread.currentThread().isInterrupted()) { StatusLine status = response.getStatusLine(); byte[] responseBody; responseBody = getResponseData(response.getEntity()); // additional cancellation check as getResponseData() can take non-zero time to process if (!Thread.currentThread().isInterrupted()) { if (status.getStatusCode() >= 300) { sendFailureMessage(status.getStatusCode(), response.getAllHeaders(), responseBody, new HttpResponseException(status.getStatusCode(), status.getReasonPhrase())); } else { sendSuccessMessage(status.getStatusCode(), response.getAllHeaders(), responseBody); }// www . j av a2 s . co m } } }
From source file:com.amytech.android.library.utils.asynchttp.AsyncHttpResponseHandler.java
@Override public void sendResponseMessage(HttpResponse response) throws IOException { // do not process if request has been cancelled if (!Thread.currentThread().isInterrupted()) { StatusLine status = response.getStatusLine(); byte[] responseBody; responseBody = getResponseData(response.getEntity()); // additional cancellation check as getResponseData() can take // non-zero time to process if (!Thread.currentThread().isInterrupted()) { if (status.getStatusCode() >= 300) { sendFailureMessage(status.getStatusCode(), response.getAllHeaders(), responseBody, new HttpResponseException(status.getStatusCode(), status.getReasonPhrase())); } else { sendSuccessMessage(status.getStatusCode(), response.getAllHeaders(), responseBody); }//from www. ja va 2s . c o m } } }
From source file:tds.tdsadmin.rest.TDSAdminController.java
@RequestMapping(value = "/rest/alterOpportunityExpiration", method = RequestMethod.POST) @ResponseBody//from w w w. j ava 2 s . c o m @Secured({ "ROLE_Opportunity Modify" }) public ProcedureResult alterOpportunityExpiration(HttpServletResponse response, @RequestParam(value = "oppkey", required = false) UUID v_oppKey, @RequestParam(value = "requester", required = false) String v_requester, @RequestParam(value = "dayincrement", required = false) Integer v_dayincrement, @RequestParam(value = "reason", required = false) String v_reason) throws HttpResponseException { ProcedureResult result = null; // throwing exception when oppkey is null or dayincrement is not in // range <-365,365>, this is an arbitrary range if (v_oppKey == null || StringUtils.isEmpty(v_requester) || v_dayincrement == null || v_dayincrement < -365 || v_dayincrement > 365) { response.setStatus(HttpStatus.SC_BAD_REQUEST); throw new HttpResponseException(HttpStatus.SC_BAD_REQUEST, "oppkey, requester, and dayincrement are required parameters. reason is accepted as an optional parameter and dayIncrement range:<-365,365> "); } try { result = getDao().alterOpportunityExpiration(v_oppKey, v_requester, v_dayincrement, v_reason); if (result != null && "success".equalsIgnoreCase(result.getStatus())) logger.info(String.format( "Appeals: Extend expiration date successful for Oppkey=%s, DayIncrement=%s, requester=%s, Reason=%s", v_oppKey, v_dayincrement, v_requester, v_reason)); else logger.error(String.format( "Appeals: Extend expiration date failed for Oppkey=%s, DayIncrement=%s, requester=%s, Reason=%s", v_oppKey, v_dayincrement, v_requester, (result != null) ? result.getReason() : null)); } catch (ReturnStatusException e) { logger.error("Appeals: " + e.getMessage()); } return result; }
From source file:com.ab.http.AsyncHttpResponseHandler.java
/** * Send response message.//w w w . j av a 2 s. c o m * * @param response the response * @throws IOException Signals that an I/O exception has occurred. */ void sendResponseMessage(HttpResponse response) throws IOException { // do not process if request has been cancelled if (!Thread.currentThread().isInterrupted()) { StatusLine status = response.getStatusLine(); byte[] responseBody; responseBody = getResponseData(response.getEntity()); // additional cancellation check as getResponseData() can take non-zero time to process if (!Thread.currentThread().isInterrupted()) { if (status.getStatusCode() >= 300) { sendFailureMessage(status.getStatusCode(), response.getAllHeaders(), responseBody, new HttpResponseException(status.getStatusCode(), status.getReasonPhrase())); } else { sendSuccessMessage(status.getStatusCode(), response.getAllHeaders(), responseBody); } } } }
From source file:com.kixeye.janus.client.http.rest.DefaultRestHttpClient.java
/** * Executes a function with load balancer. * /*www. ja v a 2s. c om*/ * @param path * @param function * @return * @throws NoServerAvailableException * @throws RetriesExceededException */ private <T> HttpResponse<T> executeWithLoadBalancer(String path, FunctionWrapper<T> function) throws NoServerAvailableException, RetriesExceededException { long retries = numRetries; do { // get a load balanced server ServerStats server = janus.getServer(); if (server == null) { throw new NoServerAvailableException(janus.getServiceName()); } // prefix URL with selected server String newUrl = server.getServerInstance().getUrl() + path; // call into REST Template wrapper HttpResponse<T> result = null; long latency = -1; try { server.incrementSentMessages(); server.incrementOpenRequests(); long startTime = System.currentTimeMillis(); result = function.execute(newUrl); latency = System.currentTimeMillis() - startTime; // exit if successful if (result == null) { throw new TimeoutException("Timed out while waiting for a response."); } else { if (result.getStatusCode() >= 500) { throw new HttpResponseException(result.getStatusCode(), "Unexpected response"); } return result; } } catch (Exception e) { // unexpected exception, treat as a server problem but also log it. logger.warn("RestClient threw unexpected exception, retrying another server", e); server.incrementErrors(); } finally { server.decrementOpenRequests(); if (latency > 0) { server.recordLatency(latency); } } retries -= 1; } while (retries >= 0); throw new RetriesExceededException(janus.getServiceName(), numRetries); }
From source file:org.opentestsystem.shared.permissions.dao.db.dll.DbPermissionsDll.java
public void editComponent(SQLConnection connection, String componentId, String newComponent) throws ReturnStatusException, HttpResponseException { // check if the component already exists or not Component c = getComponentByComponentName(connection, newComponent); if (c != null) throw new HttpResponseException(409, "Component already exists."); final String SQL = "UPDATE component set component.name = ${newName} where component.name = ${compName};"; SqlParametersMaps parameters = new SqlParametersMaps(); parameters.put("compName", componentId).put("newName", newComponent); executeStatement(connection, SQL, parameters, false); }
From source file:ch.cyberduck.core.spectra.SpectraBulkService.java
/** * Forces a full reclaim of all caches, and waits until the reclaim completes. Cache contents that need to be retained because they are a part of an active job are retained. * Any cache contents that can be reclaimed will be. This operation may take a very long time to complete, depending on how much of the cache can be reclaimed and how many blobs the cache is managing. *///from w ww .j a v a 2 s . c o m protected void clear() throws BackgroundException { try { final RequestEntityRestStorageService client = session.getClient(); final HttpPut request = new HttpPut(String.format("%s://%s/_rest_/cache_filesystem?reclaim", session.getHost().getProtocol().getScheme(), session.getHost().getHostname())); client.authorizeHttpRequest(request, null, null); final HttpResponse response = client.getHttpClient().execute(request); if (HttpStatus.SC_NO_CONTENT != response.getStatusLine().getStatusCode()) { throw new HttpResponseException(response.getStatusLine().getStatusCode(), response.getStatusLine().getReasonPhrase()); } } catch (HttpResponseException e) { throw new HttpResponseExceptionMappingService().map(e); } catch (IOException e) { throw new DefaultIOExceptionMappingService().map(e); } catch (ServiceException e) { throw new S3ExceptionMappingService().map(e); } }
From source file:com.esri.geoportal.commons.csw.client.impl.Client.java
/** * Loads capabilites.//from w w w. j av a 2 s. c om * * @throws IOException if reading capabilities fails * @throws ParserConfigurationException if creating XML parser * @throws SAXException if invalid XML response */ private void loadCapabilities() throws IOException, ParserConfigurationException, SAXException { if (capabilites == null) { LOG.debug(String.format("Loading capabilities")); RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(5000).setSocketTimeout(2500) .build(); HttpGet getRequest = new HttpGet( baseUrl.toExternalForm() + "?request=GetCapabilities&service=CSW&version=2.0.2"); getRequest.setConfig(requestConfig); try (CloseableHttpResponse httpResponse = httpClient.execute(getRequest); InputStream stream = httpResponse.getEntity().getContent();) { if (httpResponse.getStatusLine().getStatusCode() >= 400) { throw new HttpResponseException(httpResponse.getStatusLine().getStatusCode(), httpResponse.getStatusLine().getReasonPhrase()); } capabilites = readCapabilities(stream); } } }
From source file:org.sakaiproject.hybrid.util.NakamuraAuthenticationHelperTest.java
/** * @see NakamuraAuthenticationHelper#getPrincipalLoggedIntoNakamura(HttpServletRequest) *//*from w w w . j av a2 s .c o m*/ @Test public void testHttpResponseException() throws Exception { // HttpResponseException when(httpClient.execute(any(HttpUriRequest.class), any(BasicResponseHandler.class))) .thenThrow(new HttpResponseException(404, "could not find cookie / not valid")); AuthInfo authInfo = nakamuraAuthenticationHelper.getPrincipalLoggedIntoNakamura(request); assertNull(authInfo); }