List of usage examples for org.springframework.http HttpHeaders HttpHeaders
public HttpHeaders()
From source file:com.kolich.spring.controllers.KolichControllerClosure.java
public static final ResponseEntity<byte[]> getResponseEntity(final KolichCommonEntity entity, final HttpHeaders headers, final MediaType contentType, final HttpStatus status) { final HttpHeaders merged = new HttpHeaders(); if (headers != null) { merged.putAll(headers);/*from www. j a va 2s. c o m*/ } merged.setContentType(contentType); return getResponseEntity(entity, merged, status); }
From source file:com.allogy.amazonaws.elasticbeanstalk.worker.simulator.application.WorkerApplication.java
private HttpEntity<String> createHttpEntity(MessageWrapper messageWrapper, Message message) { String messageId = message.getMessageId(); HttpHeaders headers = new HttpHeaders(); headers.set("User-Agent", "aws-sqsd/1.1 (simulated bridge)"); headers.set("X-Aws-Sqsd-Msgid", messageId); headers.set("X-Aws-Sqsd-Queue", messageWrapper.getQueueName()); headers.set("X-Aws-Sqsd-Receive-Count", Integer.toString(messageWrapper.getMessageCount())); headers.setContentType(MediaType.APPLICATION_JSON); return new HttpEntity<>(message.getBody(), headers); }
From source file:eu.freme.broker.eservices.EPublishing.java
@RequestMapping(value = "/e-publishing/html", method = RequestMethod.POST) public ResponseEntity<byte[]> htmlToEPub(@RequestParam("htmlZip") MultipartFile file, @RequestParam("metadata") String jMetadata) throws InvalidZipException, EPubCreationException, IOException, MissingMetadataException { if (file.getSize() > maxUploadSize) { double size = maxUploadSize / (1024.0 * 1024); return new ResponseEntity<>(new byte[0], HttpStatus.BAD_REQUEST); //throw new BadRequestException(String.format("The uploaded file is too large. The maximum file size for uploads is %.2f MB", size)); }//from ww w . j a va 2 s .c o m Gson gson = new Gson(); Metadata metadata = gson.fromJson(jMetadata, Metadata.class); HttpHeaders responseHeaders = new HttpHeaders(); responseHeaders.add("Content-Type", "application/epub+zip"); try { return new ResponseEntity<>(entityAPI.createEPUB(metadata, file.getInputStream()), HttpStatus.OK); } catch (InvalidZipException | EPubCreationException | IOException | MissingMetadataException ex) { logger.log(Level.SEVERE, ex.getMessage()); throw ex; } }
From source file:de.fhg.fokus.nubomedia.paas.VNFRServiceImpl.java
/** * Registers a new App to the VNFR with a specific VNFR ID * /*from w ww. j ava2 s. com*/ * @param externalAppId - application identifier * @param points - capacity */ public ApplicationRecord registerApplication(String externalAppId, int points) throws NotEnoughResourcesException { try { if (serviceProfile == null) { logger.info("Service Profile not set. make sure the VNFR_ID, VNFM_IP and VNFM_PORT are available "); return null; } String URL = serviceProfile.getServiceApiUrl(); ApplicationRecordBody bodyObj = new ApplicationRecordBody(externalAppId, points); Gson mapper = new GsonBuilder().create(); String body = mapper.toJson(bodyObj, ApplicationRecordBody.class); logger.info("registering new application: \nURL: " + URL + "\n + " + body); HttpHeaders creationHeader = new HttpHeaders(); creationHeader.add("Accept", "application/json"); creationHeader.add("Content-type", "application/json"); HttpEntity<String> registerEntity = new HttpEntity<String>(body, creationHeader); ResponseEntity response = restTemplate.exchange(URL, HttpMethod.POST, registerEntity, String.class); logger.info("response from VNFM " + response); HttpStatus status = response.getStatusCode(); if (status.equals(HttpStatus.CREATED) || status.equals(HttpStatus.OK)) { logger.info("Deployment status: " + status + " response: " + response); ApplicationRecord responseBody = mapper.fromJson((String) response.getBody(), ApplicationRecord.class); logger.info("returned object " + responseBody.toString()); return responseBody; } else if (status.equals(HttpStatus.UNPROCESSABLE_ENTITY)) { throw new NotEnoughResourcesException("Not enough resource " + response.getBody()); } } catch (NotEnoughResourcesException e) { logger.error(e.getMessage()); } catch (RestClientException e) { logger.error("Error registering application to VNFR - " + e.getMessage()); } return null; }
From source file:eu.agilejava.javaonedemo.api.CookBookUserResource.java
@RequestMapping(method = RequestMethod.POST, consumes = APPLICATION_JSON_VALUE) public ResponseEntity<CookBookUser> create(@RequestBody CookBookUser user) { cookBookUserService.create(user);//from w w w.j a v a 2 s . c o m HttpHeaders responseHeaders = new HttpHeaders(); responseHeaders.add("Location", ServletUriComponentsBuilder.fromCurrentRequestUri() .pathSegment(String.valueOf(user.getId())).build().toUriString()); return new ResponseEntity<>(responseHeaders, HttpStatus.CREATED); }
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:jetbrains.buildServer.vsoRooms.rest.impl.VSOTeamRoomsAPIConnectionImpl.java
private HttpHeaders getRequestHeaders() { final HttpHeaders headers = new HttpHeaders(); headers.add("Authorization", "Basic " + getEncodedCreds(myUser, myPassword)); headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON)); return headers; }
From source file:com.github.ffremont.microservices.springboot.node.services.MsService.java
/** * Retourne un MS// w w w. ja v a 2s . c o m * * @param msName * @return */ public MicroServiceRest getMs(String msName) { MasterUrlBuilder builder = new MasterUrlBuilder(cluster, node, masterhost, masterPort, masterCR); builder.setUri(msName); HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.parseMediaType(MS_JSON_TYPE_MIME))); HttpEntity<MicroServiceRest> entity = new HttpEntity<>(headers); ResponseEntity<MicroServiceRest> response = restTempate.exchange(builder.build(), HttpMethod.GET, entity, MicroServiceRest.class); return HttpStatus.OK.equals(response.getStatusCode()) ? response.getBody() : null; }
From source file:net.paslavsky.springrest.SpringRestClientMethodInterceptorTest.java
private HttpHeaders getAuthHttpHeaders() { HttpHeaders authHeaders = new HttpHeaders(); authHeaders.add("Auth", "######"); return authHeaders; }
From source file:web.EventLogRESTController.java
/** * Adds an event to the Event Log through REST API * @param el//from w w w .j a v a 2s . c o m * @param ucBuilder * @return */ @RequestMapping(value = "/api/eventlog/", method = RequestMethod.POST) public ResponseEntity<Void> addEvent(@RequestBody EventLog el, UriComponentsBuilder ucBuilder) { dao.addEvent(el); //returns newly added Event info HttpHeaders headers = new HttpHeaders(); headers.setLocation(ucBuilder.path("/api/eventlog/{id}").buildAndExpand(el.getEventid()).toUri()); return new ResponseEntity<Void>(headers, HttpStatus.CREATED); }