当前位置: 首页>>代码示例>>Java>>正文


Java ContainerResponseContext类代码示例

本文整理汇总了Java中javax.ws.rs.container.ContainerResponseContext的典型用法代码示例。如果您正苦于以下问题:Java ContainerResponseContext类的具体用法?Java ContainerResponseContext怎么用?Java ContainerResponseContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ContainerResponseContext类属于javax.ws.rs.container包,在下文中一共展示了ContainerResponseContext类的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 requestContext, ContainerResponseContext responseContext)
        throws IOException {
    String origin = requestContext.getHeaderString(ORIGIN);
    if (origin == null || requestContext.getMethod().equalsIgnoreCase("OPTIONS")
            || requestContext.getProperty("cors.failure") != null) {
        // don't do anything if origin is null, its an OPTIONS request, or cors.failure is set
        return;
    }
    responseContext.getHeaders().putSingle(ACCESS_CONTROL_ALLOW_ORIGIN, origin);
    if (allowCredentials)
        responseContext.getHeaders().putSingle(ACCESS_CONTROL_ALLOW_CREDENTIALS, "true");

    if (exposedHeaders != null) {
        responseContext.getHeaders().putSingle(ACCESS_CONTROL_EXPOSE_HEADERS, exposedHeaders);
    }
}
 
开发者ID:fabric8-launcher,项目名称:launcher-backend,代码行数:18,代码来源:CorsFilter.java

示例3: filter

import javax.ws.rs.container.ContainerResponseContext; //导入依赖的package包/类
@Override
public void filter(final ContainerRequestContext req, final ContainerResponseContext res) throws IOException {
    if (READ_METHODS.contains(req.getMethod())) {

        if (res.getLinks().stream().filter(l -> l.getRel().equals(TYPE)).map(Link::getUri).map(URI::toString)
            .anyMatch(uri -> uri.equals(Container.getIRIString()) || uri.equals(NonRDFSource.getIRIString()))) {

            final String urlBase = nonNull(baseUrl) ? baseUrl : req.getUriInfo().getBaseUri().toString();
            final String identifier = urlBase + req.getUriInfo().getPath();

            res.getHeaders().add("Link", fromUri(identifier + "?ext=" + UPLOADS)
                        .rel(multipartUploadService.getIRIString()).build());
        }

        final List<String> exts = req.getUriInfo().getQueryParameters().getOrDefault("ext", emptyList());
        if (exts.contains(UPLOADS)) {
            res.getHeaders().putSingle(ALLOW, join(",", POST, OPTIONS));
        }
    }
}
 
开发者ID:trellis-ldp,项目名称:trellis,代码行数:21,代码来源:MultipartUploader.java

示例4: filter

import javax.ws.rs.container.ContainerResponseContext; //导入依赖的package包/类
@Override
public void filter(ContainerRequestContext reqCtx, ContainerResponseContext respCtx) throws IOException {
    final UriInfo uriInfo = reqCtx.getUriInfo();
    final MultivaluedMap<String, String> queryParameters = uriInfo.getQueryParameters();
    if (queryParameters.containsKey("pretty")) {
        ObjectWriterInjector.set(new IndentingModifier());
    }
}
 
开发者ID:stevespringett,项目名称:Alpine,代码行数:9,代码来源:PrettyPrintFilter.java

示例5: filter

import javax.ws.rs.container.ContainerResponseContext; //导入依赖的package包/类
@Override
public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) throws IOException {
    if (!shouldFilter(requestContext, resourceInfo)) {
        // do nothing if the filter doesn't apply
        return;
    }

    try {
        Span span = (Span) requestContext.getProperty(SERVER_SPAN_CONTEXT_KEY);
        if (span != null) {
            span.setTag(Tags.HTTP_STATUS.getKey(), responseContext.getStatus());
            span.finish();
        }
    } catch (Exception e) {
        LOGGER.error("Server Response Filter failed", e);
    }
}
 
开发者ID:ExpediaDotCom,项目名称:haystack-client-java,代码行数:18,代码来源:ServerFilter.java

示例6: filter

import javax.ws.rs.container.ContainerResponseContext; //导入依赖的package包/类
@Override
public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) throws IOException {
    System.out.println("Response = " + requestContext + " " + responseContext);
    Long start = concurrentRequests.get(requestContext);
    concurrentRequests.remove(requestContext);
    long duration = (System.nanoTime() - start);
    System.out.println("Duration: " + duration);
    UriInfo uriInfo = requestContext.getUriInfo();

    String ipv4 = extractIpAddress(uriInfo);
    System.out.println("ipv4 = " + ipv4);
    String serviceName = extractServiceName(uriInfo);
    System.out.println("serviceName = " + serviceName);
    String spanName = extractSpanName(uriInfo);
    System.out.println("spanName = " + spanName);
    Optional<String> traceId = extractTraceId(requestContext);
    String spanId = traceId.map(id -> this.tracee.saveChildSpan(id, spanName, serviceName, ipv4, 0)).
            orElseGet(() -> this.tracee.saveParentSpan(spanName, serviceName, ipv4, duration));
    System.out.println("Storing span id: " + spanId);
    storeSpandId(responseContext, spanId);
}
 
