List of usage examples for org.springframework.http HttpStatus equals
public boolean equals(Object obj)
From source file:io.curly.commons.config.feign.ErrorDecoderFactory.java
public static Exception create(HttpStatus httpStatus, String reason) { if (httpStatus.equals(HttpStatus.NOT_FOUND)) { return new ResourceNotFoundException(reason); } else if (httpStatus.equals(HttpStatus.BAD_REQUEST)) { return new BadRequestException(reason); } else if (httpStatus.equals(HttpStatus.INTERNAL_SERVER_ERROR)) { return new InternalServerErrorException(reason); } else if (httpStatus.equals(HttpStatus.UNAUTHORIZED)) { return new UnauthorizedException(reason); } else if (httpStatus.equals(HttpStatus.UNSUPPORTED_MEDIA_TYPE)) { return new UnsupportedMediaTypeException(reason); }//w ww. j a v a2s. co m return new BadRequestException(reason); }
From source file:org.eclipse.cft.server.core.internal.CloudErrorUtil.java
public static boolean isWrongCredentialsException(CoreException e) { Throwable cause = e.getCause(); if (cause instanceof HttpClientErrorException) { HttpClientErrorException httpException = (HttpClientErrorException) cause; HttpStatus statusCode = httpException.getStatusCode(); if (statusCode.equals(HttpStatus.FORBIDDEN) && httpException instanceof CloudFoundryException) { return ((CloudFoundryException) httpException).getDescription().equals("Operation not permitted"); //$NON-NLS-1$ }//from w w w . ja v a 2 s.co m } return false; }
From source file:org.eclipse.cft.server.core.internal.CloudErrorUtil.java
public static boolean isHttpException(Throwable t, HttpStatus status) { HttpClientErrorException httpException = getHttpClientError(t); if (httpException != null) { HttpStatus statusCode = httpException.getStatusCode(); return statusCode.equals(status); }/*from w w w . jav a 2 s . co m*/ return false; }
From source file:com.xyxy.platform.examples.showcase.demos.hystrix.service.GetUserCommand.java
/** * ?HystrixBadRequestException?/*from w w w . j a v a2s . c o m*/ */ protected Exception handleException(HttpStatusCodeException e) { HttpStatus status = e.getStatusCode(); if (status.equals(HttpStatus.BAD_REQUEST)) { throw new HystrixBadRequestException(e.getResponseBodyAsString(), e); } throw e; }
From source file:de.fhg.fokus.nubomedia.paas.VNFRServiceImpl.java
/** * Registers a new App to the VNFR with a specific VNFR ID * //from w ww . j a va2s . com * @param externalAppId - application identifier * @param points - capacity */ public ApplicationRecord registerApplication(String externalAppId, int points) throws NotEnoughResourcesException { try { if (serviceProfile == null) { logger.info("Service Profile not set. make sure the VNFR_ID, VNFM_IP and VNFM_PORT are available "); return null; } String URL = serviceProfile.getServiceApiUrl(); ApplicationRecordBody bodyObj = new ApplicationRecordBody(externalAppId, points); Gson mapper = new GsonBuilder().create(); String body = mapper.toJson(bodyObj, ApplicationRecordBody.class); logger.info("registering new application: \nURL: " + URL + "\n + " + body); HttpHeaders creationHeader = new HttpHeaders(); creationHeader.add("Accept", "application/json"); creationHeader.add("Content-type", "application/json"); HttpEntity<String> registerEntity = new HttpEntity<String>(body, creationHeader); ResponseEntity response = restTemplate.exchange(URL, HttpMethod.POST, registerEntity, String.class); logger.info("response from VNFM " + response); HttpStatus status = response.getStatusCode(); if (status.equals(HttpStatus.CREATED) || status.equals(HttpStatus.OK)) { logger.info("Deployment status: " + status + " response: " + response); ApplicationRecord responseBody = mapper.fromJson((String) response.getBody(), ApplicationRecord.class); logger.info("returned object " + responseBody.toString()); return responseBody; } else if (status.equals(HttpStatus.UNPROCESSABLE_ENTITY)) { throw new NotEnoughResourcesException("Not enough resource " + response.getBody()); } } catch (NotEnoughResourcesException e) { logger.error(e.getMessage()); } catch (RestClientException e) { logger.error("Error registering application to VNFR - " + e.getMessage()); } return null; }
From source file:org.avidj.zuul.client.ZuulRestClient.java
@Override public boolean lock(String sessionId, List<String> path, LockType type, LockScope scope) { RestTemplate restTemplate = new RestTemplate(); HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON)); HttpEntity<String> entity = new HttpEntity<String>("parameters", headers); Map<String, String> parameters = new HashMap<>(); parameters.put("id", sessionId); // set the session id UriComponentsBuilder uriBuilder = UriComponentsBuilder.fromHttpUrl(serviceUrl + lockPath(path)) .queryParam("t", type(type)).queryParam("s", scope(scope)); ResponseEntity<String> result = restTemplate.exchange(uriBuilder.build().encode().toUri(), HttpMethod.PUT, entity, String.class); LOG.info(result.toString());//from w w w. j a va 2s .co m HttpStatus code = result.getStatusCode(); return code.equals(HttpStatus.CREATED); }
From source file:com.fredhopper.core.connector.index.upload.impl.RestPublishingStrategy.java
@Override public String checkStatus(final InstanceConfig config, final URI triggerUrl) throws ResponseStatusException { Preconditions.checkArgument(config != null); Preconditions.checkArgument(triggerUrl != null); final RestTemplate restTemplate = restTemplateProvider.createTemplate(config.getHost(), config.getPort(), config.getUsername(), config.getPassword()); final URI url = triggerUrl.resolve(triggerUrl.getPath() + STATUS_PATH); final HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.TEXT_PLAIN); final HttpEntity<String> httpEntity = new HttpEntity<>(headers); final ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.GET, httpEntity, String.class); final HttpStatus status = response.getStatusCode(); if (status.equals(HttpStatus.OK)) { return response.getBody(); } else {/*www . ja va 2 s .c o m*/ throw new ResponseStatusException( "HttpStatus " + status.toString() + " response received. Load trigger monitoring failed."); } }
From source file:com.fredhopper.core.connector.index.upload.impl.RestPublishingStrategy.java
@Override public URI triggerDataLoad(final InstanceConfig config, final String dataId) throws ResponseStatusException { Preconditions.checkArgument(config != null); Preconditions.checkArgument(StringUtils.isNotBlank(dataId)); final RestTemplate restTemplate = restTemplateProvider.createTemplate(config.getHost(), config.getPort(), config.getUsername(), config.getPassword()); final URI url = createUri(config.getScheme(), config.getHost(), config.getPort(), config.getServername(), TRIGGER_PATH, Collections.emptyList()); final HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.TEXT_PLAIN); final HttpEntity<String> httpEntity = new HttpEntity<>(dataId, headers); final ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.PUT, httpEntity, String.class); final HttpStatus status = response.getStatusCode(); if (status.equals(HttpStatus.CREATED)) { return response.getHeaders().getLocation(); } else {//from w w w. ja va 2 s . c om throw new ResponseStatusException( "HttpStatus " + status.toString() + " response received. Load trigger creation failed."); } }
From source file:com.fredhopper.core.connector.index.upload.impl.RestPublishingStrategy.java
@Override public String uploadDataSet(final InstanceConfig config, final File file) throws ResponseStatusException { Preconditions.checkArgument(config != null); Preconditions.checkArgument(file != null); final RestTemplate restTemplate = restTemplateProvider.createTemplate(config.getHost(), config.getPort(), config.getUsername(), config.getPassword()); final String checkSum = createCheckSum(file); final List<NameValuePair> params = Arrays .asList(new NameValuePair[] { new BasicNameValuePair("checksum", checkSum) }); final URI url = createUri(config.getScheme(), config.getHost(), config.getPort(), config.getServername(), UPLOAD_PATH, params);/*from w w w .j a va2s .c o m*/ final HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.valueOf("application/zip")); final HttpEntity<Resource> httpEntity = new HttpEntity<>(new FileSystemResource(file), headers); final ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.PUT, httpEntity, String.class); final HttpStatus status = response.getStatusCode(); if (status.equals(HttpStatus.CREATED)) { return response.getBody().trim(); } else { throw new ResponseStatusException( "HttpStatus " + status.toString() + " response received. File upload failed."); } }
From source file:com.redblackit.web.test.RestTemplateTestHelperTest.java
/** * Find a status code (not 2xx) which does not equal supplied code * /*from w ww.j a v a2s . c o m*/ * @param expectedStatusCode * @return different statusCode */ private HttpStatus getNonMatchingErrorStatusCode(HttpStatus expectedStatusCode) { return (expectedStatusCode.equals(HttpStatus.FORBIDDEN) ? HttpStatus.INTERNAL_SERVER_ERROR : HttpStatus.FORBIDDEN); }