List of usage examples for org.springframework.web.client HttpServerErrorException getStatusCode
public HttpStatus getStatusCode()
From source file:com.alexshabanov.springrestapi.ControllerMockTest.java
@Test public void shouldGetInternalServerError() throws IOException { doThrow(UnsupportedOperationException.class).when(profileController).deleteProfile(id); when(profileController.handleUnsupportedOperationException()).thenReturn(errorDesc); try {/*from ww w.j a va 2 s . c om*/ restClient.delete(path(CONCRETE_PROFILE_RESOURCE), id); fail(); } catch (HttpServerErrorException e) { assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, e.getStatusCode()); final ErrorDesc actual = getObjectMapper().reader(ErrorDesc.class) .readValue(e.getResponseBodyAsString()); assertEquals(errorDesc, actual); } }
From source file:io.syndesis.rest.v1.handler.exception.HttpServerErrorExceptionMapper.java
@Override public Response toResponse(HttpServerErrorException exception) { RestError error = new RestError(exception.getMessage(), exception.getMessage(), ErrorMap.from(new String(exception.getResponseBodyAsByteArray(), StandardCharsets.UTF_8)), exception.getStatusCode().value()); return Response.status(exception.getStatusCode().value()).type(MediaType.APPLICATION_JSON_TYPE) .entity(error).build();/*from ww w . jav a2s .c o m*/ }
From source file:info.raack.appliancelabeler.service.OAuthRequestProcessor.java
public <T, S> S processRequest(String uri, OAuthSecurityContext context, ResponseHandler<T, S> handler) throws OAuthUnauthorizedException { logger.debug("Attempting to request " + uri); String responseString = null; InputStream xmlInputStream = null; try {//from w ww. j a va 2 s . c o m if (context != null) { // set the current authentication context OAuthSecurityContextHolder.setContext(context); } // use the normal request processor for the currently logged in user byte[] bytes = oAuthRestTemplate.getForObject(URI.create(uri), byte[].class); responseString = new String(bytes); //logger.debug(new String(bytes)); xmlInputStream = new ByteArrayInputStream(bytes); //logger.debug("response: " + new String(bytes)); synchronized (this) { try { T item = (T) ((JAXBElement) u1.unmarshal(xmlInputStream)).getValue(); return handler.extractValue(item); } catch (Exception e) { // don't do anything if we can't unmarshall with the teds.xsd - try the other one try { xmlInputStream.close(); } catch (Exception e2) { } xmlInputStream = new ByteArrayInputStream(bytes); } T item = (T) ((JAXBElement) u2.unmarshal(xmlInputStream)).getValue(); return handler.extractValue(item); } } catch (HttpClientErrorException e2) { // if unauthorized - our credentials are bad or have been revoked - throw exception up the stack if (e2.getStatusCode() == HttpStatus.UNAUTHORIZED) { throw new OAuthUnauthorizedException(); } else { throw new RuntimeException( "Unknown remote server error " + e2.getStatusCode() + " (" + e2.getStatusText() + ") returned when requesting " + uri + "; " + e2.getResponseBodyAsString()); } } catch (HttpServerErrorException e3) { throw new RuntimeException( "Unknown remote server error " + e3.getStatusCode() + " (" + e3.getStatusText() + ") returned when requesting " + uri + "; " + e3.getResponseBodyAsString()); } catch (Exception e) { throw new RuntimeException( "Could not request " + uri + (responseString != null ? " response was " + responseString : ""), e); } finally { try { if (xmlInputStream != null) { xmlInputStream.close(); } } catch (Exception e) { } } }
From source file:com.orange.clara.cloud.servicedbdumper.integrations.AbstractIntegrationWithRealCfClientTest.java
protected void createService(CloudService cloudService) { try {// ww w .ja v a 2s.c o m logger.info("Creating service {} from {} with plan {} ", cloudService.getName(), cloudService.getLabel(), cloudService.getPlan()); cfClientToPopulate.createService(cloudService); if (!this.isFinishedCreatingService(cloudService)) { fail("Cannot create service '" + cloudService.getName() + "'"); } } catch (HttpServerErrorException e) { if (!e.getStatusCode().equals(HttpStatus.BAD_GATEWAY)) { throw e; } else { String skipMessage = "Bad gateway error, skipping test"; this.reportIntegration.setSkipped(true); this.reportIntegration.setSkippedReason(skipMessage); assumeTrue(skipMessage, false); } } }
From source file:org.eclipse.cft.server.core.internal.client.UpdateServicesOperation.java
@Override public void run(IProgressMonitor monitor) throws CoreException { try {//from w ww .j a v a 2s . com List<CFServiceInstance> existingServices = request.run(monitor); ServerEventHandler.getDefault().fireServicesUpdated(getBehaviour().getCloudFoundryServer(), existingServices); } catch (CoreException e) { // See if it is an HttpServerErrorException (thrown when receiving, // for example, 5xx). // If so, parse it into readable form. This follows the pattern of // CloudErrorUtil.asCoreException(...) CoreException rethrow = e; if (e.getCause() instanceof HttpServerErrorException) { HttpServerErrorException hsee = (HttpServerErrorException) e.getCause(); // Wrap the status inner exception into a new exception to allow the UI to properly display the full error message ServiceCreationFailedException scfe = new ServiceCreationFailedException( hsee.getStatusCode() + " " + hsee.getStatusCode().getReasonPhrase(), hsee); Status newStatus = new Status(e.getStatus().getSeverity(), e.getStatus().getPlugin(), e.getStatus().getCode(), hsee.getMessage(), scfe); rethrow = new CoreException(newStatus); } logNonModuleError(rethrow); throw rethrow; } }
From source file:br.com.modoagil.asr.rest.support.RESTErrorHandler.java
/** * Manipula exceo para status HTTP {@code 5xx}, exceo do servidor * * @param ex//from w ww .ja v a 2s . c om * {@link HttpServerErrorException} * @return resposta ao cliente */ @ResponseBody @ExceptionHandler(HttpServerErrorException.class) public Response<E> processHttpServerErrorException(final HttpServerErrorException ex) { this.logger.info("handleHttpServerErrorException - Catching: " + ex.getClass().getSimpleName(), ex); return new ResponseBuilder<E>().success(false).message(ex.getMessage()).status(ex.getStatusCode()).build(); }
From source file:ingest.inspect.PointCloudInspector.java
/** * Executes POST request to Point Cloud to grab the Payload * /* w w w. jav a 2 s. co m*/ * @param url * The URL to post for point cloud api * @return The PointCloudResponse object containing metadata. */ private PointCloudResponse postPointCloudTemplate(String url, String payload) throws IOException { // Setup Basic Headers HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); // Create the Request template and execute post HttpEntity<String> request = new HttpEntity<String>(payload, headers); String response = ""; try { logger.log("Sending Metadata Request to Point Cloud Service", Severity.INFORMATIONAL, new AuditElement(INGEST, "requestPointCloudMetadata", url)); response = restTemplate.postForObject(url, request, String.class); } catch (HttpServerErrorException e) { String error = "Error occurred posting to: " + url + "\nPayload: \n" + payload + "\nMost likely the payload source file is not accessible."; // this exception will be thrown until the s3 file is accessible to external services LOG.error(error, e); throw new HttpServerErrorException(e.getStatusCode(), error); } // Parse required fields from point cloud json response ObjectMapper mapper = new ObjectMapper(); JsonNode root = mapper.readTree(response); double maxx = root.at("/response/metadata/maxx").asDouble(); double maxy = root.at("/response/metadata/maxy").asDouble(); double maxz = root.at("/response/metadata/maxz").asDouble(); double minx = root.at("/response/metadata/minx").asDouble(); double miny = root.at("/response/metadata/miny").asDouble(); double minz = root.at("/response/metadata/minz").asDouble(); String spatialreference = root.at("/response/metadata/spatialreference").asText(); // Return the new PointCloudResponse object return new PointCloudResponse(spatialreference, maxx, maxy, maxz, minx, miny, minz); }
From source file:org.cloudfoundry.client.lib.rest.CloudControllerClientV1.java
public void uploadApplication(String appName, ApplicationArchive archive, UploadStatusCallback callback) throws IOException { Assert.notNull(appName, "AppName must not be null"); Assert.notNull(archive, "Archive must not be null"); if (callback == null) { callback = UploadStatusCallback.NONE; }//from ww w . java 2s .co m CloudResources knownRemoteResources = getKnownRemoteResources(archive); callback.onCheckResources(); callback.onMatchedFileNames(knownRemoteResources.getFilenames()); UploadApplicationPayload payload = new UploadApplicationPayload(archive, knownRemoteResources); callback.onProcessMatchedResources(payload.getTotalUncompressedSize()); HttpEntity<?> entity = generatePartialResourceRequest(payload, knownRemoteResources); String url = getUrl("apps/{appName}/application"); try { getRestTemplate().put(url, entity, appName); } catch (HttpServerErrorException hsee) { if (HttpStatus.INTERNAL_SERVER_ERROR.equals(hsee.getStatusCode())) { // this is for supporting legacy Micro Cloud Foundry 1.1 and older uploadAppUsingLegacyApi(url, entity, appName); } else { throw hsee; } } }
From source file:org.terasoluna.gfw.functionaltest.app.exceptionhandling.ExceptionHandlingTest.java
@Test public void test03_09_servletFrameworkHandling() { driver.findElement(By.id("servletFrameworkHandling_03_09")).click(); // TODO Assert Output Log // Error Code assert assertThat(driver.findElement(By.id("exceptionCode")).getText(), is("e.xx.xxx")); // screen capture screenCapture.save(driver);/*from www .j a va 2 s .c o m*/ try { restTemplate.getForEntity( applicationContextUrl + "/exceptionHandlingChangeAttribute/exceptionhandling/3_9", String.class); } catch (HttpServerErrorException e) { // Response Header Error Code assert assertThat(e.getResponseHeaders().get("X-Error-Code").get(0).toString(), is("e.xx.xxx")); // Response Code assert assertThat(e.getStatusCode().toString(), is("500")); } }
From source file:org.terasoluna.gfw.functionaltest.app.exceptionhandling.ExceptionHandlingTest.java
@Test public void test03_08_servletFrameworkHandling() { driver.findElement(By.id("servletFrameworkHandling_03_08")).click(); // TODO Assert Output Log // Error Code assert assertThat(driver.findElement(By.id("exceptionCode")).getText(), is("e.xx.9999")); // screen capture screenCapture.save(driver);/*www .ja va 2 s.co m*/ try { restTemplate.getForEntity( applicationContextUrl + "/exceptionHandlingChangeAttribute/exceptionhandling/3_8", String.class); } catch (HttpServerErrorException e) { // Response Header Error Code assert assertThat(e.getResponseHeaders().get("X-Error-Code").get(0).toString(), is("e.xx.9999")); // Response Code assert assertThat(e.getStatusCode().toString(), is("500")); } }