开发者ID:AdamBien,项目名称:SpanEE,代码行数:22,代码来源:SpanEEContainerRequestFilter.java

示例7: allowCors

import javax.ws.rs.container.ContainerResponseContext; //导入依赖的package包/类
/**
 * Adds the HTTP head "Access-Control-Allow-Origin: *" to enable
 * all cross domain requests.
 */
private static void allowCors(final ContainerRequestContext request, final ContainerResponseContext response)  {
    final String origin = request.getHeaderString("Origin");
    if (origin == null) {
        return;
    }

    response.getHeaders().add("Access-Control-Allow-Origin", "*");
    response.getHeaders().add("Access-Control-Allow-Credentials", "true");
    response.getHeaders().add("Access-Control-Allow-Methods", "GET, HEAD, OPTIONS, PATCH, POST, PUT, DELETE");

    final String headers = request.getHeaderString("Access-Control-Request-Headers");
    if (headers != null) {
        response.getHeaders().add("Access-Control-Allow-Headers", UrlUtils.urlDecode(headers));
    }
}
 
开发者ID:minijax,项目名称:minijax,代码行数:20,代码来源:MinijaxCorsFilter.java

示例8: filter404SingleParameter

import javax.ws.rs.container.ContainerResponseContext; //导入依赖的package包/类
@SuppressWarnings("rawtypes")
@Test
public void filter404SingleParameter() {
	final ContainerRequestContext requestContext = Mockito.mock(ContainerRequestContext.class);
	final ContainerResponseContext responseContext = Mockito.mock(ContainerResponseContext.class);
	Mockito.when(responseContext.getStatus()).thenReturn(204);
	final Annotation anno1 = Mockito.mock(Annotation.class);
	final Annotation anno2 = Mockito.mock(Annotation.class);
	final Annotation[] annotations = new Annotation[] { anno1, anno2 };
	Mockito.when((Class) anno2.annotationType()).thenReturn(OnNullReturn404.class);
	Mockito.when(responseContext.getEntityAnnotations()).thenReturn(annotations);

	final UriInfo uriInfo = Mockito.mock(UriInfo.class);
	final MultivaluedMap<String, String> parameters = new MultivaluedHashMap<>();
	parameters.putSingle("id", "2000");

	Mockito.when(uriInfo.getPathParameters()).thenReturn(parameters);
	Mockito.when(requestContext.getUriInfo()).thenReturn(uriInfo);
	filter.filter(requestContext, responseContext);
	Mockito.verify(responseContext, VerificationModeFactory.atLeastOnce()).setStatus(404);
	Mockito.verify(responseContext, VerificationModeFactory.atLeastOnce()).setEntity(
			"{\"code\":\"entity\",\"message\":\"2000\",\"parameters\":null,\"cause\":null}", annotations, MediaType.APPLICATION_JSON_TYPE);
}
 
开发者ID:ligoj,项目名称:bootstrap,代码行数:24,代码来源:NotFoundResponseFilterTest.java

示例9: filter404NoParameter

import javax.ws.rs.container.ContainerResponseContext; //导入依赖的package包/类
@SuppressWarnings("rawtypes")
@Test
public void filter404NoParameter() {
	final ContainerRequestContext requestContext = Mockito.mock(ContainerRequestContext.class);
	final ContainerResponseContext responseContext = Mockito.mock(ContainerResponseContext.class);
	Mockito.when(responseContext.getStatus()).thenReturn(204);
	final Annotation anno1 = Mockito.mock(Annotation.class);
	final Annotation anno2 = Mockito.mock(Annotation.class);
	final Annotation[] annotations = new Annotation[] { anno1, anno2 };
	Mockito.when((Class) anno2.annotationType()).thenReturn(OnNullReturn404.class);
	Mockito.when(responseContext.getEntityAnnotations()).thenReturn(annotations);

	final UriInfo uriInfo = Mockito.mock(UriInfo.class);
	final MultivaluedMap<String, String> parameters = new MultivaluedHashMap<>();

	Mockito.when(uriInfo.getPathParameters()).thenReturn(parameters);
	Mockito.when(requestContext.getUriInfo()).thenReturn(uriInfo);
	filter.filter(requestContext, responseContext);
	Mockito.verify(responseContext, VerificationModeFactory.atLeastOnce()).setStatus(404);
	Mockito.verify(responseContext, VerificationModeFactory.atLeastOnce())
			.setEntity("{\"code\":\"data\",\"message\":null,\"parameters\":null,\"cause\":null}", annotations, MediaType.APPLICATION_JSON_TYPE);
}
 
