本文整理汇总了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);
}
}
示例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;
}
示例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);
}
示例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);
}
示例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());
}
}
示例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()));
}
}
示例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);
}
示例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);
}
示例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);
}
示例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());
}
示例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);
}
示例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()));
}
示例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);
}
示例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());
}
示例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);
}