List of usage examples for org.springframework.http HttpHeaders HttpHeaders
public HttpHeaders()
From source file:edu.infsci2560.services.BookService.java
@RequestMapping(value = "/{id}", method = RequestMethod.GET, produces = "application/json") public ResponseEntity<Book> list(@PathVariable("id") Long id) { HttpHeaders headers = new HttpHeaders(); return new ResponseEntity<>(repository.findOne(id), headers, HttpStatus.OK); }
From source file:com.arya.latihan.controller.SalesOrderController.java
@RequestMapping(method = RequestMethod.POST) @Transactional(readOnly = false)/*ww w.java 2 s .c o m*/ public ResponseEntity<SalesOrder> saveSalesOrder(@Valid SalesOrder salesOrder) { salesOrder = salesOrderRepository.save(salesOrder); URI uri = ServletUriComponentsBuilder.fromCurrentRequest().path("/{id}").buildAndExpand(salesOrder.getId()) .toUri(); HttpHeaders headers = new HttpHeaders(); headers.setLocation(uri); return new ResponseEntity<SalesOrder>(headers, HttpStatus.CREATED); }
From source file:HCEngine.java
@Override public ResponseEntity<String> submit(JCurlRequestOptions requestOptions) throws Exception { ResponseEntity<String> stringResponseEntity = null; try (CloseableHttpClient hc = createCloseableHttpClient()) { for (int i = 0; i < requestOptions.getCount(); i++) { final HttpHeaders headers = new HttpHeaders(); for (Map.Entry<String, String> e : requestOptions.getHeaderMap().entrySet()) { headers.put(e.getKey(), Collections.singletonList(e.getValue())); }/*from ww w . j a v a2s. c om*/ final HttpEntity<Void> requestEntity = new HttpEntity<>(headers); RestTemplate template = new RestTemplate(new HttpComponentsClientHttpRequestFactory(hc)); stringResponseEntity = template.exchange(requestOptions.getUrl(), HttpMethod.GET, requestEntity, String.class); System.out.println(stringResponseEntity.getBody()); } return stringResponseEntity; } }
From source file:org.nebula.service.exception.NebulaExceptionHandler.java
@ExceptionHandler({ IllegalArgumentException.class, GeneralSecurityException.class }) protected ResponseEntity<Object> badRequest(IllegalArgumentException ex, WebRequest request) { String bodyOfResponse = ex.getMessage(); ResponseEntity<Object> response = handleExceptionInternal(null, bodyOfResponse, new HttpHeaders(), HttpStatus.BAD_REQUEST, request); logger.error("Exception:" + response.toString(), ex); return response; }
From source file:org.craftercms.deployer.impl.rest.ExceptionHandlers.java
@ExceptionHandler(Exception.class) public ResponseEntity<Object> handleGeneralException(Exception exception, WebRequest webRequest) { return handleExceptionInternal(exception, null, new HttpHeaders(), HttpStatus.INTERNAL_SERVER_ERROR, webRequest);/*from w ww .ja va 2s .com*/ }
From source file:com.arya.latihan.controller.CustomerController.java
@RequestMapping(method = RequestMethod.POST) @Transactional(readOnly = false)/*from ww w.j a va 2 s . c om*/ public ResponseEntity<Customer> saveCustomer(@Valid Customer customer) { customer = customerRepository.save(customer); URI location = ServletUriComponentsBuilder.fromCurrentRequest().path("/{id}") .buildAndExpand(customer.getId()).toUri(); HttpHeaders headers = new HttpHeaders(); headers.setLocation(location); return new ResponseEntity<Customer>(headers, HttpStatus.CREATED); }
From source file:com.wavemaker.commons.json.deserializer.HttpHeadersDeSerializer.java
@Override public HttpHeaders deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { ObjectCodec codec = jp.getCodec();/*ww w . j a v a 2s . c o m*/ ObjectNode root = codec.readTree(jp); Map<String, Object> map = ((ObjectMapper) codec).readValue(root.toString(), new TypeReference<LinkedHashMap<String, Object>>() { }); HttpHeaders httpHeaders = new HttpHeaders(); for (Map.Entry<String, Object> entry : map.entrySet()) { Object value = entry.getValue(); if (value instanceof String) { httpHeaders.add(entry.getKey(), (String) entry.getValue()); } else if (value instanceof List) { httpHeaders.put(entry.getKey(), (List<String>) value); } } return httpHeaders; }
From source file:edu.infsci2560.services.LocationsService.java
@RequestMapping(value = "/{id}", method = RequestMethod.GET, produces = "application/json") public ResponseEntity<Location> list(@PathVariable("id") Long id) { HttpHeaders headers = new HttpHeaders(); return new ResponseEntity<>(repository.findOne(id), headers, HttpStatus.OK); }
From source file:$.RestExceptionHandler.java
@ExceptionHandler(value = { RestException.class }) public final ResponseEntity<?> handleException(RestException ex, WebRequest request) { HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.parseMediaType(MediaTypes.TEXT_PLAIN_UTF_8)); return handleExceptionInternal(ex, ex.getMessage(), headers, ex.status, request); }/*from w w w. j a va 2 s . co m*/
From source file:com.healthcit.cacure.web.controller.FormElementBatchDeleteController.java
@RequestMapping(value = "/questionList.delete", method = RequestMethod.POST) public ResponseEntity<String> batchDelete(@RequestParam(value = "feIds[]", required = false) Long[] feIds) { HashSet<Long> uniqueIds = new HashSet<Long>(Arrays.asList(feIds)); Set<Long> deleted = new HashSet<Long>(); for (Long id : uniqueIds) { try {/*w w w . jav a2 s . c o m*/ qaManager.deleteFormElementByID(id); deleted.add(id); } catch (Exception e) { e.printStackTrace(); } } JSONArray jsonArray = new JSONArray(); for (Long id : deleted) { jsonArray.add(id); } HttpHeaders headers = new HttpHeaders(); headers.add("Content-Type", "application/json"); return new ResponseEntity<String>(jsonArray.toString(), headers, HttpStatus.OK); }