本文整理汇总了Java中javax.ws.rs.container.ContainerResponseContext.getHeaders方法的典型用法代码示例。如果您正苦于以下问题:Java ContainerResponseContext.getHeaders方法的具体用法?Java ContainerResponseContext.getHeaders怎么用?Java ContainerResponseContext.getHeaders使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.ws.rs.container.ContainerResponseContext
的用法示例。
在下文中一共展示了ContainerResponseContext.getHeaders方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: filter
import javax.ws.rs.container.ContainerResponseContext; //导入方法依赖的package包/类
@Override
public void filter(
ContainerRequestContext containerRequestContext,
ContainerResponseContext containerResponseContext) throws IOException {
MultivaluedMap<String, Object> headers = containerResponseContext.getHeaders();
headers.add(
"Access-Control-Allow-Origin",
"*");
headers.add(
"Access-Control-Allow-Methods",
"GET, POST, OPTIONS");
headers.add(
"Access-Control-Allow-Headers",
"Cache-Control, X-Requested-With, Origin, Content-Type, Accept, Authorization");
}
示例2: filter
import javax.ws.rs.container.ContainerResponseContext; //导入方法依赖的package包/类
@Override
public void filter(ContainerRequestContext containerRequestContext,
ContainerResponseContext containerResponseContext) throws IOException {
MultivaluedMap<String, Object> headers = containerResponseContext.getHeaders();
headers.add(ACCESS_CONTROL_ALLOW_HEADERS, "orgin");
headers.add(ACCESS_CONTROL_ALLOW_HEADERS, "content-type");
headers.add(ACCESS_CONTROL_ALLOW_HEADERS, "accept");
headers.add(ACCESS_CONTROL_ALLOW_HEADERS, "authorization");
customHeaders.forEach(s -> headers.add(ACCESS_CONTROL_ALLOW_HEADERS, s));
// make sure there's only one header with this name
String headerString = (String) headers.get(ACCESS_CONTROL_ALLOW_HEADERS).stream()
.reduce((a, b) -> a.toString() + ", " + b.toString()).get();
headers.putSingle(ACCESS_CONTROL_ALLOW_HEADERS, headerString);
headers.putSingle("Access-Control-Allow-Credentials", "true");
headers.putSingle("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
}
示例3: filter
import javax.ws.rs.container.ContainerResponseContext; //导入方法依赖的package包/类
@Override
public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext)
throws IOException {
RequestLog.startTiming(this);
MultivaluedMap<String, Object> headers = responseContext.getHeaders();
String origin = requestContext.getHeaderString("origin");
if (origin == null || "".equals(origin)) {
headers.add("Access-Control-Allow-Origin", "*");
} else {
headers.add("Access-Control-Allow-Origin", origin);
}
String requestedHeaders = requestContext.getHeaderString("access-control-request-headers");
// allow all requested headers
headers.add("Access-Control-Allow-Headers", requestedHeaders == null ? "" : requestedHeaders);
headers.add("Access-Control-Allow-Methods", "GET, POST, DELETE, OPTIONS, PUT, PATCH");
headers.add("Access-Control-Allow-Credentials", "true");
RequestLog.stopTiming(this);
}
示例4: filter
import javax.ws.rs.container.ContainerResponseContext; //导入方法依赖的package包/类
@Override
public void filter(ContainerRequestContext requestContext,
ContainerResponseContext responseContext) throws IOException {
MultivaluedMap<String, Object> headers = responseContext.getHeaders();
//生成元が異なる場合frame要素やiframe要素の内部に表示しない
headers.add("X-Frame-Options", "SAMEORIGIN");
//Content-Typeの自動判別防止
headers.add("X-Content-Type-Options", "nosniff");
//XSSフィルターを有効化する
headers.add("X-XSS-Protection", "1; mode=block");
//リソースの取得元を生成元のみに制限する
//画像は生成元に加えてgravatarも許可する
headers.add("Content-Security-Policy",
"default-src 'self'; img-src 'self' www.gravatar.com");
}
示例5: filter
import javax.ws.rs.container.ContainerResponseContext; //导入方法依赖的package包/类
@Override
public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext)
throws IOException {
MultivaluedMap<String, Object> headers = responseContext.getHeaders();
// Allow from all origins...
if (!headers.containsKey("Access-Control-Allow-Origin")) {
headers.add("Access-Control-Allow-Origin", "*");
}
// Allow changing the following headers...
if (!headers.containsKey("Access-Control-Allow-Headers")) {
headers.add("Access-Control-Allow-Headers", "Content-Type, auth-id, auth-token");
}
// Allow credentials...
if (!headers.containsKey("Access-Control-Allow-Credentials")) {
headers.add("Access-Control-Allow-Credentials", "true");
}
// Allow methods...
if (!headers.containsKey("Access-Control-Allow-Methods")) {
headers.add("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS, HEAD");
}
// Max 14 days...
if (!headers.containsKey("Access-Control-Max-Age")) {
headers.add("Access-Control-Max-Age", "1209600");
}
}
示例6: filter
import javax.ws.rs.container.ContainerResponseContext; //导入方法依赖的package包/类
public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext)
throws IOException {
MultivaluedMap<String, Object> headers = responseContext.getHeaders();
headers.add("Access-Control-Allow-Origin", "*");
headers.add("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT");
headers.add("Access-Control-Allow-Headers", "X-Requested-With, Content-Type, X-Codingpedia");
}
示例7: filter
import javax.ws.rs.container.ContainerResponseContext; //导入方法依赖的package包/类
@Override
public void filter(ContainerRequestContext containerRequestContext, ContainerResponseContext containerResponseContext) throws IOException {
MultivaluedMap<String, Object> headers = containerResponseContext.getHeaders();
headers.add("Access-Control-Allow-Origin", containerRequestContext.getHeaders().getFirst("Origin"));
headers.add("Access-Control-Allow-Headers", "origin, content-type, accept, authorization");
headers.add("Access-Control-Allow-Credentials", "true");
headers.add("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS, HEAD");
}
示例8: filter
import javax.ws.rs.container.ContainerResponseContext; //导入方法依赖的package包/类
@Override
public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext)
throws IOException
{
MultivaluedMap<String, Object> headers = responseContext.getHeaders();
headers.add(ALLOW_ORIGIN, requestContext.getHeaderString(ORIGIN));
headers.add(ALLOW_METHODS, requestContext.getHeaderString(REQUEST_METHOD));
headers.add(ALLOW_HEADERS, requestContext.getHeaderString(REQUEST_HEADERS));
headers.add(ALLOW_CREDENTIALS, true);
}
示例9: filter
import javax.ws.rs.container.ContainerResponseContext; //导入方法依赖的package包/类
@Override
public void filter(ContainerRequestContext req, ContainerResponseContext res) throws IOException {
MultivaluedMap<String, Object> headers = res.getHeaders();
headers.add("Access-Control-Allow-Origin", "*");
headers.add("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT, OPTIONS, HEAD");
headers.add("Access-Control-Allow-Headers", "Content-Type"); // X-Requested-With を追加するべき?
}
示例10: filter
import javax.ws.rs.container.ContainerResponseContext; //导入方法依赖的package包/类
@Override
public void filter(
ContainerRequestContext containerRequestContext,
ContainerResponseContext containerResponseContext)
throws IOException {
Object entity = containerResponseContext.getEntity();
if (entity instanceof Try.Failure) {
Try.Failure failure = (Try.Failure)entity;
Exception exception = failure.getException();
Optional<APIError> optional = _exceptionConverterManager.convert(
exception);
APIError apiError = optional.orElseThrow(
() -> new MustHaveExceptionConverter(exception.getClass()));
if (_apioLogger != null) {
_apioLogger.error(apiError);
}
ErrorMessageMapper errorMessageMapper =
_errorMessageMapperManager.getErrorMessageMapper(
apiError, _httpHeaders);
String result = ErrorWriter.writeError(
errorMessageMapper, apiError, _httpHeaders);
MultivaluedMap<String, Object> headers =
containerResponseContext.getHeaders();
headers.remove("Content-Type");
headers.add("Content-Type", errorMessageMapper.getMediaType());
containerResponseContext.setEntity(result);
containerResponseContext.setStatus(apiError.getStatusCode());
}
}
示例11: filter
import javax.ws.rs.container.ContainerResponseContext; //导入方法依赖的package包/类
public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext)
throws IOException {
MultivaluedMap<String, Object> headers = responseContext.getHeaders();
headers.add("Access-Control-Allow-Origin", "*");
headers.add("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT, OPTIONS");
headers.add("Access-Control-Allow-Headers", "X-Requested-With, Content-Type");
}
示例12: filter
import javax.ws.rs.container.ContainerResponseContext; //导入方法依赖的package包/类
@Override
public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) throws IOException {
final MultivaluedMap<String, Object> headers = responseContext.getHeaders();
headers.add("Access-Control-Allow-Origin", "*");
headers.add("Access-Control-Allow-Headers", getRequestedAllowedHeaders(requestContext));
// do not set expose headers
//headers.add("Access-Control-Expose-Headers", getRequestedExposedHeaders(requestContext));
headers.add("Access-Control-Allow-Credentials", "true");
headers.add("Access-Control-Allow-Methods", ALLOWED_METHODS);
headers.add("Access-Control-Max-Age", MAX_AGE);
headers.add("x-responded-by", "cors-response-filter");
}
示例13: filter
import javax.ws.rs.container.ContainerResponseContext; //导入方法依赖的package包/类
@Override
public void filter(final ContainerRequestContext requestContext, final ContainerResponseContext cres)
throws IOException {
MultivaluedMap<String, Object> headers = cres.getHeaders();
headers.add("Access-Control-Allow-Origin", "*");
headers.add("Access-Control-Allow-Headers", "origin, content-converter, accept, authorization");
headers.add("Access-Control-Allow-Credentials", "true");
headers.add("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS, HEAD");
headers.add("Access-Control-Max-Age", "1209600");
}
示例14: filter
import javax.ws.rs.container.ContainerResponseContext; //导入方法依赖的package包/类
@Override
public void filter(final ContainerRequestContext requestContext, final ContainerResponseContext responseContext)
throws IOException {
final MultivaluedMap<String, Object> headers = responseContext.getHeaders();
headers.add("Access-Control-Allow-Origin", "*");
headers.add("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT, PATCH");
headers.add("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization");
}
示例15: filter
import javax.ws.rs.container.ContainerResponseContext; //导入方法依赖的package包/类
@Override
public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext)
throws IOException {
final MultivaluedMap<String, Object> headers = responseContext.getHeaders();
// if
// (requestContext.getHeaderString("Host").endsWith("pokebattler.com"))
// {
//
// if (requestContext.getHeaderString("Origin") == null) {
// headers.putSingle("Access-Control-Allow-Origin",
// (requestContext.getSecurityContext().isSecure()?"https":"http") +
// "://www.pokebattler.com");
// } else if
// (requestContext.getHeaderString("Origin").endsWith("pokebattler.com"))
// {
// headers.putSingle("Access-Control-Allow-Origin",
// requestContext.getHeaderString("Origin"));
// headers.putSingle("Access-Control-Allow-Origin", "*");
// }
// } else {
headers.putSingle("Access-Control-Allow-Origin", "*");
// }
// headers.add("Access-Control-Allow-Origin",
// "http://podcastpedia.org"); //allows CORS requests only coming from
// podcastpedia.org
headers.putSingle("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT");
headers.putSingle("Access-Control-Allow-Headers", "X-Requested-With");
headers.putSingle("Allow", "OPTIONS");
}