List of usage examples for org.springframework.web.client HttpClientErrorException getStatusCode
public HttpStatus getStatusCode()
From source file:org.cloudfoundry.caldecott.client.HttpTunnel.java
@SuppressWarnings({ "unchecked", "rawtypes" }) public void close() { if (logger.isDebugEnabled()) { logger.debug("Deleting tunnel " + this.tunnelInfo.get("path")); }/*from ww w .j a va 2 s. co m*/ HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.set("Auth-Token", auth); HttpEntity<?> requestEntity = new HttpEntity(requestHeaders); try { restOperations.exchange(url + this.tunnelInfo.get("path"), HttpMethod.DELETE, requestEntity, null); } catch (HttpClientErrorException e) { if (e.getStatusCode().value() == 404) { if (logger.isDebugEnabled()) { logger.debug("Tunnel not found [" + e.getStatusCode() + "] " + e.getStatusText()); } } else { logger.warn("Error while deleting tunnel [" + e.getStatusCode() + "] " + e.getStatusText()); } } }
From source file:org.icgc.dcc.metadata.client.core.MetadataClient.java
private List<Entity> getEntities(String gnosId, String fileName) { val url = baseUrl + "/" + "entities?gnosId=" + gnosId + "&" + "fileName=" + fileName; try {// w w w .j a v a 2 s . com val entities = Arrays.asList(restTemplate.getForObject(url, Entity[].class)); log.info("Entities: {}", entities); return entities; } catch (HttpClientErrorException e) { log.error("Unexpected response code {} requesting entity with gnosId = {}, fileName = {}", e.getStatusCode(), gnosId, fileName); throw e; } }
From source file:com.ge.predix.test.utils.PolicyHelper.java
public CreatePolicyStatus createPolicySet(final String policyFile, final RestTemplate restTemplate, final HttpHeaders headers) { PolicySet policySet;//from w ww. j a v a 2 s .c om try { policySet = new ObjectMapper().readValue(new File(policyFile), PolicySet.class); String policyName = policySet.getName(); restTemplate.put(zoneHelper.getAcsBaseURL() + ACS_POLICY_SET_API_PATH + policyName, new HttpEntity<>(policySet, headers)); return CreatePolicyStatus.SUCCESS; } catch (IOException e) { return CreatePolicyStatus.JSON_ERROR; } catch (HttpClientErrorException httpException) { return httpException.getStatusCode() != null && httpException.getStatusCode().equals(HttpStatus.UNPROCESSABLE_ENTITY) ? CreatePolicyStatus.INVALID_POLICY_SET : CreatePolicyStatus.ACS_ERROR; } catch (RestClientException e) { return CreatePolicyStatus.ACS_ERROR; } }
From source file:io.syndesis.rest.v1.handler.exception.HttpClientErrorExceptionMapper.java
@Override public Response toResponse(HttpClientErrorException 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();// w ww.j ava 2 s.com }
From source file:de.zib.gndms.gndmc.gorfx.Test.TaskClientTest.java
@Test(groups = { "TaskFlowClientTest" }, dependsOnMethods = { "deleteTask" }) public void deleteTaskFlow() throws InterruptedException { // delete task flow {/*from w w w. j av a2 s. com*/ final ResponseEntity<Integer> responseEntity = taskFlowClient .deleteTaskflow(FailureTaskFlowMeta.TASK_FLOW_TYPE_KEY, taskFlowId, admindn, TASKFLOW_WID); Assert.assertNotNull(responseEntity); Assert.assertEquals(responseEntity.getStatusCode(), HttpStatus.OK); } // try to not find taskflow { try { final ResponseEntity<Facets> responseEntity = taskFlowClient .getFacets(FailureTaskFlowMeta.TASK_FLOW_TYPE_KEY, taskFlowId, admindn); Assert.assertNotNull(responseEntity); Assert.assertEquals(responseEntity.getStatusCode(), HttpStatus.NOT_FOUND); } catch (HttpClientErrorException e) { Assert.assertEquals(e.getStatusCode(), HttpStatus.NOT_FOUND); } } }
From source file:io.spring.initializr.actuate.stat.MainControllerStatsIntegrationTests.java
@Test public void invalidProjectSillHasStats() { try {//from w w w . jav a 2 s .co m downloadArchive("/starter.zip?type=invalid-type"); fail("Should have failed to generate project with invalid type"); } catch (HttpClientErrorException ex) { assertEquals(HttpStatus.BAD_REQUEST, ex.getStatusCode()); } assertEquals("No stat got generated", 1, statsMockController.stats.size()); StatsMockController.Content content = statsMockController.stats.get(0); JSONObject json = new JSONObject(content.json); assertEquals("com.example", json.get("groupId")); assertEquals("demo", json.get("artifactId")); assertEquals(true, json.get("invalid")); assertEquals(true, json.get("invalidType")); assertNotNull(json.get("errorMessage")); assertTrue(((String) json.get("errorMessage")).contains("invalid-type")); }
From source file:aiai.ai.station.LaunchpadRequester.java
/** * this scheduler is being run at the station side * * long fixedDelay()//from ww w. j av a 2 s . c om * Execute the annotated method with a fixed period in milliseconds between the end of the last invocation and the start of the next. */ public void fixedDelay() { if (globals.isUnitTesting) { return; } if (!globals.isStationEnabled) { return; } ExchangeData data = new ExchangeData(); String stationId = stationService.getStationId(); if (stationId == null) { data.setCommand(new Protocol.RequestStationId()); } data.setStationId(stationId); if (stationId != null) { // always report about current active sequences, if we have actual stationId data.setCommand(stationTaskService.produceStationSequenceStatus()); data.setCommand(stationService.produceReportStationStatus()); final boolean b = stationTaskService.isNeedNewExperimentSequence(stationId); if (b) { data.setCommand(new Protocol.RequestTask(globals.isAcceptOnlySignedSnippets)); } if (System.currentTimeMillis() - lastRequestForMissingResources > 15_000) { data.setCommand(new Protocol.CheckForMissingOutputResources()); lastRequestForMissingResources = System.currentTimeMillis(); } } reportSequenceProcessingResult(data); List<Command> cmds; synchronized (commands) { cmds = new ArrayList<>(commands); commands.clear(); } data.setCommands(cmds); // !!! always use data.setCommand() for correct initializing stationId !!! // we have to pull new tasks from server constantly try { HttpHeaders headers = new HttpHeaders(); headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON)); headers.setContentType(MediaType.APPLICATION_JSON); if (globals.isSecureRestUrl) { String auth = globals.restUsername + '=' + globals.restToken + ':' + globals.stationRestPassword; byte[] encodedAuth = Base64.encodeBase64(auth.getBytes(StandardCharsets.US_ASCII)); String authHeader = "Basic " + new String(encodedAuth); headers.set("Authorization", authHeader); } HttpEntity<ExchangeData> request = new HttpEntity<>(data, headers); ResponseEntity<ExchangeData> response = restTemplate.exchange(globals.serverRestUrl, HttpMethod.POST, request, ExchangeData.class); ExchangeData result = response.getBody(); addCommands(commandProcessor.processExchangeData(result).getCommands()); log.debug("fixedDelay(), {}", result); } catch (HttpClientErrorException e) { if (e.getStatusCode() == HttpStatus.UNAUTHORIZED) { log.error("Error 401 accessing url {}, globals.isSecureRestUrl: {}", globals.serverRestUrl, globals.isSecureRestUrl); } else { throw e; } } catch (RestClientException e) { log.error("Error accessing url: {}", globals.serverRestUrl); log.error("Stacktrace", e); } }
From source file:org.slc.sli.dashboard.client.RESTClient.java
/** * Makes a JSONRequest with the path. Times out, if boolean timeout property is set to true. * Timeout value is set in application-context.xml (dashboard.WSCall.timeout) * @param path//from w ww. jav a 2 s . com * @param timeout * @return */ public String getJsonRequest(String path, boolean timeout) { HttpHeaders headers = new HttpHeaders(); HttpEntity<String> response = null; RestTemplate templateToUse; if (timeout) { templateToUse = templateWTimeout; } else { templateToUse = template; } try { response = exchange(templateToUse, path, HttpMethod.GET, new HttpEntity(headers), String.class); } catch (HttpClientErrorException e) { logger.debug("Catch HttpClientException: {}", e.getStatusCode()); } if (response == null) { return null; } JsonParser parser = new JsonParser(); String jsonText = parser.parse(response.getBody()).getAsString(); return jsonText; }
From source file:org.slc.sli.dashboard.client.RESTClient.java
/** * Make a PUT request to a REST service//from w w w.j a v a 2 s .c o m * * @param path * the unique portion of the requested REST service URL * @param token * not used yet * * @param entity * entity used for update * * @throws NoSessionException */ public void putJsonRequestWHeaders(String path, String token, Object entity) { if (token != null) { URLBuilder url = null; if (!path.startsWith("http")) { url = new URLBuilder(getSecurityUrl()); url.addPath(path); } else { url = new URLBuilder(path); } HttpHeaders headers = new HttpHeaders(); headers.add("Authorization", "Bearer " + token); headers.add("Content-Type", "application/json"); HttpEntity requestEntity = new HttpEntity(entity, headers); logger.debug("Updating API at: {}", url); try { template.put(url.toString(), requestEntity); } catch (HttpClientErrorException e) { logger.debug("Catch HttpClientException: {}", e.getStatusCode()); } } }
From source file:com.ge.predix.test.utils.ZoneHelper.java
public HttpStatus deleteZone(final RestTemplate restTemplate, final String zoneName, final boolean registeredWithZac) { try {/* w w w . ja v a2 s. c om*/ restTemplate.delete(this.acsBaseUrl + ACS_ZONE_API_PATH + zoneName); if (registeredWithZac) { deleteServiceFromZac(zoneName); } return HttpStatus.NO_CONTENT; } catch (HttpClientErrorException httpException) { return httpException.getStatusCode(); } catch (JsonProcessingException e) { return HttpStatus.INTERNAL_SERVER_ERROR; } catch (RestClientException e) { return HttpStatus.INTERNAL_SERVER_ERROR; } }