當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。