本文整理汇总了Java中com.sun.jersey.spi.container.ContainerRequest.getRequestHeaders方法的典型用法代码示例。如果您正苦于以下问题:Java ContainerRequest.getRequestHeaders方法的具体用法?Java ContainerRequest.getRequestHeaders怎么用?Java ContainerRequest.getRequestHeaders使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.jersey.spi.container.ContainerRequest
的用法示例。
在下文中一共展示了ContainerRequest.getRequestHeaders方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkRequestHeader
import com.sun.jersey.spi.container.ContainerRequest; //导入方法依赖的package包/类
/**
* リクエストヘッダーの値をチェックする.
* 現在は、Acceptヘッダーのみ(US-ASCII文字以外かどうか)をチェックする
* @param request フィルター前リクエスト
*/
private void checkRequestHeader(ContainerRequest request) {
// ヘッダーのキー名に全角文字が含まれる場合は、その文字を含めたキー名となるため、実際にはこの指定は無視される。
// Jersey1.10では、Acceptヘッダーのキー名と値にUS-ASCII文字以外が含まれる場合に異常終了するため以下を対処
// (Acceptを含む他のヘッダーにも同様の処理が行われるが、上記理由により動作上は問題ないと判断)
// -キー名に含まれる場合は、その指定を無効(Accept:*/*)とする(Jerseryで組み込み済み)。
// -値に含まれる場合は、400エラーとする。
InBoundHeaders newHeaders = new InBoundHeaders();
MultivaluedMap<String, String> headers = request.getRequestHeaders();
for (String header : headers.keySet()) {
if (header.contains(org.apache.http.HttpHeaders.ACCEPT)
&& !acceptHeaderValueRegex.matcher(header).matches()) {
continue;
} else {
newHeaders.put(header, request.getRequestHeader(header));
}
}
request.setHeaders(newHeaders);
String acceptValue = request.getHeaderValue(org.apache.http.HttpHeaders.ACCEPT);
if (acceptValue != null && !acceptHeaderValueRegex.matcher(acceptValue).matches()) {
PersoniumCoreException exception = PersoniumCoreException.OData.BAD_REQUEST_HEADER_VALUE.params(
org.apache.http.HttpHeaders.ACCEPT, acceptValue);
throw exception;
}
}
示例2: filter
import com.sun.jersey.spi.container.ContainerRequest; //导入方法依赖的package包/类
@Override
public ContainerRequest filter(ContainerRequest request) {
MultivaluedMap<String, String> headers = request.getRequestHeaders();
if (headers.containsKey(HttpHeaders.ACCEPT_LANGUAGE)) {
List<String> acceptLanguageValues = headers.remove(HttpHeaders.ACCEPT_LANGUAGE);
for (int i = 0; i < acceptLanguageValues.size(); i++) {
final String acceptLanguageValue = acceptLanguageValues.get(i);
// replace es-419 (invalid) with es_ES (valid, hopefully good enough.)
if (acceptLanguageValue.contains(ES_419)) {
acceptLanguageValues.set(i, acceptLanguageValue.replace(ES_419, ES_ES));
}
}
headers.put(HttpHeaders.ACCEPT_LANGUAGE, acceptLanguageValues);
request.setHeaders((InBoundHeaders) headers);
}
return request;
}
示例3: adjustHeader
import com.sun.jersey.spi.container.ContainerRequest; //导入方法依赖的package包/类
private void adjustHeader(ContainerRequest request, String path, String suffix) {
String mime = SUFFIXES.get(suffix);
// change accept header
InBoundHeaders headers = (InBoundHeaders) request.getRequestHeaders();
headers.put(HttpHeaders.ACCEPT, Collections.singletonList(mime));
request.setHeaders(headers);
// remove suffix from the URL
String newPath = path.substring(0, path.length() - suffix.length());
URI requestUri = request.getRequestUri();
URI newURI = UriBuilder.fromUri(requestUri).replacePath(newPath).build();
request.setUris(request.getBaseUri(), newURI);
}
示例4: addRequestHeaders
import com.sun.jersey.spi.container.ContainerRequest; //导入方法依赖的package包/类
private void addRequestHeaders(ContainerRequest cReq) {
MultivaluedMap<String, String> headers = cReq.getRequestHeaders();
for (Entry<String, List<String>> e : headers.entrySet()) {
StaashRequestContext.addContext("H__" + e.getKey(), e.getValue().toString());
}
}
示例5: build
import com.sun.jersey.spi.container.ContainerRequest; //导入方法依赖的package包/类
public static CacheRequestContext build(ContainerRequest request, Set<String> vary, boolean includeBody) {
try {
MessageDigest digest = MessageDigest.getInstance("SHA-1");
for (String header : vary) {
List<String> headerValues = request.getRequestHeader(header);
if (headerValues != null && headerValues.size() > 0) {
digest.update(header.getBytes(Charsets.UTF_8));
digest.update((byte) 0xFD);
for (String value : headerValues) {
digest.update(value.getBytes(Charsets.UTF_8));
digest.update((byte) 0xFE);
}
digest.update((byte) 0xFF);
}
}
if (includeBody) {
byte[] requestBody = request.getEntity(byte[].class);
if (requestBody == null) {
requestBody = new byte[0];
}
if (requestBody.length > 0) {
digest.update("Body".getBytes(Charsets.UTF_8));
digest.update((byte) 0xFD);
digest.update(requestBody);
digest.update((byte) 0xFF);
}
request.setEntityInputStream(new ByteArrayInputStream(requestBody));
}
String hash = new String(Base64.encode(digest.digest()), Charsets.US_ASCII);
return new CacheRequestContext(request.getMethod(), request.getRequestUri(), request.getRequestHeaders(), hash);
} catch (NoSuchAlgorithmException ex) {
// This error should not occur since SHA-1 must be included with every java distribution
throw Throwables.propagate(ex);
}
}
示例6: filter
import com.sun.jersey.spi.container.ContainerRequest; //导入方法依赖的package包/类
@Override
public ContainerRequest filter(ContainerRequest request) {
LOG.debug(String.format("Authenticating request to %s", request.getRequestUri().toString()));
LOG.debug("headers: " + request.getRequestHeaders());
LOG.debug(request.getQueryParameters());
// validate the user
String accessKey = getAccessKey(request);
if (null == accessKey || accessKey.length() == 0) {
LOG.debug("Request received with no accesskey to " + request.getAbsolutePath());
request.getRequestHeaders().add(PI_USER_ID_KEY, ANONYMOUS_USER);
request.getRequestHeaders().add(PI_ACCESS_KEY_ID, ANONYMOUS_USER);
} else {
if (!userManager.userExists(accessKey)) {
LOG.debug("Rejecting request from inexistent access key " + accessKey);
throw new WebApplicationException(Status.UNAUTHORIZED);
}
User user = null;
for (AuthenticationHandler handler : authHandlers) {
if (handler.canHandle(request)) {
try {
user = handler.authenticate(request);
} catch (AuthenticationException e) {
LOG.debug("Authentication handler did not like request from user with access key " + accessKey, e);
throw new WebApplicationException(e, Status.UNAUTHORIZED);
}
}
}
if (null != user) {
request.getRequestHeaders().add(PI_USER_ID_KEY, user.getUsername());
request.getRequestHeaders().add(PI_ACCESS_KEY_ID, user.getApiAccessKey());
} else {
LOG.debug("Unable to handle request for " + request.getAbsolutePath() + " with headers: " + request.getRequestHeaders());
throw new WebApplicationException(Status.UNAUTHORIZED);
}
}
// massive hack to make various clients work - maybe factor out into another filter?
String contentType = request.getHeaderValue(HttpHeaders.CONTENT_TYPE);
LOG.debug(String.format("%s: %s", HttpHeaders.CONTENT_TYPE, contentType));
if ("".equals(contentType)) {
LOG.info(String.format("Setting content type for request without one..."));
MultivaluedMap<String, String> requestHeaders = request.getRequestHeaders();
requestHeaders.remove(HttpHeaders.CONTENT_TYPE);
requestHeaders.add(HttpHeaders.CONTENT_TYPE, ObjectMetaData.DEFAULT_OBJECT_CONTENT_TYPE);
}
return request;
}