Example usage for org.springframework.http HttpHeaders putAll

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

Introduction

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

Prototype

@Override
    public void putAll(Map<? extends String, ? extends List<String>> map) 

Source Link

Usage

From source file:org.cloudfoundry.identity.app.integration.ServerRunning.java

public ResponseEntity<Void> postForResponse(String path, HttpHeaders headers,
        MultiValueMap<String, String> params) {
    HttpHeaders actualHeaders = new HttpHeaders();
    actualHeaders.putAll(headers);
    actualHeaders.setContentType(MediaType.APPLICATION_FORM_URLENCODED);

    ResponseEntity<Void> exchange = client.exchange(getUrl(path), HttpMethod.POST,
            new HttpEntity<MultiValueMap<String, String>>(params, actualHeaders), Void.class);
    logger.debug("Response headers: " + exchange.getHeaders());
    return exchange;
}

From source file:org.cloudfoundry.identity.uaa.integration.ServerRunning.java

public ResponseEntity<Void> postForResponse(String path, HttpHeaders headers,
        MultiValueMap<String, String> params) {
    HttpHeaders actualHeaders = new HttpHeaders();
    actualHeaders.putAll(headers);
    actualHeaders.setContentType(MediaType.APPLICATION_FORM_URLENCODED);

    return client.exchange(getUrl(path), HttpMethod.POST, new HttpEntity<>(params, actualHeaders), Void.class);
}

From source file:org.cloudfoundry.identity.uaa.login.AbstractControllerInfo.java

protected HttpHeaders getRequestHeaders(HttpHeaders headers) {
    // Some of the headers coming back are poisonous apparently
    // (content-length?)...
    HttpHeaders outgoingHeaders = new HttpHeaders();
    outgoingHeaders.putAll(headers);
    outgoingHeaders.remove(HOST);/*  w  w w  .ja  v  a 2s .  c  om*/
    outgoingHeaders.remove(HOST.toLowerCase());
    outgoingHeaders.set(HOST, getUaaHost());
    logger.debug("Outgoing headers: " + outgoingHeaders);
    return outgoingHeaders;
}

From source file:org.cloudfoundry.identity.uaa.login.RemoteUaaController.java

@RequestMapping(value = "/oauth/authorize", params = "response_type")
public ModelAndView startAuthorization(HttpServletRequest request, @RequestParam Map<String, String> parameters,
        Map<String, Object> model, @RequestHeader HttpHeaders headers, Principal principal) throws Exception {

    String path = extractPath(request);

    MultiValueMap<String, String> map = new LinkedMaskingMultiValueMap<String, String>();
    map.setAll(parameters);//ww  w . j  av  a2  s  . c om

    String redirectUri = parameters.get("redirect-uri");
    if (redirectUri != null && !redirectUri.matches("(http:|https:)?//.*")) {
        redirectUri = "http://" + redirectUri;
        map.set("redirect-uri", redirectUri);
    }

    if (principal != null) {
        map.set("source", "login");
        map.setAll(getLoginCredentials(principal));
        map.remove("credentials"); // legacy cf might break otherwise
        map.remove("password"); // request for token will not use password
    } else {
        throw new BadCredentialsException("No principal found in authorize endpoint");
    }

    HttpHeaders requestHeaders = new HttpHeaders();
    requestHeaders.putAll(getRequestHeaders(headers));
    requestHeaders.remove(AUTHORIZATION.toLowerCase());
    requestHeaders.remove(USER_AGENT);
    requestHeaders.remove(ACCEPT.toLowerCase());
    requestHeaders.remove(CONTENT_TYPE.toLowerCase());
    requestHeaders.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
    requestHeaders.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
    requestHeaders.remove(COOKIE);
    requestHeaders.remove(COOKIE.toLowerCase());

    @SuppressWarnings("rawtypes")
    ResponseEntity<Map> response;

    response = authorizationTemplate.exchange(getUaaBaseUrl() + "/" + path, HttpMethod.POST,
            new HttpEntity<MultiValueMap<String, String>>(map, requestHeaders), Map.class);

    saveCookie(response.getHeaders(), model);

    @SuppressWarnings("unchecked")
    Map<String, Object> body = response.getBody();
    if (body != null) {
        // User approval is required
        logger.debug("Response: " + body);
        model.putAll(body);
        model.put("links", getLinksInfo());
        if (!body.containsKey("options")) {
            String errorMsg = "No options returned from UAA for user approval";
            if (body.containsKey("error")) {
                throw OAuth2Exception.create((String) body.get("error"),
                        (String) (body.containsKey("error_description") ? body.get("error_description")
                                : errorMsg));
            } else {
                throw new OAuth2Exception(errorMsg);
            }
        }
        logger.info("Approval required in /oauth/authorize for: " + principal.getName());
        return new ModelAndView("access_confirmation", model);
    }

    String location = response.getHeaders().getFirst("Location");
    if (location != null) {
        logger.info("Redirect in /oauth/authorize for: " + principal.getName());
        // Don't expose model attributes (cookie) in redirect
        return new ModelAndView(new RedirectView(location, false, true, false));
    }

    throw new IllegalStateException("Neither a redirect nor a user approval");

}

