Example usage for org.springframework.http HttpHeaders put

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

Introduction

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

Prototype

@Override
    public List<String> put(String key, List<String> value) 

Source Link

Usage

From source file:org.spearal.spring.rest.SpearalEntity.java

private static HttpHeaders toHeaders(SpearalFactory factory,
        SpearalPropertyFilterBuilder serverPropertyFilterBuilder) {
    HttpHeaders headers = new HttpHeaders();
    if (serverPropertyFilterBuilder == null)
        return headers;
    headers.put(PROPERTY_FILTER_HEADER, serverPropertyFilterBuilder.toHeaders(factory.getContext()));
    return headers;
}

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;
    }// w ww . j a va  2  s .c  o m
    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:com.ginema.ApplicationTests.java

@Test
public void loginSucceeds() {
    ResponseEntity<String> response = template.getForEntity("http://localhost:" + port + "/ginema-server/login",
            String.class);
    String csrf = getCsrf(response.getBody());
    MultiValueMap<String, String> form = new LinkedMultiValueMap<String, String>();
    form.set("username", "user");
    form.set("password", "password");
    form.set("_csrf", csrf);
    HttpHeaders headers = new HttpHeaders();
    headers.put("COOKIE", response.getHeaders().get("Set-Cookie"));
    RequestEntity<MultiValueMap<String, String>> request = new RequestEntity<MultiValueMap<String, String>>(
            form, headers, HttpMethod.POST, URI.create("http://localhost:" + port + "/ginema-server/login"));
    ResponseEntity<Void> location = template.exchange(request, Void.class);
    assertEquals("http://localhost:" + port + "/ginema-server/", location.getHeaders().getFirst("Location"));
}

From source file:org.zaizi.AuthServerApplicationTests.java

@Test
public void loginSucceeds() {
    ResponseEntity<String> response = template.getForEntity("http://localhost:" + port + contextPath + "/login",
            String.class);
    String csrf = getCsrf(response.getBody());
    MultiValueMap<String, String> form = new LinkedMultiValueMap<String, String>();
    form.set("username", "admin");
    form.set("password", "ulibraxi");
    form.set("_csrf", csrf);
    HttpHeaders headers = new HttpHeaders();
    headers.put("COOKIE", response.getHeaders().get("Set-Cookie"));
    RequestEntity<MultiValueMap<String, String>> request = new RequestEntity<MultiValueMap<String, String>>(
            form, headers, HttpMethod.POST, URI.create("http://localhost:" + port + contextPath + "/login"));
    ResponseEntity<Void> location = template.exchange(request, Void.class);
    assertEquals("http://localhost:" + port + contextPath + "/", location.getHeaders().getFirst("Location"));
}

From source file:cz.jirutka.spring.http.client.cache.internal.InMemoryClientHttpResponse.java

public InMemoryClientHttpResponse deepCopy() {
    HttpHeaders headersCopy = new HttpHeaders();
    for (Entry<String, List<String>> entry : headers.entrySet()) {
        headersCopy.put(entry.getKey(), new LinkedList<>(entry.getValue()));
    }/*from ww  w .  j  a  v  a  2  s.c o m*/
    return new InMemoryClientHttpResponse(body.clone(), statusCode, headersCopy);
}

From source file:io.bosh.client.jobs.SpringJobs.java

private Observable<Task> changeJobState(String deploymentName, Consumer<UriComponentsBuilder> builderCallback) {
    HttpHeaders headers = new HttpHeaders();
    headers.put("content-type", Arrays.asList("text/yaml"));

    return deployments.get(deploymentName)
            .flatMap(deployment -> exchangeForEntity(deployment.getRawManifest(), Void.class, headers,
                    HttpMethod.PUT, builder -> builderCallback.accept(builder)))
            .flatMap(response -> tasks.trackToCompletion(getTaskId(response)));
}

From source file:com.jim.im.core.topic.service.CommHeaderInterceptor.java

@Override
public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution)
        throws IOException {
    HttpHeaders headers = request.getHeaders();
    if (this._headers != null) {
        for (Map.Entry<String, List<String>> entry : _headers.entrySet()) {
            headers.put(entry.getKey(), entry.getValue());
        }/*from w  w  w .  j  a v  a  2s .c  o m*/
    }
    return execution.execute(request, body);

}

From source file:org.agatom.springatom.web.controller.SVDefaultController.java

protected <T> ResponseEntity<T> response(final HttpHeaders headers, final T body, final HttpStatus status) {
    final HttpHeaders httpHeaders = new HttpHeaders();

    if (null != headers) {
        httpHeaders.putAll(headers);/* www . j  a  v a2 s.  co  m*/
    }

    httpHeaders.put("sa-error", Collections.singletonList(Boolean.TRUE.toString()));

    return new ResponseEntity<>(body, httpHeaders, status);
}

From source file:HCEngine.java

@Override
public ResponseEntity<String> submit(JCurlRequestOptions requestOptions) throws Exception {
    ResponseEntity<String> stringResponseEntity = null;
    try (CloseableHttpClient hc = createCloseableHttpClient()) {
        for (int i = 0; i < requestOptions.getCount(); i++) {
            final HttpHeaders headers = new HttpHeaders();
            for (Map.Entry<String, String> e : requestOptions.getHeaderMap().entrySet()) {
                headers.put(e.getKey(), Collections.singletonList(e.getValue()));
            }/*ww w .j a  v a  2 s  . com*/

            final HttpEntity<Void> requestEntity = new HttpEntity<>(headers);

            RestTemplate template = new RestTemplate(new HttpComponentsClientHttpRequestFactory(hc));

            stringResponseEntity = template.exchange(requestOptions.getUrl(), HttpMethod.GET, requestEntity,
                    String.class);
            System.out.println(stringResponseEntity.getBody());

        }
        return stringResponseEntity;
    }
}

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

public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution)
        throws IOException {

    HttpRequestWrapper wrapper = new HttpRequestWrapper(request) {

        @Override//from   w  w w.j  a  v  a 2 s.  c o  m
        public URI getURI() {
            URI uri = super.getURI();
            String fragment = uri.toString();
            String url = baseUrl + fragment;
            try {
                return new URI(url);
            } catch (URISyntaxException ex) {
                throw new IllegalArgumentException("Could not create HTTP URL from [" + url + "]: " + ex, ex);
            }
        }

        @Override
        public HttpHeaders getHeaders() {
            HttpHeaders headers = super.getHeaders();

            if (StringUtils.isNotEmpty(applicationEnvironment)) {
                headers.put("X-AppGlu-Environment", Arrays.asList(applicationEnvironment));
            }

            headers.putAll(defaultHeaders);
            return headers;
        }

    };

    return execution.execute(wrapper, body);
}