List of usage examples for org.springframework.http HttpHeaders set
@Override public void set(String headerName, @Nullable String headerValue)
From source file:com.jvoid.core.controller.HomeController.java
@RequestMapping(value = "/sign-up", method = RequestMethod.POST) public @ResponseBody String jvoidSignUpNewUser( @RequestParam(required = false, value = "params") JSONObject jsonParams) { System.out.println("sign-up:jsonParams=>" + jsonParams.toString()); RestTemplate restTemplate = new RestTemplate(); HttpHeaders headers = new HttpHeaders(); headers.set("Accept", MediaType.APPLICATION_JSON_VALUE); String uri = ""; try {/*ww w . j ava 2 s. co m*/ if (jsonParams.getInt("id") > 0) { uri = ServerUris.CUSTOMER_SERVER_URI + URIConstants.UPDATE_CUSTOMER; } else { uri = ServerUris.CUSTOMER_SERVER_URI + URIConstants.ADD_CUSTOMER; } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(uri).queryParam("params", jsonParams); HttpEntity<?> entity = new HttpEntity<>(headers); HttpEntity<String> returnString = restTemplate.exchange(builder.build().toUri(), HttpMethod.GET, entity, String.class); return returnString.getBody(); }
From source file:com.jvoid.core.controller.HomeController.java
@RequestMapping("/order") public @ResponseBody String orderProductNowById(@RequestParam("cartId") String cartId, @RequestParam("prodId") String productId) { RestTemplate restTemplate = new RestTemplate(); HttpHeaders headers = new HttpHeaders(); headers.set("Accept", MediaType.APPLICATION_JSON_VALUE); JSONObject jsonObj = new JSONObject(); try {/*from w ww. j av a 2s . c om*/ jsonObj.put("cartId", Integer.parseInt(cartId)); jsonObj.put("productId", Integer.parseInt(productId)); jsonObj.put("attributeId", 1); jsonObj.put("quantity", 1); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println("param jsonObj=>" + jsonObj.toString()); UriComponentsBuilder builder = UriComponentsBuilder .fromHttpUrl(ServerUris.QUOTE_SERVER_URI + URIConstants.ADD_PRODUCT_TO_CART) .queryParam("params", jsonObj); HttpEntity<?> entity = new HttpEntity<>(headers); HttpEntity<String> returnString = restTemplate.exchange(builder.build().toUri(), HttpMethod.GET, entity, String.class); return returnString.getBody(); }
From source file:com.jvoid.core.controller.HomeController.java
@RequestMapping("/jvoid-products") public @ResponseBody String listAllJVoidProductsForOutView() { RestTemplate restTemplate = new RestTemplate(); HttpHeaders headers = new HttpHeaders(); headers.set("Accept", MediaType.APPLICATION_JSON_VALUE); JSONObject jsonObj = new JSONObject(); try {/*from w w w . jav a 2s. c o m*/ jsonObj.put("id", -1); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } UriComponentsBuilder builder = UriComponentsBuilder .fromHttpUrl(ServerUris.PRODUCT_SERVER_URI + URIConstants.GET_PRODUCT) .queryParam("params", jsonObj); HttpEntity<?> entity = new HttpEntity<>(headers); HttpEntity<String> returnString = restTemplate.exchange(builder.build().toUri(), HttpMethod.GET, entity, String.class); JSONObject returnJsonObj = null; try { returnJsonObj = new JSONObject(returnString.getBody()); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } return returnJsonObj.toString(); }
From source file:com.jvoid.core.controller.HomeController.java
@RequestMapping("/jvoid-products-by-cat") public @ResponseBody String listAllJVoidProductsByCategoryForOutView(@RequestParam("catId") String catId) { RestTemplate restTemplate = new RestTemplate(); HttpHeaders headers = new HttpHeaders(); headers.set("Accept", MediaType.APPLICATION_JSON_VALUE); JSONObject jsonObj = new JSONObject(); try {/*from w ww . j av a2 s. c om*/ jsonObj.put("id", Integer.parseInt(catId)); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } UriComponentsBuilder builder = UriComponentsBuilder .fromHttpUrl(ServerUris.PRODUCT_SERVER_URI + URIConstants.GET_PRODUCTS_BY_CATEGORY) .queryParam("params", jsonObj); HttpEntity<?> entity = new HttpEntity<>(headers); HttpEntity<String> returnString = restTemplate.exchange(builder.build().toUri(), HttpMethod.GET, entity, String.class); JSONObject returnJsonObj = null; try { returnJsonObj = new JSONObject(returnString.getBody()); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } return returnJsonObj.toString(); }
From source file:com.jvoid.core.controller.HomeController.java
@RequestMapping("/jvoid-categories") public @ResponseBody String listAllJVoidCategoriesForOutView() { RestTemplate restTemplate = new RestTemplate(); HttpHeaders headers = new HttpHeaders(); headers.set("Accept", MediaType.APPLICATION_JSON_VALUE); JSONObject jsonObj = new JSONObject(); try {//from www. j a va 2 s.c o m jsonObj.put("id", -1); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } UriComponentsBuilder builder = UriComponentsBuilder .fromHttpUrl(ServerUris.PRODUCT_SERVER_URI + URIConstants.GET_CATEGORY) .queryParam("params", jsonObj); HttpEntity<?> entity = new HttpEntity<>(headers); HttpEntity<String> returnString = restTemplate.exchange(builder.build().toUri(), HttpMethod.GET, entity, String.class); JSONObject returnJsonObj = null; try { returnJsonObj = new JSONObject(returnString.getBody()); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } return returnJsonObj.toString(); }
From source file:com.jvoid.core.controller.HomeController.java
@RequestMapping("/login-tester") public @ResponseBody String jvoidLoginTester(@RequestParam("params") String jsonParams) { System.out.println("login-tester: jsonParams=>" + jsonParams); JSONObject jsonObj = null;//from w w w . j a v a 2s . com try { jsonObj = new JSONObject(jsonParams); } catch (JSONException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } System.out.println("Login-tester:jsonObj=>" + jsonObj); RestTemplate restTemplate = new RestTemplate(); HttpHeaders headers = new HttpHeaders(); headers.set("Accept", MediaType.APPLICATION_JSON_VALUE); UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:9080/jvoidcore/login") .queryParam("params", jsonObj); HttpEntity<?> entity = new HttpEntity<>(headers); HttpEntity<String> returnString = restTemplate.exchange(builder.build().toUri(), HttpMethod.POST, entity, String.class); System.out.println("returnString=>" + returnString); JSONObject returnJsonObj = null; try { returnJsonObj = new JSONObject(); returnJsonObj.put("result", returnString); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } return returnJsonObj.toString(); }
From source file:am.ik.categolj2.app.authentication.AuthenticationHelper.java
public HttpEntity<MultiValueMap<String, Object>> createRopRequest(String username, String password) { MultiValueMap<String, Object> params = new LinkedMultiValueMap<>(); params.add("username", username); params.add("password", password); params.add("grant_type", "password"); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); byte[] clientInfo = (adminClientProperties.getClientId() + ":" + adminClientProperties.getClientSecret()) .getBytes(StandardCharsets.UTF_8); String basic = new String(Base64.getEncoder().encode(clientInfo), StandardCharsets.UTF_8); headers.set(com.google.common.net.HttpHeaders.AUTHORIZATION, "Basic " + basic); return new HttpEntity<>(params, headers); }
From source file:com.fengduo.bee.web.controller.product.ProductController.java
/** * pdf?/*from w w w . j a va 2s . c om*/ * * @param id * @return * @throws IOException */ @RequestMapping("/item/{id}/download") public ResponseEntity<byte[]> download(@PathVariable("id") Long id) throws IOException { HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_OCTET_STREAM); headers.setContentDispositionFormData("attachment", ".pdf"); String name = ""; name = new String(name.getBytes(), "ISO8859-1"); headers.set("content-disposition", "attachment;filename=" + name + ".pdf"); if (Argument.isNotPositive(id)) { return new ResponseEntity<byte[]>(null, headers, HttpStatus.CREATED); } ItemFinance itemFinance = itemService.getItemFinanceByItemId(id); if (itemFinance == null) { return new ResponseEntity<byte[]>(null, headers, HttpStatus.CREATED); } String url = itemFinance.getPdfUrl(); File file = fileService.getFile(url); if (file == null) { return new ResponseEntity<byte[]>(null, headers, HttpStatus.CREATED); } return new ResponseEntity<byte[]>(FileUtils.readFileToByteArray(file), headers, HttpStatus.CREATED); }
From source file:com.jvoid.core.controller.HomeController.java
@RequestMapping(value = "/jvoid-checkout-cart", method = RequestMethod.POST) public @ResponseBody String jvoidChrckoutCart(@RequestParam("params") String jsonParams) { RestTemplate restTemplate = new RestTemplate(); HttpHeaders headers = new HttpHeaders(); headers.set("Accept", MediaType.APPLICATION_JSON_VALUE); System.out.println("jsonParams=>" + jsonParams); UriComponentsBuilder builder = UriComponentsBuilder .fromHttpUrl(ServerUris.QUOTE_SERVER_URI + URIConstants.CHECKOUT_CART) .queryParam("params", jsonParams); HttpEntity<?> entity = new HttpEntity<>(headers); HttpEntity<String> returnString = restTemplate.exchange(builder.build().toUri(), HttpMethod.GET, entity, String.class); JSONObject returnJsonObj = null;//w w w. j av a2s . c om try { returnJsonObj = new JSONObject(returnString.getBody()); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println("returnJsonObj=>" + returnJsonObj); String result = ""; try { result = returnJsonObj.getString("result"); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } String response = ""; if (result.equals("Success")) { UriComponentsBuilder builder1 = UriComponentsBuilder .fromHttpUrl(ServerUris.ORDER_SERVER_URI + URIConstants.ADD_ORDER) .queryParam("params", jsonParams); HttpEntity<?> entity1 = new HttpEntity<>(headers); HttpEntity<String> returnString1 = restTemplate.exchange(builder1.build().toUri(), HttpMethod.GET, entity1, String.class); response = returnString1.getBody(); } return response; }