Example usage for org.springframework.http HttpHeaders HttpHeaders

List of usage examples for org.springframework.http HttpHeaders HttpHeaders

Introduction

In this page you can find the example usage for org.springframework.http HttpHeaders HttpHeaders.

Prototype

public HttpHeaders() 

Source Link

Document

Construct a new, empty instance of the HttpHeaders object.

Usage

From source file:org.openbaton.nfvo.vnfm_reg.impl.sender.RestVnfmSender.java

@PostConstruct
private void init() {
    this.rest = new RestTemplate();
    this.headers = new HttpHeaders();
    headers.add("Content-Type", "application/json");
    headers.add("Accept", "*/*");
}

From source file:ar.com.aleatoria.ue.rest.SimpleClientHttpResponse.java

public HttpHeaders getHeaders() {
    if (this.headers == null) {
        this.headers = new HttpHeaders();
        // Header field 0 is the status line for most HttpURLConnections, but not on GAE
        String name = this.connection.getHeaderFieldKey(0);
        if (StringUtils.hasLength(name)) {
            this.headers.add(name, this.connection.getHeaderField(0));
        }// www  .  j a  va  2  s.  com
        int i = 1;
        while (true) {
            name = this.connection.getHeaderFieldKey(i);
            if (!StringUtils.hasLength(name)) {
                break;
            }
            this.headers.add(name, this.connection.getHeaderField(i));
            i++;
        }
    }
    return this.headers;
}

From source file:edu.mayo.cts2.uriresolver.controller.ResolveURI.java

@RequestMapping(method = RequestMethod.PUT, value = "/ids/{type}/{identifier}")
public ResponseEntity<String> saveIdentifiers(@RequestBody UriResults uriResults, @PathVariable String type,
        @PathVariable String identifier) {
    logger.info("\n\nsaveIdentifiers\n\n");
    uriDAO.saveIdentifiers(uriResults);/*  w w w . j  a  va2s .co m*/
    logger.info("finshed saving");
    return new ResponseEntity<String>(new HttpHeaders(), HttpStatus.OK);
}

From source file:io.jmnarloch.spring.request.correlation.http.ClientHttpRequestCorrelationInterceptorTest.java

@Test
public void shouldNotSetHeader() throws IOException {

    // given/* w  w  w  .j  a va2 s .  com*/
    final HttpRequest request = mock(HttpRequest.class);
    final ClientHttpRequestExecution execution = mock(ClientHttpRequestExecution.class);
    final byte[] body = new byte[0];

    when(request.getHeaders()).thenReturn(new HttpHeaders());

    // when
    instance.intercept(request, body, execution);

    // then
    assertFalse(request.getHeaders().containsKey(RequestCorrelationConsts.HEADER_NAME));
    verify(execution).execute(request, body);
}

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  . java 2 s  .  c om*/
    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:org.moserp.product.rest.ProductController.java

@ResponseBody
@RequestMapping(method = RequestMethod.GET, value = "/{productId}/quantityOnHand")
public Quantity getProductQuantityOnHand(@RequestHeader(value = "Authorization") String authorization,
        @PathVariable String productId) {
    if (!moduleRegistry.isModuleRegistered(OtherResources.MODULE_INVENTORY)) {
        return Quantity.ZERO;
    }/*from   www. jav a 2s.  com*/
    HttpHeaders headers = new HttpHeaders();
    headers.put("Authorization", Collections.singletonList(authorization));
    HttpEntity request = new HttpEntity(headers);
    String url = "http://" + OtherResources.MODULE_INVENTORY + "/" + OtherResources.PRODUCTS + "/" + productId
            + "/quantityOnHand";
    ResponseEntity<Quantity> responseEntity = restTemplate.exchange(url, HttpMethod.GET, request,
            Quantity.class);
    return responseEntity.getBody();
}

From source file:io.github.autsia.crowly.controllers.DashboardController.java

