Example usage for org.springframework.http HttpHeaders set

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

Introduction

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

Prototype

@Override
public void set(String headerName, @Nullable String headerValue) 

Source Link

Document

Set the given, single header value under the given name.

Usage

From source file:org.zalando.riptide.Actions.java

/**
 * Normalizes the {@code Location} and {@code Content-Location} headers of any given response by resolving them
 * against the given {@code uri}.//w  w w  .  j  a  v a2  s  .  c  om
 *
 * @param uri the base uri to resolve against
 * @return a function that normalizes responses
 */
public static ThrowingFunction<ClientHttpResponse, ClientHttpResponse, IOException> normalize(final URI uri) {
    return response -> {
        final HttpHeaders headers = new HttpHeaders();
        headers.putAll(response.getHeaders());

        Optional.ofNullable(headers.getLocation()).map(uri::resolve).ifPresent(headers::setLocation);

        Optional.ofNullable(headers.getFirst(CONTENT_LOCATION)).map(uri::resolve)
                .ifPresent(location -> headers.set(CONTENT_LOCATION, location.toASCIIString()));

        return new ForwardingClientHttpResponse() {

            @Override
            protected ClientHttpResponse delegate() {
                return response;
            }

            @Override
            public HttpHeaders getHeaders() {
                return headers;
            }

        };
    };
}

From source file:com.groupdocs.HomeController.java

protected static ResponseEntity<String> typeOut(Object obj, MediaType mediaType) {
    HttpHeaders httpHeaders = new HttpHeaders();
    if (mediaType == MediaType.APPLICATION_JSON) {
        httpHeaders.set("Content-type", "application/json;charset=UTF-8");
    } else {//from w  w w . j a  v  a 2s .com
        httpHeaders.setContentType(mediaType);
    }
    return new ResponseEntity<String>(obj.toString(), httpHeaders, HttpStatus.CREATED);
}

From source file:net.slkdev.swagger.confluence.service.impl.XHtmlToConfluenceServiceImpl.java

private static HttpHeaders buildHttpHeaders(final String confluenceAuthentication) {
    final HttpHeaders headers = new HttpHeaders();
    headers.set("Authorization", String.format("Basic %s", confluenceAuthentication));
    headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON_UTF8));
    headers.setContentType(MediaType.APPLICATION_JSON_UTF8);

    return headers;
}

From source file:org.schedoscope.metascope.controller.MetascopeAdminControllerTest.java

@Test
public void sometest() throws Exception {
    HttpHeaders headers = new HttpHeaders();
    headers.set("Referer", "/test");
    HttpEntity<String> entity = new HttpEntity<String>("parameters", headers);

    ResponseEntity<String> response = this.restTemplate.exchange("/admin/sync", HttpMethod.POST, entity,
            String.class);
    assertEquals(302, response.getStatusCodeValue());
    assertTrue(response.getHeaders().get("Location").get(0).endsWith("/test"));
}

From source file:org.busko.routemanager.web.RoutePlotterController.java

@RequestMapping(method = RequestMethod.GET)
public ResponseEntity<byte[]> handheldApk(Model uiModel, HttpServletRequest httpServletRequest)
        throws Exception {
    InputStream input = getClass().getClassLoader().getResourceAsStream("BuskoPlotter.apk");
    int fileSize = input.available();
    byte[] bytes = new byte[fileSize];
    input.read(bytes);/* w  w w  .  j a  v  a  2  s. com*/
    input.close();

    HttpHeaders responseHeaders = new HttpHeaders();
    responseHeaders.set("Content-Disposition", "attachment;filename=BuskoPlotter.apk");
    responseHeaders.set("Content-Length", Integer.toString(fileSize));
    responseHeaders.set("Content-Type", "application/vnd.android.package-archive");
    return new ResponseEntity<byte[]>(bytes, responseHeaders, HttpStatus.OK);
}

From source file:org.busko.routemanager.web.admin.community.RouteSubmissionController.java

@RequestMapping(params = "view", value = "/{id}", method = RequestMethod.GET)
public ResponseEntity<byte[]> view(@PathVariable("id") Long id, Model uiModel) throws Exception {
    RouteSubmission routeSubmission = RouteSubmission.findRouteSubmission(id);

    HttpHeaders responseHeaders = new HttpHeaders();
    responseHeaders.set("Content-Disposition", "attachment;filename=" + routeSubmission.getUsername() + ".xml");
    responseHeaders.set("Content-Length", Integer.toString(routeSubmission.getFileContent().length));
    //        responseHeaders.set("Content-Type", "text/plain; charset=UTF-8");
    responseHeaders.set("Content-Type", "text/xml");
    return new ResponseEntity<byte[]>(routeSubmission.getFileContent(), responseHeaders, HttpStatus.OK);
}

From source file:org.energyos.espi.thirdparty.repository.impl.ResourceRESTRepositoryImpl.java

public IdentifiedObject get(Authorization authorization, String url) {
    HttpHeaders requestHeaders = new HttpHeaders();
    requestHeaders.set("Authorization", "Bearer " + authorization.getAccessToken());
    @SuppressWarnings({ "rawtypes", "unchecked" })
    HttpEntity<?> requestEntity = new HttpEntity(requestHeaders);

    HttpEntity<String> response = template.exchange(url, HttpMethod.GET, requestEntity, String.class);

    return (IdentifiedObject) marshaller.unmarshal(new StreamSource(response.getBody()));
}

From source file:org.trustedanalytics.routermetrics.gathering.GatheringConfig.java

private HttpEntity<byte[]> getGorouterHeaders() {
    HttpHeaders headers = new HttpHeaders();
    headers.set("Authorization",
            "Basic " + new String(
                    encodeBase64((gorouterProperties.getUsername() + ":" + gorouterProperties.getPassword())
                            .getBytes(Charset.forName("US-ASCII")))));
    return new HttpEntity<>(headers);
}

From source file:com.appglu.impl.ApiHeadersTest.java

@Override
protected HttpHeaders createDefaultHttpHeaders() {
    HttpHeaders defaultHttpHeaders = super.createDefaultHttpHeaders();
    defaultHttpHeaders.set("ApiVersion", "2.0");
    defaultHttpHeaders.set("AppgluVersion", "1.0");
    return defaultHttpHeaders;
}

From source file:org.schedoscope.metascope.controller.MetascopeDataDistributionControllerTest.java

@Test
public void sometest() throws Exception {
    HttpHeaders headers = new HttpHeaders();
    headers.set("Referer", "/test");

    HttpEntity<String> entity = new HttpEntity<String>("parameters", headers);

    ResponseEntity<String> response = this.restTemplate.exchange("/datadistribution/start?fqdn=test",
            HttpMethod.POST, entity, String.class);
    assertEquals(302, response.getStatusCodeValue());
    assertTrue(response.getHeaders().get("Location").get(0).endsWith("/test#datadistributionContent"));
}