當前位置: 首頁>>代碼示例>>Java>>正文


Java ClientRequestContext.getHeaders方法代碼示例

本文整理匯總了Java中javax.ws.rs.client.ClientRequestContext.getHeaders方法的典型用法代碼示例。如果您正苦於以下問題:Java ClientRequestContext.getHeaders方法的具體用法?Java ClientRequestContext.getHeaders怎麽用?Java ClientRequestContext.getHeaders使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.ws.rs.client.ClientRequestContext的用法示例。


在下文中一共展示了ClientRequestContext.getHeaders方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: filter

import javax.ws.rs.client.ClientRequestContext; //導入方法依賴的package包/類
@Override
public void filter(ClientRequestContext clientRequestContext) throws IOException {
    String method = clientRequestContext.getMethod();
    URI uri = clientRequestContext.getUri();
    MultivaluedMap<String, Object> headers = clientRequestContext.getHeaders();
    System.out.printf("Sending %s to: %s\n", method, uri);
    System.out.printf("Headers:\n");
    for(String key : headers.keySet()) {
        System.out.printf("  %s: %s\n", key, headers.getFirst(key));
    }
    if(clientRequestContext.hasEntity()) {
        final OutputStream stream = new LoggingStream(clientRequestContext.getEntityStream());
        clientRequestContext.setEntityStream(stream);
        clientRequestContext.setProperty("client.LoggingStream", stream);
    }
}
 
開發者ID:obsidian-toaster-quickstarts,項目名稱:redhat-sso,代碼行數:17,代碼來源:LoggingFilter.java

示例2: withCredentials

import javax.ws.rs.client.ClientRequestContext; //導入方法依賴的package包/類
public WordPressClientFactory withCredentials(String username, String password) {
    this.clientRequestFilter = new ClientRequestFilter() {
        private final String charset = StandardCharsets.UTF_8.name();

        @Override
        public void filter(ClientRequestContext requestContext) throws IOException {

            String token = String.format("%s:%s", username, password);

            String basicAuthHeader = null;

            try {
                basicAuthHeader = "BASIC " + DatatypeConverter.printBase64Binary(token.getBytes(charset));
            }
            catch (UnsupportedEncodingException ex) {
                throw new IllegalStateException("Cannot encode with " + charset, ex);
            }

            MultivaluedMap<String, Object> headers = requestContext.getHeaders();
            headers.add("Authorization", basicAuthHeader);

            logger.trace("Added BasicAuth filter with username {}", username);
        }
    };
    return this;
}
 
開發者ID:washingtonpost,項目名稱:wordpress-rest-api-java-client,代碼行數:27,代碼來源:WordPressClientFactory.java

示例3: filter

import javax.ws.rs.client.ClientRequestContext; //導入方法依賴的package包/類
@Override
public void filter( ClientRequestContext context ) throws IOException {

    if (debugLevel == RESTDebugLevel.NONE || debugLevel == RESTDebugLevel.TARGET_URI) {
        return;
    }

    MultivaluedMap<String, Object> reqHeaders = context.getHeaders();
    StringBuilder requestMessage = new StringBuilder();
    requestMessage.append("Sending the following request: \n");
    if ( (debugLevel & RESTDebugLevel.HEADERS) == RESTDebugLevel.HEADERS) {
        requestMessage.append(context.getMethod() + " " + context.getUri() + " \n");

        for (Entry<String, List<Object>> reqHeaderEntry : reqHeaders.entrySet()) {
            requestMessage.append(reqHeaderEntry.getKey() + ": "
                                  + Arrays.toString(reqHeaderEntry.getValue().toArray()) + " \n");
        }
    }
    if ( (debugLevel & RESTDebugLevel.BODY) == RESTDebugLevel.BODY && context.hasEntity()) {
        //log request body
        Object entity = context.getEntity();
        if (entity instanceof Form) {
            requestMessage.append("Body: " + ((Form) entity).asMap());
        } else {
            requestMessage.append("Body: " + entity.toString());
        }
    }
    log.info(requestMessage);
}
 
開發者ID:Axway,項目名稱:ats-framework,代碼行數:30,代碼來源:RestClient.java

示例4: filter