@RequestMapping(value = "/campaigns/export/{campaignId}", method = RequestMethod.GET)
public ResponseEntity<byte[]> export(@PathVariable("campaignId") String campaignId, ModelMap model)
        throws DocumentException {
    Document document = new Document();
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    PdfWriter.getInstance(document, byteArrayOutputStream);
    document.open();//from  www.j a v  a 2  s. c om
    Gson gson = new Gson();
    String json = gson.toJson(mentionRepository.findByCampaignId(campaignId));
    document.add(new Paragraph(json));
    document.close();

    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.parseMediaType("application/pdf"));
    String filename = "output.pdf";
    headers.setContentDispositionFormData(filename, filename);
    headers.setCacheControl("must-revalidate, post-check=0, pre-check=0");
    ResponseEntity<byte[]> response = new ResponseEntity<byte[]>(byteArrayOutputStream.toByteArray(), headers,
            HttpStatus.OK);
    return response;
}

From source file:com.salmon.security.xacml.demo.springmvc.rest.controller.MarketPlacePopulatorController.java

@RequestMapping(method = RequestMethod.POST, consumes = "application/json", produces = "application/json", value = "vehicleadd")
@ResponseStatus(HttpStatus.CREATED)//from   w w w .  j a  v a  2 s  . co m
@ResponseBody
public ResponseEntity<Vehicle> createVehicle(@RequestBody Vehicle vehicle, UriComponentsBuilder builder) {

    LOG.info("REST CREATE Vechicle - " + vehicle.toString());

    marketPlaceController.registerVehicle(vehicle);

    HttpHeaders headers = new HttpHeaders();

    URI newVehicleLocation = builder.path("/aggregators/dvla/vehicles/{plate}")
            .buildAndExpand(vehicle.getPlate()).toUri();

    LOG.info("REST CREATE VEHICLE - new vehicle @ " + newVehicleLocation.toString());

    headers.setLocation(newVehicleLocation);

    return new ResponseEntity<Vehicle>(vehicle, headers, HttpStatus.CREATED);
}

From source file:org.openbaton.nfvo.api.exceptions.GlobalExceptionHandler.java

@ExceptionHandler({ BadRequestException.class, BadFormatException.class, NetworkServiceIntegrityException.class,
        WrongStatusException.class, UnrecognizedPropertyException.class, VimException.class,
        CyclicDependenciesException.class, WrongAction.class, PasswordWeakException.class })
@ResponseStatus(value = HttpStatus.BAD_REQUEST)
protected ResponseEntity<Object> handleInvalidRequest(Exception e, WebRequest request) {
    if (log.isDebugEnabled()) {
        log.error("Exception was thrown -> Return message: " + e.getMessage(), e);
    } else {/*from w ww  .  j av  a  2 s.co m*/
        log.error("Exception was thrown -> Return message: " + e.getMessage());
    }
    ExceptionResource exc = new ExceptionResource("Bad Request", e.getMessage());
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_JSON);

    return handleExceptionInternal(e, exc, headers, HttpStatus.UNPROCESSABLE_ENTITY, request);
}

From source file:com.tamnd2.basicwebapp.rest.mvc.BlogController.java

@RequestMapping(value = "/{blogId}/blog-entries", method = RequestMethod.POST)
public ResponseEntity<BlogEntryResource> createBlogEntry(@PathVariable Long blogId,
        @RequestBody BlogEntryResource sentBlogEntry) {
    BlogEntry createdBlogEntry = null;/*  ww  w  .  j  av a  2s  . co m*/
    try {
        createdBlogEntry = blogService.createBlogEntry(blogId, sentBlogEntry.toBlogEntry());
        BlogEntryResource createdResource = new BlogEntryResourceAsm().toResource(createdBlogEntry);
        HttpHeaders headers = new HttpHeaders();
        headers.setLocation(URI.create(createdResource.getLink("self").getHref()));
        return new ResponseEntity<BlogEntryResource>(createdResource, headers, HttpStatus.CREATED);
    } catch (BlogNotFoundException e) {
        throw new NotFoundException(e);
    }
}