List of usage examples for org.springframework.http ResponseEntity getStatusCodeValue
public int getStatusCodeValue()
From source file:net.nfpj.webcounter.api.CounterIT.java
/** * Test of getCounter method, of class CounterRestService. *///from ww w .j a v a 2 s . c o m @Test public void testGetCounter() { String name = "C1Get"; createCounter(name); ResponseEntity<Counter> entity = restTemplate.getForEntity("/counter/" + name + "/", Counter.class); assertEquals("Unexpected response status: " + entity.getStatusCodeValue(), 200, entity.getStatusCodeValue()); assertEquals(new Counter(name, 0), entity.getBody()); }
From source file:net.nfpj.webcounter.api.CounterIT.java
/** * Test of createIncCounter method, of class CounterRestService. *//*w w w.j a va2 s . c o m*/ @Test public void testCreateIncCounter() { String name = "C1CreateInc"; ResponseEntity<Counter> entity = restTemplate.postForEntity("/counter/" + name + "/", "", Counter.class); assertEquals("Unexpected response status: " + entity.getStatusCodeValue(), 200, entity.getStatusCodeValue()); assertEquals(new Counter(name, 1), entity.getBody()); }
From source file:net.nfpj.webcounter.api.CounterIT.java
/** * Test of getCounters method, of class CounterRestService. */// ww w.j a va2s . c om @Test public void testGetCounters() { String[] countersName = new String[] { "C1List", "C2List", "C3List" }; for (String name : countersName) { createCounter(name); } ResponseEntity<Counter[]> entity = restTemplate.getForEntity("/counter/list/", Counter[].class); assertEquals("Unexpected response status: " + entity.getStatusCodeValue(), 200, entity.getStatusCodeValue()); Counter[] counters = entity.getBody(); assertTrue(countersName.length <= counters.length); Arrays.sort(countersName, (n1, n2) -> n1.compareTo(n2)); Arrays.sort(counters, (c1, c2) -> c1.getName().compareTo(c2.getName())); int countEquals = 0; for (int i = 0, j = 0; i < countersName.length;) { if (countersName[i].equals(counters[j].getName())) { countEquals++; i++; } j++; } assertEquals(countersName.length, countEquals); }
From source file:net.nfpj.webcounter.api.CounterIT.java
@Test public void testIncCounterMissing() { String name = "C1IncMissing"; ResponseEntity<Counter> entity = restTemplate.exchange("/counter/{name}/", HttpMethod.PUT, null, Counter.class, name); assertEquals("Unexpected response status: " + entity.getStatusCodeValue(), HttpStatus.SC_NOT_FOUND, entity.getStatusCodeValue()); }
From source file:net.nfpj.webcounter.api.CounterIT.java
/** * Test of incCounter method, of class CounterRestService. *///from w ww.j a v a2 s . c o m @Test public void testIncCounter() { String name = "C1Inc"; createCounter(name); ResponseEntity<Counter> entity = restTemplate.exchange("/counter/{name}/", HttpMethod.PUT, null, Counter.class, name); assertEquals("Unexpected response status: " + entity.getStatusCodeValue(), 200, entity.getStatusCodeValue()); assertEquals(new Counter(name, 1), entity.getBody()); }
From source file:net.nfpj.webcounter.api.CounterIT.java
private void createCounter(String name) { ResponseEntity<Counter> entity = restTemplate.postForEntity("/counter/create", new CounterCreationRequest(name), Counter.class); assertEquals("Unexpected response status: " + entity.getStatusCodeValue(), HttpStatus.SC_CREATED, entity.getStatusCodeValue()); assertEquals(new Counter(name, 0), entity.getBody()); }
From source file:net.nfpj.webcounter.api.CounterIT.java
@Test public void testCreateCounterExisting() throws DuplicatedCounterException { String name = "C1CreateExist"; createCounter(name);// w ww. j av a 2s. co m ResponseEntity<String> entity = restTemplate.postForEntity("/counter/create/", new CounterCreationRequest(name), String.class); assertEquals("Unexpected response status: " + entity.getStatusCodeValue(), HttpStatus.SC_BAD_REQUEST, entity.getStatusCodeValue()); }
From source file:net.nfpj.webcounter.api.CounterIT.java
/** * Test of createCounter method, of class CounterRestService. *//*from w ww .jav a 2 s. c o m*/ @Test public void testCreateCounter() { String name = "C1Create"; ResponseEntity<Counter> entity = restTemplate.postForEntity("/counter/create/", new CounterCreationRequest(name), Counter.class); assertEquals("Unexpected response status: " + entity.getStatusCodeValue(), 201, entity.getStatusCodeValue()); assertEquals(new Counter(name, 0), entity.getBody()); }
From source file:org.apache.knox.solr.ui.SearchController.java
/** * Do a solr search//from w w w .j a va 2s . c om * * @param solrRequest * the Solr request * @return the HTML response */ @RequestMapping("/search") public @ResponseBody String search(@RequestBody SolrRequest solrRequest) { logger.debug("Received Solr Request: {}", solrRequest); final String solrUrl = buildSolrUrl(solrRequest); logger.debug("Executing with URL: {}", solrUrl); final RestTemplate restTemplate = new RestTemplate(); final ResponseEntity<String> solrResult = restTemplate.getForEntity(solrUrl, String.class); logger.debug("Solr Result: {}", solrResult); if (HttpStatus.OK.equals(solrResult.getStatusCode())) { return solrResult.getBody(); } else { logger.error("Error getting Solr Result - http status: {}", solrResult.getStatusCodeValue()); return ""; } }
From source file:com.insys.cfclient.nozzle.InfluxDBSender.java
@Async public void sendBatch(List<String> messages) { log.debug("ENTER sendBatch"); httpClient.setErrorHandler(new ResponseErrorHandler() { @Override/*from www . jav a 2s. c o m*/ public boolean hasError(ClientHttpResponse clientHttpResponse) throws IOException { return clientHttpResponse.getRawStatusCode() > 399; } @Override public void handleError(ClientHttpResponse clientHttpResponse) throws IOException { } }); RetryTemplate retryable = new RetryTemplate(); retryable.setBackOffPolicy(getBackOffPolicy()); retryable.setRetryPolicy(new SimpleRetryPolicy(properties.getMaxRetries(), Collections.singletonMap(ResourceAccessException.class, true))); final AtomicInteger counter = new AtomicInteger(0); retryable.execute(retryContext -> { int count = counter.incrementAndGet(); log.trace("Attempt {} to deliver this batch", count); final StringBuilder builder = new StringBuilder(); messages.forEach(s -> builder.append(s).append("\n")); String body = builder.toString(); RequestEntity<String> entity = new RequestEntity<>(body, HttpMethod.POST, getUri()); ResponseEntity<String> response; response = httpClient.exchange(entity, String.class); if (response.getStatusCode() != HttpStatus.NO_CONTENT) { log.error("Failed to write logs to InfluxDB! Expected error code 204, got {}", response.getStatusCodeValue()); log.trace("Request Body: {}", body); log.trace("Response Body: {}", response.getBody()); } else { log.debug("batch sent successfully!"); } log.debug("EXIT sendBatch"); return null; }, recoveryContext -> { log.trace("Failed after {} attempts!", counter.get()); return null; }); }