import javax.ws.rs.client.ClientRequestContext; //導入方法依賴的package包/類
@Override
public void filter(ClientRequestContext requestContext) throws IOException {
    MultivaluedMap<String, Object> headers = requestContext.getHeaders();
    final String basicAuthentication = getBasicAuthentication();
    headers.add("Authorization", basicAuthentication);

}
 
開發者ID:jmd-stuff,項目名稱:task-app,代碼行數:8,代碼來源:TaskAppClient.java

示例5: filter

import javax.ws.rs.client.ClientRequestContext; //導入方法依賴的package包/類
@Override
public void filter(ClientRequestContext requestContext) throws IOException {
  MultivaluedMap headers = requestContext.getHeaders();
  for (Map.Entry<String, String> entry : headersToAdd.entrySet()) {
    headers.putSingle(entry.getKey(), entry.getValue());
  }
}
 
開發者ID:SK-EID,項目名稱:smart-id-java-client,代碼行數:8,代碼來源:ClientRequestHeaderFilter.java

示例6: filter

import javax.ws.rs.client.ClientRequestContext; //導入方法依賴的package包/類
@Override
public void filter(ClientRequestContext requestContext) throws IOException
{
    CorrelationId correlationId = CorrelationIdUtil.getId();
    if(correlationId != null){
        MultivaluedMap<String, Object> headers = requestContext.getHeaders();
        headers.put(CorrelationIdFilter.CORRELATION_ID_HEADER, Arrays.asList(correlationId.getId()));
        headers.put(CorrelationIdFilter.CORRELATION_ID_SOURCE_HEADER, Arrays.asList(correlationId.getSource()));
        headers.put(CorrelationIdFilter.CORRELATION_ID_TIME_HEADER, Arrays.asList(correlationId.getCreationTime()));
    }
}
 
開發者ID:jesty,項目名稱:orientdb-microservices,代碼行數:12,代碼來源:CorrelationIdClientRequestFilter.java

示例7: filter

import javax.ws.rs.client.ClientRequestContext; //導入方法依賴的package包/類
@Override
public void filter(ClientRequestContext requestContext) throws IOException {
    final MultivaluedMap<String, Object> headers = requestContext.getHeaders();
    final String basicAuthentication = getBasicAuthentication();
    headers.add("Authorization", basicAuthentication);

}
 
開發者ID:projectomakase,項目名稱:omakase,代碼行數:8,代碼來源:OmakaseClient.java

示例8: filter

import javax.ws.rs.client.ClientRequestContext; //導入方法依賴的package包/類
/**
 * Adds date and authorization headers to the request.
 *
 * @param requestContext request context.
 * @throws IOException if an I/O exception occurs.
 */
@Override
public void filter(final ClientRequestContext requestContext) throws IOException {
    final MultivaluedMap<String, Object> headers = requestContext.getHeaders();
    final ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
    final String dateHeaderValue = DateTimeFormatter.RFC_1123_DATE_TIME.format(now);
    headers.add(DATE_HEADER_NAME, dateHeaderValue);
    final String authHeaderValue = signer.get().createAuthorizationHeader(
            loginName,
            keyPair,
            now
    );
    headers.add(AUTHORIZATION_HEADER_NAME, authHeaderValue);
}
 
開發者ID:joyent,項目名稱:java-http-signature,代碼行數:20,代碼來源:SignedRequestClientRequestFilter.java

示例9: filter

import javax.ws.rs.client.ClientRequestContext; //導入方法依賴的package包/類
@Override
public void filter(ClientRequestContext clientRequestContext) throws IOException {
    MultivaluedMap<String, Object> headers = clientRequestContext.getHeaders();
    if (credentials.getUsername() == null && credentials.getPassword() == null) {
        return;
    }
    final String basicAuthentication = getBasicAuthentication();
    headers.add("Authorization", basicAuthentication);

}
 
開發者ID:Jaspersoft,項目名稱:jrs-rest-java-client,代碼行數:11,代碼來源:BasicAuthenticationFilter.java

示例10: filter