开发者ID:ligoj,项目名称:bootstrap,代码行数:23,代码来源:NotFoundResponseFilterTest.java

示例10: 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

示例11: filter

import javax.ws.rs.container.ContainerResponseContext; //导入依赖的package包/类
@Override
    public void filter(ContainerRequestContext request, ContainerResponseContext response) {
        String path = request.getUriInfo().getRequestUri().getPath();
        LOG.fine(String.format("Received request : crossdomain for %s", path));

        // TODO : disable for production
        // *** ONLY FOR DEMO ***
//        response.getHeaders().add("Access-Control-Allow-Origin", "http://localhost:3002");
        response.getHeaders().add("Access-Control-Allow-Origin", "*");
        response.getHeaders().add("Access-Control-Allow-Headers", "Content-Range, Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");
        response.getHeaders().add("Access-Control-Expose-Headers", "Content-Range, Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");
//        response.getHeaders().add("Access-Control-Allow-Credentials", "http://localhost:3002");
        response.getHeaders().add("Access-Control-Allow-Credentials", "*");
        response.getHeaders().add("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS, HEAD, PATCH");
        response.getHeaders().add("Access-Control-Max-Age", "*");
    }
 
开发者ID:javathought,项目名称:devoxx-2017,代码行数:17,代码来源:CrossDomainFilter.java

示例12: filter

import javax.ws.rs.container.ContainerResponseContext; //导入依赖的package包/类
@Override
public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) throws IOException {

    final EntityTag entityTag = getEntityTag(responseContext);
    final Date lastModified = getLastModified(responseContext);

    responseContext.getHeaders().putSingle(HttpHeaders.CACHE_CONTROL, cacheControl);
    writeHeader(responseContext, HttpHeaders.ETAG, entityTag);
    writeHeader(responseContext, HttpHeaders.LAST_MODIFIED, lastModified == null ? null : HttpUtils.getHttpDateFormat().format(lastModified));

    final Response.ResponseBuilder builder = evaluatePreconditions(requestContext, entityTag, lastModified);
    if (builder != null) {
        responseContext.setStatusInfo(Response.Status.NO_CONTENT);
        responseContext.setEntity(null);
    }
}
 
开发者ID:Microbule,项目名称:microbule,代码行数:17,代码来源:ContainerCacheFilter.java

示例13: controllerRedirectEvent

import javax.ws.rs.container.ContainerResponseContext; //导入依赖的package包/类
/**
 * Upon detecting a redirect, either add cookie to response or re-write URL of new
 * location to co-relate next request.
 *
 * @param event the event.
 */
public void controllerRedirectEvent(@Observes ControllerRedirectEvent event) {
    if (request.getAttribute(SCOPE_ID) != null) {
        if (usingCookies()) {
            Cookie cookie = new Cookie(COOKIE_NAME, request.getAttribute(SCOPE_ID).toString());
            cookie.setPath(mvc.getContextPath());
            cookie.setMaxAge(600);
            cookie.setHttpOnly(true);
            response.addCookie(cookie);
        } else {
            final ContainerResponseContext crc = ((ControllerRedirectEventImpl) event).getContainerResponseContext();
            final UriBuilder builder = UriBuilder.fromUri(crc.getStringHeaders().getFirst(HttpHeaders.LOCATION));
            builder.queryParam(SCOPE_ID, request.getAttribute(SCOPE_ID).toString());
            crc.getHeaders().putSingle(HttpHeaders.LOCATION, builder.build());
        }
    }
}
 
开发者ID:mvc-spec,项目名称:ozark,代码行数:23,代码来源:RedirectScopeManager.java

示例14: 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

示例15: filter

import javax.ws.rs.container.ContainerResponseContext; //导入依赖的package包/类
@Override
public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext)
         throws IOException
{
   String origin = requestContext.getHeaderString(ORIGIN);
   if (origin == null || requestContext.getMethod().equalsIgnoreCase("OPTIONS")
            || requestContext.getProperty("cors.failure") != null)
   {
      // don't do anything if origin is null, its an OPTIONS request, or cors.failure is set
      return;
   }
   responseContext.getHeaders().putSingle(ACCESS_CONTROL_ALLOW_ORIGIN, origin);
   if (allowCredentials)
      responseContext.getHeaders().putSingle(ACCESS_CONTROL_ALLOW_CREDENTIALS, "true");

   if (exposedHeaders != null)
   {
      responseContext.getHeaders().putSingle(ACCESS_CONTROL_EXPOSE_HEADERS, exposedHeaders);
   }
}
 
开发者ID:fabric8-launcher,项目名称:launchpad-backend,代码行数:21,代码来源:CorsFilter.java


注:本文中的javax.ws.rs.container.ContainerResponseContext类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。