List of usage examples for org.springframework.http ResponseEntity getStatusCode
public HttpStatus getStatusCode()
From source file:gov.nyc.doitt.gis.geoclient.service.web.RestControllerTest.java
@Test public void testHandleMissingRequestParameter() { MockHttpServletRequest req = new MockHttpServletRequest(); String requestUri = "/foo"; String queryString = "bar=1"; req.setRequestURI(requestUri);//from ww w . j av a 2 s. c o m req.setQueryString(queryString); MissingAnyOfOptionalServletRequestParametersException e = new MissingAnyOfOptionalServletRequestParametersException( "dog", "cat"); ResponseEntity<BadRequest> result = this.restController.handleMissingRequestParameter(e, req); assertEquals(HttpStatus.BAD_REQUEST, result.getStatusCode()); assertEquals(String.format("%s?%s", requestUri, queryString), result.getBody().getRequestUri()); assertEquals(e.getMessage(), result.getBody().getMessage()); }
From source file:org.mythtv.service.myth.v25.HostHelperV25.java
private List<String> downloadHosts(final LocationProfile locationProfile) throws MythServiceApiRuntimeException, RemoteException, OperationApplicationException { Log.v(TAG, "downloadHosts : enter"); List<String> hosts = null; ResponseEntity<org.mythtv.services.api.ArrayOfString> responseEntity = mMythServicesTemplate .mythOperations().getHosts(ETagInfo.createEmptyETag()); if (responseEntity.getStatusCode().equals(HttpStatus.OK)) { org.mythtv.services.api.ArrayOfString hostList = responseEntity.getBody(); if (null != hostList.getValue() && hostList.getValue().length > 0) { hosts = load(hostList);//from ww w .ja v a 2 s. co m } } Log.v(TAG, "downloadHosts : exit"); return hosts; }
From source file:org.ow2.proactive.procci.rest.MixinRestTest.java
@Test public void postMixinTest() throws ClientException, IOException { MixinRendering mixinRendering = new MixinBuilder("schemeTest", "termTest").build().getRendering(); ResponseEntity<MixinRendering> response = mixinRest.createMixin(mixinRendering); assertThat(response.getBody().getScheme()).matches("schemeTest"); assertThat(response.getBody().getTerm()).matches("termTest"); assertThat(response.getStatusCode().is2xxSuccessful()).isTrue(); }
From source file:org.trustedanalytics.user.orgs.OrgsIT.java
@Test public void getOrgsWithSpaces_shouldAskCfForSpacesAndReturnGroupedByOrg() { Page<CcSpace> SPACES_FROM_CF = new Page<>(); SPACES_FROM_CF.setResources(OrgsTestsResources.getSpacesReturnedByCf().getSpaces()); Page<CcOrg> ORGS_FROM_CF = new Page<>(); ORGS_FROM_CF.setResources(OrgsTestsResources.getOrgsReturnedByCf().getOrgs()); final String EXPECTED_ORGS_WITH_SPACES = OrgsTestsResources.getOrgsWithSpacesExpectedToBeReturnedBySc(); Observable<CcOrg> orgs = Observable.from(OrgsTestsResources.getOrgsReturnedByCf().getOrgs()); when(ccClient.getOrgs()).thenReturn(orgs); Observable<CcSpace> spaces = Observable.from(OrgsTestsResources.getSpacesReturnedByCf().getSpaces()); when(ccClient.getSpaces()).thenReturn(spaces); when(detailsFinder.findUserId(Mockito.any())).thenReturn(UUID.randomUUID()); when(ccClient.getManagedOrganizations(any())).thenReturn(Collections.EMPTY_LIST); TestRestTemplate testRestTemplate = new TestRestTemplate(); ResponseEntity<String> response = RestOperationsHelpers.getForEntityWithToken(testRestTemplate, TOKEN, BASE_URL + OrgsController.GENERAL_ORGS_URL); assertThat(response.getStatusCode(), equalTo(HttpStatus.OK)); assertThat(response.getBody(), equalTo(EXPECTED_ORGS_WITH_SPACES)); }
From source file:org.venice.piazza.servicecontroller.messaging.handlers.DescribeServiceHandlerTest.java
@Test /**//w ww . ja v a2 s. co m * Test what happens when a null is sent to register a service */ public void testHandleJobRequestNull() { PiazzaJobType jobRequest = null; ResponseEntity<String> result = dsHandler.handle(jobRequest); assertEquals("The response to a null JobRequest update should be null", result.getStatusCode(), HttpStatus.BAD_REQUEST); }
From source file:com.bodybuilding.argos.discovery.ClusterListDiscovery.java
private Collection<Cluster> getClustersFromURL(String url) { Set<Cluster> clusters = new HashSet<>(); try {// w w w . j a v a2s . com ResponseEntity<List<ClusterInfo>> response = restTemplate.exchange(url, HttpMethod.GET, null, new ParameterizedTypeReference<List<ClusterInfo>>() { }); if (response.getStatusCode().value() != 200) { throw new RuntimeException("Failed to request clusters from " + url + ", return code: " + response.getStatusCode().value()); } response.getBody().stream().filter( c -> !Strings.isNullOrEmpty(c.getName()) && !Strings.isNullOrEmpty(c.getTurbineStream())) .map(c -> new Cluster(c.getName(), c.getTurbineStream())).forEach(clusters::add); } catch (Exception e) { LOG.warn("Failed getting clusters from {}", url, e); } return clusters; }
From source file:com.teradata.benchto.driver.graphite.GraphiteClient.java
@Retryable(value = { RestClientException.class, IncompleteDataException.class }, backoff = @Backoff(delay = 5000, multiplier = 2), maxAttempts = 4) public Map<String, double[]> loadMetrics(Map<String, String> metrics, long fromEpochSecond, long toEpochSecond) { URI uri = buildLoadMetricsURI(metrics, fromEpochSecond, toEpochSecond); LOGGER.debug("Loading metrics: {}", uri); ResponseEntity<GraphiteRenderResponseItem[]> response = restTemplate.getForEntity(uri, GraphiteRenderResponseItem[].class); if (response.getStatusCode() != OK) { throw new BenchmarkExecutionException("Could not load metrics: " + metrics + " - error: " + response); }/* w w w . j a v a 2 s . c o m*/ return Arrays.stream(response.getBody()).collect(toMap(GraphiteRenderResponseItem::getTarget, responseItem -> parseDataPoints(responseItem.datapoints))); }
From source file:com.companyname.plat.commons.client.HttpRestfulClient.java
public Object getObject(Map<String, String> params, Class clz) { RestTemplate restTemplate = new RestTemplate(); try {/* w w w.ja v a2 s . c o m*/ ResponseEntity<Object> entity = restTemplate.exchange(getEndPoint(), HttpMethod.GET, getHttpRequest(params), clz); setResponseStatus(entity.getStatusCode().toString()); return entity.getBody(); } catch (HttpClientErrorException ex) { if (HttpStatus.UNAUTHORIZED == ex.getStatusCode()) { System.out .println("Unauthorized call to " + this.getEndPoint() + "\nWrong login and/or password (\"" + this.getUserName() + "\" / \"" + this.getPassword() + "\")"); System.out.println("Cause: \n" + ex.getMessage()); } } return null; }
From source file:de.codecentric.boot.admin.services.ApplicationRegistrator.java
/** * Registers the client application at spring-boot-admin-server. * * @return true if successful registration on at least one admin server *//*from w ww. ja v a 2 s. c om*/ public boolean register() { boolean isRegistrationSuccessful = false; Application self = createApplication(); for (String adminUrl : admin.getAdminUrl()) { try { @SuppressWarnings("rawtypes") ResponseEntity<Map> response = template.postForEntity(adminUrl, new HttpEntity<>(self, HTTP_HEADERS), Map.class); if (response.getStatusCode().equals(HttpStatus.CREATED)) { if (registeredId.compareAndSet(null, response.getBody().get("id").toString())) { LOGGER.info("Application registered itself as {}", response.getBody()); } else { LOGGER.debug("Application refreshed itself as {}", response.getBody()); } isRegistrationSuccessful = true; if (admin.isRegisterOnce()) { break; } } else { LOGGER.warn("Application failed to registered itself as {}. Response: {}", self, response.toString()); } } catch (Exception ex) { LOGGER.warn("Failed to register application as {} at spring-boot-admin ({}): {}", self, admin.getAdminUrl(), ex.getMessage()); } } return isRegistrationSuccessful; }
From source file:it.reply.orchestrator.service.CmdbServiceImpl.java
@Override public CloudService getServiceById(String id) { ResponseEntity<CloudService> response = restTemplate.getForEntity(url.concat(serviceIdUrlPath).concat(id), CloudService.class); if (response.getStatusCode().is2xxSuccessful()) { return response.getBody(); }//from w ww. j ava 2 s.c om throw new DeploymentException("Unable to find service <" + id + "> in the CMDB." + response.getStatusCode().toString() + " " + response.getStatusCode().getReasonPhrase()); }