import javax.ws.rs.client.ClientRequestContext; //導入方法依賴的package包/類
@Override
public void filter(ClientRequestContext requestContext, ClientResponseContext responseContext) throws IOException
{
    if (requestContext == null || responseContext == null || responseContext.getStatus() != Response.Status.FOUND.getStatusCode()) {
       return;
    }

    log.debug("Processing redirect for " + requestContext.getMethod() + " " + requestContext.getUri().toASCIIString() + " to " + responseContext.getLocation().toASCIIString());

    Client inClient = requestContext.getClient();
    Object entity = requestContext.getEntity();
    MultivaluedMap<String, Object> headers = requestContext.getHeaders();
    String method = requestContext.getMethod();
    Response resp;
    if ("POST".equalsIgnoreCase(method) || "PUT".equalsIgnoreCase(method)) {
        resp = inClient.target(responseContext.getLocation())
                .request(requestContext.getMediaType())
                .headers(headers)
                .method(requestContext.getMethod(), Entity.entity(new GenericEntity<JAXBElement<?>>((JAXBElement<?>)entity) {}, NsiConstants.NSI_DDS_V1_XML));
    }
    else {
        resp = inClient.target(responseContext.getLocation())
                .request(requestContext.getMediaType())
                .headers(headers)
                .method(requestContext.getMethod());
    }

    responseContext.setEntityStream((InputStream) resp.getEntity());
    responseContext.setStatusInfo(resp.getStatusInfo());
    responseContext.setStatus(resp.getStatus());
    responseContext.getHeaders().putAll(resp.getStringHeaders());

    log.debug("Processing redirect with result " + resp.getStatus());
}
 
開發者ID:BandwidthOnDemand,項目名稱:nsi-dds,代碼行數:35,代碼來源:RestClient.java

示例11: storeSpandId

import javax.ws.rs.client.ClientRequestContext; //導入方法依賴的package包/類
void storeSpandId(ClientRequestContext responseContext, String id) {
    System.out.println("Storing id: " + id);
    MultivaluedMap<String, Object> headers = responseContext.getHeaders();
    headers.putSingle(TRACEE_HEADER, id);
}
 
開發者ID:AdamBien,項目名稱:SpanEE,代碼行數:6,代碼來源:SpanEEClientRequestFilter.java

示例12: filter

import javax.ws.rs.client.ClientRequestContext; //導入方法依賴的package包/類
@Override
public void filter(ClientRequestContext requestContext) throws IOException {
    MultivaluedMap<String, Object> requestHeaders = requestContext.getHeaders();
    this.headersToSet.entrySet().forEach(entry -> requestHeaders.putSingle(entry.getKey(), entry.getValue()));
}
 
開發者ID:code-obos,項目名稱:servicebuilder,代碼行數:6,代碼來源:WebTargetRequestHeaderFilter.java

示例13: filter

import javax.ws.rs.client.ClientRequestContext; //導入方法依賴的package包/類
public void filter(ClientRequestContext requestContext) throws IOException {
	MultivaluedMap<String, Object> headers = requestContext.getHeaders();
	headers.add("Authorization", basicAuth);
}
 
開發者ID:bootique,項目名稱:bootique-jersey-client,代碼行數:5,代碼來源:BasicAuthenticatorFactory.java

示例14: filter

import javax.ws.rs.client.ClientRequestContext; //導入方法依賴的package包/類
public void filter(ClientRequestContext requestContext) throws IOException {
    MultivaluedMap<String, Object> headers = requestContext.getHeaders();
    headers.add("Authorization", getAuthorization());
}
 
開發者ID:bootique,項目名稱:bootique-jersey-client,代碼行數:5,代碼來源:OAuth2TokenAuthenticator.java

示例15: filter

import javax.ws.rs.client.ClientRequestContext; //導入方法依賴的package包/類
@Override
public void filter(ClientRequestContext requestContext) throws IOException {
	MultivaluedMap<String, Object> headers = requestContext.getHeaders();
	headers.putSingle(HttpHeaders.AUTHORIZATION, authHeader);
}
 
開發者ID:Mercateo,項目名稱:rest-hateoas-client,代碼行數:6,代碼來源:AuthHeaderFilter.java


注:本文中的javax.ws.rs.client.ClientRequestContext.getHeaders方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。