本文整理汇总了Java中com.sun.jersey.spi.container.ContainerRequest.setHeaders方法的典型用法代码示例。如果您正苦于以下问题:Java ContainerRequest.setHeaders方法的具体用法?Java ContainerRequest.setHeaders怎么用?Java ContainerRequest.setHeaders使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.jersey.spi.container.ContainerRequest
的用法示例。
在下文中一共展示了ContainerRequest.setHeaders方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: mutateURI
import com.sun.jersey.spi.container.ContainerRequest; //导入方法依赖的package包/类
/**
* Mutates the URI based on who the user is (provided in Authentication object) and what they're
* requesting (provided in Container Request object).
*
* @param auth
* OAuth2Authentication object (contains principal for user).
* @param request
* Container Request (contains path and query parameters).
*/
public void mutateURI(Authentication auth, ContainerRequest request) {
/*
* Don't mutate POSTs.
*/
if (request.getMethod().equals(POST)) {
return;
}
SLIPrincipal user = (SLIPrincipal) auth.getPrincipal();
String clientId = ((OAuth2Authentication) auth).getClientAuthentication().getClientId();
List<PathSegment> segments = sanitizePathSegments(request);
String parameters = request.getRequestUri().getQuery();
if (segments.size() == 0) {
throw new NotFoundException();
}
if (usingVersionedApi(segments)) {
if (!request.getProperties().containsKey(REQUESTED_PATH)) {
request.getProperties().put(REQUESTED_PATH, request.getPath());
}
MutatedContainer mutated = uriMutator.mutate(segments, parameters, user, clientId);
if (mutated != null && mutated.isModified()) {
String version = getResourceVersion(segments, mutated);
if (mutated.getHeaders() != null) {
InBoundHeaders headers = new InBoundHeaders();
headers.putAll(request.getRequestHeaders());
for (String key : mutated.getHeaders().keySet()) {
headers.putSingle(key, mutated.getHeaders().get(key));
}
request.setHeaders(headers);
}
if (mutated.getPath() != null) {
if (mutated.getQueryParameters() != null && !mutated.getQueryParameters().isEmpty()) {
LOG.info("URI Rewrite: {}?{} --> {}?{}", new Object[] { request.getPath(), parameters, mutated.getPath(),
mutated.getQueryParameters() });
request.setUris(request.getBaseUri(),
request.getBaseUriBuilder().path(version).path(mutated.getPath())
.replaceQuery(mutated.getQueryParameters()).build());
} else {
LOG.info("URI Rewrite: {} --> {}", new Object[] { request.getPath(), mutated.getPath() });
request.setUris(request.getBaseUri(),
request.getBaseUriBuilder().path(version).path(mutated.getPath()).build());
}
}
}
}
}