From source file:org.cloudfoundry.identity.uaa.login.RemoteUaaController.java

protected ResponseEntity<byte[]> passthru(HttpServletRequest request, HttpEntity entity,
        Map<String, Object> model, boolean loginClientRequired) throws Exception {

    String path = extractPath(request);

    RestOperations template = loginClientRequired ? getAuthorizationTemplate() : getDefaultTemplate();
    HttpHeaders requestHeaders = new HttpHeaders();
    requestHeaders.putAll(getRequestHeaders(entity.getHeaders()));
    requestHeaders.remove(COOKIE);//from   ww w . jav a  2 s . c  o m
    requestHeaders.remove(COOKIE.toLowerCase());
    // Get back end cookie if saved in session
    String cookie = (String) model.get(COOKIE_MODEL);
    if (cookie != null) {
        logger.debug("Found back end cookies: " + cookie);
        for (String value : cookie.split(";")) {
            requestHeaders.add(COOKIE, value);
        }
    }

    ResponseEntity<byte[]> response = template.exchange(getUaaBaseUrl() + "/" + path,
            HttpMethod.valueOf(request.getMethod()), new HttpEntity(entity.getBody(), requestHeaders),
            byte[].class);
    HttpHeaders outgoingHeaders = getResponseHeaders(response.getHeaders());
    return new ResponseEntity<byte[]>(response.getBody(), outgoingHeaders, response.getStatusCode());

}

From source file:org.cloudfoundry.identity.uaa.login.RemoteUaaController.java

protected HttpHeaders getResponseHeaders(HttpHeaders headers) {
    // Some of the headers coming back are poisonous apparently
    // (content-length?)...
    HttpHeaders outgoingHeaders = new HttpHeaders();
    outgoingHeaders.putAll(headers);
    if (headers.getContentLength() >= 0) {
        outgoingHeaders.remove(CONTENT_LENGTH);
        outgoingHeaders.remove(CONTENT_LENGTH.toLowerCase());
    }//  w ww .  j a va  2 s.  c  om
    if (headers.containsKey(TRANSFER_ENCODING)) {
        outgoingHeaders.remove(TRANSFER_ENCODING);
        outgoingHeaders.remove(TRANSFER_ENCODING.toLowerCase());
    }
    return outgoingHeaders;
}

From source file:org.jgrades.rest.client.StatefullRestTemplate.java

private Object insertCookieToHeaderIfApplicable(Object requestBody) {
    HttpEntity<?> httpEntity;/*from w ww . j  a v  a  2  s  .  c o m*/

    if (requestBody instanceof HttpEntity) {
        httpEntity = (HttpEntity<?>) requestBody;
    } else if (requestBody != null) {
        httpEntity = new HttpEntity<Object>(requestBody);
    } else {
        httpEntity = HttpEntity.EMPTY;
    }

    HttpHeaders httpHeaders = new HttpHeaders();
    httpHeaders.putAll(httpEntity.getHeaders());

    httpHeaders.set("Accept", MediaType.APPLICATION_JSON_VALUE);
    if (httpHeaders.getContentType() == null) {
        httpHeaders.setContentType(MediaType.APPLICATION_JSON);
    }

    if (StringUtils.isNotEmpty(cookie)) {
        httpHeaders.add("Cookie", cookie);
    }

    return new HttpEntity<>(httpEntity.getBody(), httpHeaders);
}

From source file:org.springframework.cloud.function.web.source.SupplierExporter.java

private void headers(HttpHeaders headers, String destination, Object value) {
    headers.putAll(this.requestBuilder.headers(destination, value));
}

From source file:org.springframework.hateoas.client.Traverson.java

private HttpEntity<?> prepareRequest(HttpHeaders headers) {

    HttpHeaders toSend = new HttpHeaders();
    toSend.putAll(headers);

    if (headers.getAccept().isEmpty()) {
        toSend.setAccept(mediaTypes);// w  w w  . j  av  a 2s  . c  om
    }

    return new HttpEntity<Void>(toSend);
}

From source file:org.springframework.web.socket.sockjs.client.AbstractXhrTransport.java

@Override
public ListenableFuture<WebSocketSession> connect(TransportRequest request, WebSocketHandler handler) {
    SettableListenableFuture<WebSocketSession> connectFuture = new SettableListenableFuture<>();
    XhrClientSockJsSession session = new XhrClientSockJsSession(request, handler, this, connectFuture);
    request.addTimeoutTask(session.getTimeoutTask());

    URI receiveUrl = request.getTransportUrl();
    if (logger.isDebugEnabled()) {
        logger.debug("Starting XHR " + (isXhrStreamingDisabled() ? "Polling" : "Streaming") + "session url="
                + receiveUrl);/* w w w .jav  a  2  s.  c o  m*/
    }

    HttpHeaders handshakeHeaders = new HttpHeaders();
    handshakeHeaders.putAll(request.getHandshakeHeaders());

    connectInternal(request, handler, receiveUrl, handshakeHeaders, session, connectFuture);
    return connectFuture;
}