List of usage examples for org.springframework.http HttpHeaders HttpHeaders
public HttpHeaders()
From source file:eu.falcon.semantic.client.DenaClient.java
public static String runQuery(String sparqlQuery) { final String uri = "http://falconsemanticmanager.euprojects.net/api/v1/ontology/query/run"; //final String uri = "http://localhost:8090/api/v1/ontology/query/run"; HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); RestTemplate restTemplate = new RestTemplate(); HttpEntity<String> entity = new HttpEntity<>(sparqlQuery, headers); String result = restTemplate.postForObject(uri, entity, String.class); return result; }
From source file:hello.TodoController.java
@RequestMapping(method = RequestMethod.GET, produces = "application/json") public ResponseEntity<Iterable<Todo>> list() { HttpHeaders headers = new HttpHeaders(); headers.add("Accept-Patch", "application/json-patch+json"); return new ResponseEntity<Iterable<Todo>>(repository.findAll(), headers, HttpStatus.OK); }
From source file:org.nubomedia.marketplace.api.exceptions.GlobalExceptionHandler.java
@ExceptionHandler({ NotFoundException.class }) @ResponseStatus(value = HttpStatus.NOT_FOUND) protected ResponseEntity<Object> handleNotFoundException(HttpServletRequest req, Exception e) { log.error("Exception with message " + e.getMessage() + " was thrown"); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); Map body = new HashMap<>(); body.put("error", "Not Found"); body.put("exception", e.getClass().toString()); body.put("message", e.getMessage()); body.put("path", req.getRequestURI()); body.put("status", HttpStatus.NOT_FOUND.value()); body.put("timestamp", new Date().getTime()); ResponseEntity responseEntity = new ResponseEntity(body, headers, HttpStatus.NOT_FOUND); return responseEntity; }
From source file:cz.jirutka.spring.http.client.cache.internal.InMemoryClientHttpResponse.java
public InMemoryClientHttpResponse(byte[] body, HttpStatus statusCode, HttpHeaders headers) { Assert.notNull(statusCode, "statusCode must not be null"); this.body = body != null ? body : new byte[0]; this.statusCode = statusCode; this.headers = headers != null ? headers : new HttpHeaders(); }
From source file:org.cloudfoundry.identity.uaa.integration.ClientInfoEndpointIntegrationTests.java
@Test public void testGetClientInfo() throws Exception { HttpHeaders headers = new HttpHeaders(); AuthorizationCodeResourceDetails app = testAccounts.getDefaultAuthorizationCodeResource(); headers.set("Authorization", testAccounts.getAuthorizationHeader(app.getClientId(), app.getClientSecret())); headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON)); @SuppressWarnings("rawtypes") ResponseEntity<Map> response = serverRunning.getForObject("/clientinfo", Map.class, headers); assertEquals(HttpStatus.OK, response.getStatusCode()); assertEquals(app.getClientId(), response.getBody().get("client_id")); }
From source file:org.openschedule.api.impl.SessionTemplate.java
public void addBlockComment(String shortName, Integer dayId, Integer scheduleId, Integer blockId, Comment comment) {/*from www .j av a 2s .com*/ HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.setContentType(new MediaType("application", "json")); HttpEntity<Comment> requestEntity = new HttpEntity<Comment>(comment, requestHeaders); restTemplate.exchange( "public/" + shortName + "/days/" + dayId + "/schedules/" + scheduleId + "/blocks/" + blockId + "/comments", HttpMethod.POST, requestEntity, String.class, shortName, dayId, scheduleId, blockId).getBody(); }
From source file:cz.muni.fi.mushroomhunter.restclient.LocationUpdateSwingWorker.java
@Override protected Integer doInBackground() throws Exception { DefaultTableModel model = (DefaultTableModel) restClient.getTblLocation().getModel(); int selectedRow = restClient.getTblLocation().getSelectedRow(); String plainCreds = RestClient.USER_NAME + ":" + RestClient.PASSWORD; byte[] plainCredsBytes = plainCreds.getBytes(); byte[] base64CredsBytes = Base64.encodeBase64(plainCredsBytes); String base64Creds = new String(base64CredsBytes); RestTemplate restTemplate = new RestTemplate(); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); List<MediaType> mediaTypeList = new ArrayList<>(); mediaTypeList.add(MediaType.ALL);/* w ww. j a va 2 s. c om*/ headers.setAccept(mediaTypeList); headers.add("Authorization", "Basic " + base64Creds); HttpEntity request = new HttpEntity<>(headers); ResponseEntity<LocationDto> responseEntity = restTemplate.exchange( RestClient.SERVER_URL + "pa165/rest/location/" + RestClient.getLocationIDs().get(selectedRow), HttpMethod.GET, request, LocationDto.class); LocationDto locationDto = responseEntity.getBody(); locationDto.setName(restClient.getTfLocationName().getText()); locationDto.setDescription(restClient.getTfLocationDescription().getText()); locationDto.setNearCity(restClient.getTfLocationNearCity().getText()); ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter(); String json = ow.writeValueAsString(locationDto); request = new HttpEntity(json, headers); restTemplate.exchange(RestClient.SERVER_URL + "pa165/rest/location", HttpMethod.PUT, request, LocationDto.class); return selectedRow; }
From source file:sample.jetty.SampleJetty8ApplicationTests.java
private HttpHeaders createHeaders(final String username, final String password) { return new HttpHeaders() { {// w w w . j a v a 2 s .c om String auth = username + ":" + password; byte[] encodedAuth = Base64.encodeBase64(auth.getBytes(Charset.forName("US-ASCII"))); String authHeader = "Basic " + new String(encodedAuth); set("Authorization", authHeader); } }; }
From source file:org.trustedanalytics.servicebroker.gearpump.service.externals.helpers.CfCaller.java
public HttpHeaders createJsonHeaders() { HttpHeaders headers = new HttpHeaders(); headers.add("Accept", "application/json"); headers.add("Content-type", "application/json"); return headers; }
From source file:io.sevenluck.chat.controller.ChatMemberController.java
@ExceptionHandler @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) public ResponseEntity<?> handleException(MemberAlreadyExistsException e) { logger.error("validate:", e.getMessage()); return new ResponseEntity<>(ExceptionDTO.newConflictInstance(e.getMessage()), new HttpHeaders(), HttpStatus.CONFLICT);//from w ww . j av a 2 s. com }