List of usage examples for org.springframework.http HttpHeaders HttpHeaders
public HttpHeaders()
From source file:cn.org.once.cstack.config.RestHandlerException.java
@ExceptionHandler(value = { ServiceException.class, JsonMappingException.class }) protected ResponseEntity<Object> handleServiceException(Exception ex, WebRequest request) { ex.printStackTrace();/*from w w w . java 2s . co m*/ HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); return handleExceptionInternal(ex, new HttpErrorServer(ex.getLocalizedMessage()), headers, HttpStatus.INTERNAL_SERVER_ERROR, request); }
From source file:com.appspot.potlachkk.controller.ImageSvc.java
@RequestMapping(value = ImageSvcApi.IMG_SVC_PATH_ID, method = RequestMethod.GET) public ResponseEntity<byte[]> getImageById(@PathVariable("id") Long id) { GiftImage img = images.findOne(id);//from w w w .j av a 2 s.c om final HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.parseMediaType(img.getMimeType())); return new ResponseEntity<byte[]>(img.getData().getBytes(), headers, HttpStatus.OK); }
From source file:edu.fing.tagsi.db4o.business.TrackingController.java
public void RegistrarNuevoSalto(Envio envio, Recorrido recorrido, List<Tracking> list) { if (list.size() < recorrido.getNodos().length) { NodoCamino nodo = recorrido.getNodos()[list.size()]; RestTemplate restTemplate = new RestTemplate(); RequestTrackingAddPackage req = new RequestTrackingAddPackage(envio.getId().toString(), envio.getCliente().getId().toString(), nodo.getCiudad().getId().toString(), new Date(), list.size() + 1 == recorrido.getNodos().length); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); HttpEntity<RequestTrackingAddPackage> entity = new HttpEntity<>(req, headers); restTemplate.postForObject(ConfigController.getInstance().getURLAddTracking(), entity, void.class); }//from w w w .j a v a 2 s. c o m }
From source file:org.slc.sli.dashboard.client.RESTClient.java
/** * Make a request to a REST service and convert the result to JSON * //w ww . j a v a 2 s .c om * @param path * the unique portion of the requested REST service URL * @param token * not used yet * * @param fullEntities * flag for returning expanded entities from the API * * @return a {@link JsonElement} if the request is successful and returns valid JSON, otherwise * null. * @throws NoSessionException */ public String makeJsonRequestWHeaders(String path, String token) { 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); HttpEntity entity = new HttpEntity(headers); logger.debug("Accessing API at: {}", url); HttpEntity<String> response = null; try { response = exchange(template, url.toString(), HttpMethod.GET, entity, String.class); } catch (HttpClientErrorException e) { logger.debug("Catch HttpClientException: {}", e.getStatusCode()); } if (response == null) { return null; } return response.getBody(); } logger.debug("Token is null in call to RESTClient for path {}", path); return null; }
From source file:net.eusashead.hateoas.conditional.interceptor.AsyncTestControllerITCase.java
@Test public void testConditionalGet() throws Exception { // Expected result HttpHeaders headers = new HttpHeaders(); headers.setETag("\"123456\""); ResponseEntity<String> expectedResult = new ResponseEntity<String>("hello", headers, HttpStatus.OK); // Execute asynchronously MvcResult mvcResult = this.mockMvc .perform(get("http://localhost/async/123").contentType(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON)) .andExpect(request().asyncStarted()).andExpect(request().asyncResult(expectedResult)).andReturn(); // Perform asynchronous dispatch this.mockMvc.perform(asyncDispatch(mvcResult)).andExpect(status().isOk()) .andExpect(header().string("ETag", "\"123456\"")) .andExpect(content().contentType(new MediaType("application", "json", Charset.forName("UTF-8")))); // The 304 should be returned synchronously (it bypasses the controller) this.mockMvc// w w w . j av a 2 s .c o m .perform(get("http://localhost/async/123").contentType(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON).header("If-None-Match", "\"123456\"")) .andExpect(status().isNotModified()).andReturn(); }
From source file:com.mycompany.springrest.controllers.RoleController.java
@RequestMapping(value = "/role/", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity<Void> createRole(@RequestBody Role role, UriComponentsBuilder ucBuilder) { logger.info("Creating Role " + role.getName()); if (roleService.isRoleExist(role)) { logger.info("A Role with name " + role.getName() + " already exist"); return new ResponseEntity<Void>(HttpStatus.CONFLICT); }//ww w . ja v a 2 s.co m roleService.addRole(role); HttpHeaders headers = new HttpHeaders(); headers.setLocation(ucBuilder.path("/role/{id}").buildAndExpand(role.getId()).toUri()); return new ResponseEntity<Void>(headers, HttpStatus.CREATED); }
From source file:org.cloudfoundry.identity.uaa.scim.remote.RemoteScimUserProvisioningTests.java
@Test public void testRemoveUser() { HttpHeaders headers = new HttpHeaders(); headers.set("If-Match", "123456789"); Mockito.when(restTemplate.exchange(Mockito.eq("http://base/User/{id}"), Mockito.eq(HttpMethod.DELETE), Mockito.argThat(new HttpHeadersMatcher()), Mockito.eq(ScimUser.class), Mockito.eq("1234"))) .thenReturn(new ResponseEntity<ScimUser>(user, HttpStatus.OK)); service.delete("1234", 123456789); }
From source file:org.makersoft.mvc.unit.RESTfulMappingHanderMappingTests.java
@Test public void testShow() throws Exception { HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.setContentType(MediaType.TEXT_HTML); mockMvc.perform(get("/account/dept/1").accept(MediaType.TEXT_HTML).headers(httpHeaders)).andDo(print()) .andExpect(status().isOk()).andExpect(view().name("account/dept/show")) .andExpect(forwardedUrl("/WEB-INF/views/account/dept/show.jsp")); }
From source file:com.orange.clara.cloud.poc.s3.controller.PocS3Controller.java
@RequestMapping(value = "/download/{fileName:.*}", method = RequestMethod.GET) public ResponseEntity<InputStreamResource> download(@PathVariable String fileName) throws IOException { Blob blob = this.blobStore.getBlob(fileName); HttpHeaders respHeaders = new HttpHeaders(); respHeaders.setContentType(MediaType.APPLICATION_OCTET_STREAM); respHeaders.setContentLength(blob.getPayload().getContentMetadata().getContentLength()); respHeaders.setContentDispositionFormData("attachment", fileName); InputStream inputStream = blob.getPayload().openStream(); InputStreamResource isr = new InputStreamResource(inputStream); return new ResponseEntity<>(isr, respHeaders, HttpStatus.OK); }
From source file:eu.dime.dnsregister.controllers.RecordsController.java
@RequestMapping(value = "/findbyip", headers = "Accept=application/json") @ResponseBody//from ww w. ja v a2 s. c om public ResponseEntity<String> showJson(@RequestParam(required = true) String ip) { Records records = null; try { records = Records.findRecordsesByContentEquals(ip).getSingleResult(); } catch (Exception e) { System.out.println("Obviament la excepcio l'has creat tu [" + Records.findRecordsesByContentEquals(ip)); } HttpHeaders headers = new HttpHeaders(); headers.add("Content-Type", "application/json; charset=utf-8"); if (records == null) { return new ResponseEntity<String>(headers, HttpStatus.NOT_FOUND); } return new ResponseEntity<String>("{\"publickey\":\"" + records.getPublickey() + "\"}", headers, HttpStatus.OK); }