List of usage examples for org.springframework.http HttpHeaders add
@Override public void add(String headerName, @Nullable String headerValue)
From source file:org.aksw.simba.cetus.web.CetusController.java
@RequestMapping("/fox") public ResponseEntity<String> fox(@RequestBody String data) { Document document = null;// w w w.j a v a 2 s . co m try { document = parser.getDocumentFromNIFString(data); } catch (Exception e) { LOGGER.error("Exception while parsing NIF string.", e); throw new IllegalArgumentException("Couldn't parse the given NIF document."); } document = foxBasedAnnotator.performTypeExtraction(document); // Add a header that clearly says, that we produce an utf-8 String. // Otherwise Spring might encode the response in the wrong way... HttpHeaders responseHeaders = new HttpHeaders(); responseHeaders.add("Content-Type", "application/x-turtle;charset=utf-8"); return new ResponseEntity<String>(creator.getDocumentAsNIFString(document), responseHeaders, HttpStatus.OK); }
From source file:ru.portal.controllers.RestController.java
/** * ? ? ? PortalTable// ww w . j a va2 s . c o m * @param isTable * @param id * @return * @throws JSONException */ @RequestMapping(method = RequestMethod.GET, produces = { MediaType.APPLICATION_JSON_VALUE }, value = { "/tables" }) @ResponseStatus(HttpStatus.OK) @ResponseBody public ResponseEntity<String> tables(@RequestParam(value = "Table", required = false) Boolean isTable, @RequestParam(value = "id", required = false) String id) throws JSONException { HttpHeaders headers = new HttpHeaders(); headers.add("Content-type", "application/json;charset=UTF-8"); return new ResponseEntity<>(generateTreeJson(isTable, id), headers, HttpStatus.OK); }
From source file:org.aksw.simba.cetus.web.CetusController.java
@RequestMapping(value = "/yago", produces = "application/x-turtle;charset=utf-8") public ResponseEntity<String> yago(@RequestBody String data) { Document document = null;/* w w w. ja v a 2 s .c o m*/ try { document = parser.getDocumentFromNIFString(data); } catch (Exception e) { LOGGER.error("Exception while parsing NIF string.", e); throw new IllegalArgumentException("Couldn't parse the given NIF document."); } LOGGER.info("Request: " + document.toString()); document = yagoBasedAnnotator.performTypeExtraction(document); LOGGER.info("Response: " + document.toString()); // Add a header that clearly says, that we produce an utf-8 String. // Otherwise Spring might encode the response in the wrong way... HttpHeaders responseHeaders = new HttpHeaders(); responseHeaders.add("Content-Type", "application/x-turtle;charset=utf-8"); return new ResponseEntity<String>(creator.getDocumentAsNIFString(document), responseHeaders, HttpStatus.OK); }
From source file:ca.qhrtech.services.implementations.BGGServiceImpl.java
private HttpEntity<?> buildXmlHttpHeader() { HttpHeaders headers = new HttpHeaders(); headers.add("Accept", MediaType.APPLICATION_XML_VALUE); return new HttpEntity<>(headers); }
From source file:cz.muni.fi.mushroomhunter.restclient.MushroomDeleteSwingWorker.java
@Override protected Integer doInBackground() throws Exception { int selectedRow = restClient.getTblMushroom().getSelectedRow(); RestTemplate restTemplate = new RestTemplate(); String plainCreds = RestClient.USER_NAME + ":" + RestClient.PASSWORD; byte[] plainCredsBytes = plainCreds.getBytes(); byte[] base64CredsBytes = Base64.encodeBase64(plainCredsBytes); String base64Creds = new String(base64CredsBytes); HttpHeaders headers = new HttpHeaders(); headers.add("Authorization", "Basic " + base64Creds); HttpEntity<String> request = new HttpEntity<>(headers); restTemplate.setRequestFactory(new HttpComponentsClientHttpRequestFactory() { @Override//from w w w . j a v a2 s .co m protected HttpUriRequest createHttpUriRequest(HttpMethod httpMethod, URI uri) { if (HttpMethod.DELETE == httpMethod) { return new HttpEntityEnclosingDeleteRequest(uri); } return super.createHttpUriRequest(httpMethod, uri); } }); restTemplate.exchange( RestClient.SERVER_URL + "pa165/rest/mushroom/" + RestClient.getMushroomIDs().get(selectedRow), HttpMethod.DELETE, request, MushroomDto.class); RestClient.getMushroomIDs().remove(selectedRow); return selectedRow; }
From source file:ru.portal.controllers.RestController.java
@RequestMapping(value = { "/random/{id}" }) @ResponseBody/*from w ww. j a v a 2 s . c o m*/ public DeferredResult<ResponseEntity<String>> random(@PathVariable Long id) { DeferredResult<ResponseEntity<String>> deferredResult = new DeferredResult<>(); String result = String.format("random : %s", ThreadLocalRandom.current().nextLong(id)); HttpHeaders headers = new HttpHeaders(); headers.add("Content-type", "application/json;charset=UTF-8"); ResponseEntity responseEntity = new ResponseEntity<>(result, headers, HttpStatus.OK); deferredResult.setResult(responseEntity); return deferredResult; }
From source file:com.tce.oauth2.spring.client.services.TodoService.java
public List<Todo> findAll(String accessToken) { HttpHeaders headers = new HttpHeaders(); headers.add("Authorization", "Bearer " + accessToken); HttpEntity<String> entity = new HttpEntity<String>(headers); ResponseEntity<Todo[]> response = restTemplate.exchange(OAUTH_RESOURCE_SERVER_URL + "/rest/todos", HttpMethod.GET, entity, Todo[].class); Todo[] todos = response.getBody();//w w w . j a va2s .co m return Arrays.asList(todos); }
From source file:com.tce.oauth2.spring.client.services.TodoService.java
public List<Todo> findByUsername(String accessToken, String username) { HttpHeaders headers = new HttpHeaders(); headers.add("Authorization", "Bearer " + accessToken); HttpEntity<String> entity = new HttpEntity<String>(headers); ResponseEntity<Todo[]> response = restTemplate.exchange( OAUTH_RESOURCE_SERVER_URL + "/rest/todos/" + username, HttpMethod.GET, entity, Todo[].class); Todo[] todos = response.getBody();/* w w w . j av a 2 s .c o m*/ return Arrays.asList(todos); }
From source file:cz.muni.fi.mushroomhunter.restclient.LocationDeleteSwingWorker.java
@Override protected Integer doInBackground() throws Exception { int selectedRow = restClient.getTblLocation().getSelectedRow(); RestTemplate restTemplate = new RestTemplate(); String plainCreds = RestClient.USER_NAME + ":" + RestClient.PASSWORD; byte[] plainCredsBytes = plainCreds.getBytes(); byte[] base64CredsBytes = Base64.encodeBase64(plainCredsBytes); String base64Creds = new String(base64CredsBytes); HttpHeaders headers = new HttpHeaders(); headers.add("Authorization", "Basic " + base64Creds); HttpEntity<String> request = new HttpEntity<>(headers); restTemplate.setRequestFactory(new HttpComponentsClientHttpRequestFactory() { @Override// ww w . j av a 2s. c om protected HttpUriRequest createHttpUriRequest(HttpMethod httpMethod, URI uri) { if (HttpMethod.DELETE == httpMethod) { return new HttpEntityEnclosingDeleteRequest(uri); } return super.createHttpUriRequest(httpMethod, uri); } }); restTemplate.exchange( RestClient.SERVER_URL + "pa165/rest/location/" + RestClient.getLocationIDs().get(selectedRow), HttpMethod.DELETE, request, LocationDto.class); RestClient.getLocationIDs().remove(selectedRow); return selectedRow; }
From source file:com.iata.ndc.trial.controllers.DefaultController.java
@RequestMapping(value = "/ba", method = RequestMethod.GET) public String getCal() { RestTemplate restTemplate = new RestTemplate(); List<HttpMessageConverter<?>> converters = new ArrayList<>(); MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter(); converter.getObjectMapper().configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true); converters.add(converter);/*from ww w .j a va 2 s . c o m*/ restTemplate.setMessageConverters(converters); HttpHeaders headers = new HttpHeaders(); headers.add("client-key", "zmd9apqgg2jwekf8zgqg5ybf"); headers.setContentType(MediaType.APPLICATION_JSON); ResponseEntity<BALocationsResponseWrapper> baLocationsResponse = restTemplate.exchange( "https://api.ba.com/rest-v1/v1/balocations", HttpMethod.GET, new HttpEntity<Object>(headers), BALocationsResponseWrapper.class); System.out.println(baLocationsResponse.getBody().getGetBALocationsResponse().getCountry().size()); return "index"; }