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


Java ContainerResponseContext.getHeaders方法代碼示例

本文整理匯總了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");
   }
 
開發者ID:Lambda-3,項目名稱:Graphene,代碼行數:18,代碼來源:CORSFilter.java

示例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");
}
 
開發者ID:Mercateo,項目名稱:rest-jersey-utils,代碼行數:21,代碼來源:SimpleAccessControlAllowHeaderFilter.java

示例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);
}
 
開發者ID:yahoo,項目名稱:fili,代碼行數:22,代碼來源:ResponseCorsFilter.java

示例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");
}
 
開發者ID:backpaper0,項目名稱:sealion,代碼行數:21,代碼來源:SecurityResponseHeaders.java

示例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");
}
   }
 
開發者ID:PureSolTechnologies,項目名稱:Purifinity,代碼行數:26,代碼來源:CORSFilter.java

示例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");
}
 
開發者ID:jiumao-org,項目名稱:wechat-mall,代碼行數:10,代碼來源:CORSResponseFilter.java

示例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");
}
 
開發者ID:Juraji,項目名稱:Biliomi,代碼行數:10,代碼來源:InCORSFilter.java

示例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);
}
 
開發者ID:code-obos,項目名稱:servicebuilder,代碼行數:11,代碼來源:ResponseCorsFilter.java

示例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 を追加するべき?
}
 
開發者ID:openNaEF,項目名稱:openNaEF,代碼行數:8,代碼來源:CORSResponseFilter.java

示例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());
	}
}
 
開發者ID:liferay,項目名稱:com-liferay-apio-architect,代碼行數:41,代碼來源:FailureFilter.java

示例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");
}
 
開發者ID:groovylabs,項目名稱:lyre,代碼行數:10,代碼來源:CORSFilter.java

示例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");
}
 
開發者ID:hantsy,項目名稱:javaee8-jaxrs-sample,代碼行數:13,代碼來源:CorsResponseFilter.java

示例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");
}
 
開發者ID:pwalser75,項目名稱:jee-demo,代碼行數:12,代碼來源:CORSFilter.java

示例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");
}
 
開發者ID:ExplorViz,項目名稱:explorviz-backend,代碼行數:11,代碼來源:CORSResponseFilter.java

示例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");
}
 
開發者ID:celandro,項目名稱:pokebattler-fight,代碼行數:32,代碼來源:CORSResponseFilter.java


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