List of usage examples for org.springframework.http HttpHeaders HttpHeaders
public HttpHeaders()
From source file:wad.controller.ReceiptController.java
@RequestMapping(value = "/{id}", method = RequestMethod.GET) public ResponseEntity<byte[]> showReceipt(@PathVariable Long expenseId, @PathVariable Long id) { Receipt receipt = receiptRepository.findOne(id); Expense expense = expenseService.getExpense(expenseId); if (expense == null || !expense.isViewableBy(userService.getCurrentUser())) { throw new ResourceNotFoundException(); }/*from w ww . j a v a 2 s. com*/ final HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.parseMediaType(receipt.getMediaType())); headers.setContentLength(receipt.getSize()); headers.add("Content-Disposition", "attachment; filename=" + receipt.getName()); return new ResponseEntity<>(receipt.getContent(), headers, HttpStatus.CREATED); }
From source file:com.orange.cepheus.broker.ConfigurationTest.java
@Test public void getHeadersForBrokerWithNullParameters() { configuration.setRemoteServiceName(null); configuration.setRemoteServicePath(null); configuration.setRemoteAuthToken(null); HttpHeaders httpHeaders = new HttpHeaders(); configuration.addRemoteHeaders(httpHeaders); assertNull(httpHeaders.getFirst("Fiware-Service")); assertNull(httpHeaders.getFirst("Fiware-ServicePath")); assertNull(httpHeaders.getFirst("X-Auth-Token")); }
From source file:io.github.howiefh.jeews.modules.sys.controller.RoleController.java
@RequiresPermissions("role:create") @RequestMapping(value = "", method = RequestMethod.POST) public ResponseEntity<RoleResource> create(HttpEntity<Role> entity, HttpServletRequest request) throws URISyntaxException { Role role = entity.getBody(); roleService.save(role);/*from www.ja v a 2s. c om*/ HttpHeaders headers = new HttpHeaders(); RoleResource roleResource = new RoleResourceAssembler().toResource(role); headers.setLocation(entityLinks.linkForSingleResource(Role.class, role.getId()).toUri()); ResponseEntity<RoleResource> responseEntity = new ResponseEntity<RoleResource>(roleResource, headers, HttpStatus.CREATED); return responseEntity; }
From source file:org.springsource.sinspctr.rest.SInspctrController.java
@ResponseBody @RequestMapping(value = "/**/*.xml", method = RequestMethod.POST) public ResponseEntity<String> saveConfig(HttpServletRequest request, @RequestParam("xml") String xml) { ResponseEntity<String> response; HttpHeaders headers = new HttpHeaders(); headers.add("content-type", "application/json"); try {// ww w.j av a 2 s . c o m //"META-INF/spring/integration/spring-integration-context.xml" String servletPath = request.getServletPath(); if (servletPath.startsWith("/sinspctr/configs")) { servletPath = servletPath.substring("/sinspctr/configs".length(), servletPath.length()); } File siConfigFile = ResourceLocator.getClasspathRelativeFile(servletPath); FileCopyUtils.copy(siConfigFile, createBackupFile(siConfigFile)); siConfigFile.delete(); FileCopyUtils.copy(xml.getBytes(), siConfigFile); response = new ResponseEntity<String>("{\"status\":\"success\"}", HttpStatus.OK); return response; } catch (Exception e) { return new ResponseEntity<String>("{\"error\":\"" + e.getMessage() + "\"}", headers, HttpStatus.INTERNAL_SERVER_ERROR); } }
From source file:org.makersoft.mvc.unit.RESTfulMappingHanderMappingTests.java
@Test public void testIndex() throws Exception { HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.setContentType(MediaType.TEXT_HTML); mockMvc.perform(get("/account/dept").accept(MediaType.TEXT_HTML).headers(httpHeaders)).andDo(print()) .andExpect(status().isOk()).andExpect(view().name("account/dept/index")) .andExpect(forwardedUrl("/WEB-INF/views/account/dept/index.jsp")); }
From source file:com.xyxy.platform.examples.showcase.demos.hystrix.web.HystrixExceptionHandler.java
/** * ?Hystrix ClientException(404).//ww w . j a va 2s . c o m * ClientException?, ? */ @ExceptionHandler(value = { HystrixBadRequestException.class }) public final ResponseEntity<?> handleException(HystrixBadRequestException e, WebRequest request) { String message = Exceptions.getErrorMessageWithNestedException(e); logger.error(message, e); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.parseMediaType(MediaTypes.TEXT_PLAIN_UTF_8)); return handleExceptionInternal(e, message, headers, HttpStatus.BAD_REQUEST, request); }
From source file:com.github.carlomicieli.nerdmovies.controllers.ImageController.java
private ResponseEntity<byte[]> render(String movieId, ImageType t) throws IOException { ObjectId id = new ObjectId(movieId); Movie m = mongoTemplate.findById(id, Movie.class); byte[] aob = null; if (t == ImageType.POSTER) aob = m.getPoster();/* www . ja v a 2s . c om*/ else if (t == ImageType.THUMB) aob = m.getThumb(); if (aob == null) return null; InputStream in = new ByteArrayInputStream(aob); final HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.IMAGE_PNG); return new ResponseEntity<byte[]>(IOUtils.toByteArray(in), headers, HttpStatus.CREATED); }
From source file:com.logaritex.hadoop.configuration.manager.SimpleHttpService.java
private static HttpHeaders createHttpHeaders(String username, String password) { HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.set("Accept-Encoding", "gzip"); httpHeaders.set("Authorization", getBasicAuthHeaderValue(username, password)); httpHeaders.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON)); return httpHeaders; }
From source file:com.tservice.Logica.PersistenceFacede.java
public void realizarPago(Licencias licencia, InformacionPago pago) throws tserviceExceptions, Exception { HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); HttpEntity<String> entity = new HttpEntity<>(headers); String url = "http://serviciosrest.cloudhub.io/rest/PAYPAL/pago/tarjeta/" + pago.getNumeroTarjeta() + "/" + pago.getNombreTarjeta() + "/Credito/" + pago.getCodigoSeguridad() + "/" + usuarioactivo.getCorreo() + "/monto/" + (int) licencia.getValor() + "/seguridad/2/TService?servicio=pago"; //http://serviciosrest.cloudhub.io/rest/PAYPAL/pago/tarjeta/4916701440291035/Visa/Credito/9209/asd@asd.com/monto/1000/seguridad/2/TService?api=api2 ResponseEntity<Object> resultado = rest.exchange(url, HttpMethod.PUT, HttpEntity.EMPTY, Object.class); //http://serviciosrest.cloudhub.io/rest/PAYPAL/pago/tarjeta/4916701440291035/Visa/Credito/9209/asd@asd.com/monto/30/seguridad/2/TService?servicio=pago String resu = resultado.getBody().toString(); resu = resu.replace("{", ""); resu = resu.replace("}", ""); ResultadoTransaccion result = new ResultadoTransaccion(resu.split(",")[0].split("=")[1], Integer.parseInt(resu.split(",")[1].split("=")[1])); if (result.getCodTransaccion() == 0) { throw new tserviceExceptions("La tarjeta es invalida o el saldo es insuficiente por favor verifique"); } else//w ww.java2 s. co m resultadoTransaccion(result.getCodTransaccion(), licencia); }
From source file:sp.SAML1Controller.java
@RequestMapping(value = "/POST/ACS", method = RequestMethod.POST) public ResponseEntity<String> handleSSOResponsePOST(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws Exception { MessageContext<SAMLObject> messageContext = decodeInboundMessageContextPost(servletRequest); if (!(messageContext.getMessage() instanceof Response)) { log.error("Inbound message was not a SAML 1 Response"); return new ResponseEntity<>("Inbound message was not a SAML 1 Response", HttpStatus.BAD_REQUEST); }//from w w w.ja va2 s . c om Response response = (Response) messageContext.getMessage(); Element responseElement = response.getDOM(); String formattedMessage = SerializeSupport.prettyPrintXML(responseElement); log.trace("Returning response" + System.lineSeparator() + "{}", formattedMessage); //TODO instead of returning plain text via a ResponseEntity, add a JSP view that looks good HttpHeaders headers = new HttpHeaders(); headers.add("Content-Type", "text/plain"); return new ResponseEntity<>(formattedMessage, headers, HttpStatus.OK); }