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


Java ContainerResponse类代码示例

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


ContainerResponse类属于com.sun.jersey.spi.container包,在下文中一共展示了ContainerResponse类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: addResponseHeaders

import com.sun.jersey.spi.container.ContainerResponse; //导入依赖的package包/类
/**
 * 全てのレスポンスに共通するレスポンスヘッダーを追加する.
 * Access-Control-Allow-Origin, Access-Control-Allow-Headers<br/>
 * X-Personium-Version<br/>
 * @param request
 * @param response
 */
private void addResponseHeaders(final ContainerRequest request, final ContainerResponse response) {
    MultivaluedMap<String, Object> mm = response.getHttpHeaders();
    String acrh = request.getHeaderValue(HttpHeaders.ACCESS_CONTROL_REQUEST_HEADERS);
    if (acrh != null) {
        mm.putSingle(HttpHeaders.ACCESS_CONTROL_ALLOW_HEADERS, acrh);
    } else {
        mm.remove(HttpHeaders.ACCESS_CONTROL_ALLOW_HEADERS);
    }
    mm.putSingle(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN, HttpHeaders.Value.ASTERISK);
    // X-Personium-Version
    mm.putSingle(HttpHeaders.X_PERSONIUM_VERSION, PersoniumUnitConfig.getCoreVersion());
}
 
开发者ID:personium,项目名称:personium-core,代码行数:20,代码来源:PersoniumCoreContainerFilter.java

示例2: testFilterContainerRequestContainerResponse

import com.sun.jersey.spi.container.ContainerResponse; //导入依赖的package包/类
/**
 * filter(ContainerRequest req, ContainerResponse res): ContainerResponseのテスト.
 * レスポンスフィルタとしてログ出力をしていることを確認。
 */
@Ignore
@Test
public void testFilterContainerRequestContainerResponse() {
    // 被テストオブジェクトを準備
    PersoniumCoreContainerFilter containerFilter = new PersoniumCoreContainerFilter();
    // ContainerRequiestモックを準備
    ContainerRequest mockRequest = mock(ContainerRequest.class);
    HttpServletRequest mockServletRequest = mock(HttpServletRequest.class);
    when(mockServletRequest.getAttribute("requestTime")).thenReturn(System.currentTimeMillis());
    containerFilter.setHttpServletRequest(mockServletRequest);

    // ContainerResponseモックを準備
    ContainerResponse mockResponse = mock(ContainerResponse.class);
    when(mockResponse.getStatus()).thenReturn(HttpStatus.SC_OK);

    // 被テスト処理の実行
    ContainerResponse filteredResponse = containerFilter.filter(mockRequest, mockResponse);

    // 結果の検証。
    // ログ出力するだけなので、非Nullであることのみ検査.
    assertNotNull(filteredResponse);
}
 
开发者ID:personium,项目名称:personium-core,代码行数:27,代码来源:PersoniumCoreContainerFilterTest.java

示例3: filter

import com.sun.jersey.spi.container.ContainerResponse; //导入依赖的package包/类
@Override
public ContainerResponse filter(ContainerRequest request, ContainerResponse response) {
    if (response.getStatusType().getFamily() == Response.Status.Family.SERVER_ERROR) {
        switch (response.getStatus()) {
            case 500:
                _meter500.mark();
                break;
            case 503:
                _meter503.mark();
                break;
            default:
                _meterOther.mark();
                break;
        }
    }
    return response;
}
 
开发者ID:bazaarvoice,项目名称:emodb,代码行数:18,代码来源:ServerErrorResponseMetricsFilter.java

示例4: filter

import com.sun.jersey.spi.container.ContainerResponse; //导入依赖的package包/类
/**
 * Extracts the client ID from the query parameter named {@link LongPollingServlet#CLIENT_ID} and subscribes
 * for updates when the data changes in any of the masters in {@link #_masterTypes}.
 * @param request The request
 * @param response The response
 * @return The unmodified response
 */
@Override
public ContainerResponse filter(ContainerRequest request, ContainerResponse response) {
  // TODO check response status
  String clientId = FilterUtils.getClientId(request, _httpContext);
  // don't subscribe if there's no client ID
  if (clientId == null) {
    return response;
  }
  String userId = (AuthUtils.isPermissive() ? null : FilterUtils.getUserId(_httpContext));
  String url = _servletRequest.getRequestURI();
  // TODO should we only subscribe if there were query params, i.e. it was a search request, not just a request for the search page
  for (MasterType masterType : _masterTypes) {
    _updateManager.subscribe(userId, clientId, masterType, url);
  }
  return response;
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:24,代码来源:MasterSubscriptionFilter.java

示例5: decorateWithGlobalMessages

import com.sun.jersey.spi.container.ContainerResponse; //导入依赖的package包/类
public void decorateWithGlobalMessages(ContainerResponse response, AddonsManager addonsManager,
        StorageService storageService,AuthorizationService authenticationService) {
    try {
        boolean admin=authenticationService.isAdmin();
        boolean notAnonymous = !authenticationService.isAnonymous();
        // Try to update the cache if needed
        triggerCacheUpdateProcessIfNeeded(addonsManager, storageService);
        // update response header with message in cache
        ObjectMapper mapper = new ObjectMapper();
        Predicate<FooterMessage> predicate = p -> isVisible(p.getVisibility(), admin, notAnonymous);
        List<FooterMessage> collect = cache.stream().filter(predicate).collect(Collectors.toList());
        String json = mapper.writeValueAsString(collect);
        response.getResponse().getMetadata().add("Artifactory-UI-messages", json);
    } catch (Exception e) {
        log.error("Fail to attache global message to response header", e);
    }
}
 
开发者ID:alancnet,项目名称:artifactory,代码行数:18,代码来源:GlobalMessageProvider.java

示例6: getDate

import com.sun.jersey.spi.container.ContainerResponse; //导入依赖的package包/类
/**
 * Get the {@link com.google.common.net.HttpHeaders#DATE} HTTP header.
 *
 * @return date header value or absent if the header is not set or the value is invalid
 */
public Optional<DateTime> getDate() {
    if (_date == null) {
        Object headerValue = _httpContext.getHttpHeaders().getFirst(DATE);

        _date = Optional.absent();

        if (headerValue != null) {
            try {
                _date = Optional.of(HttpHeaderUtils.parseDate(ContainerResponse.getHeaderValue(headerValue)));
            } catch (Exception ex) {
                LOG.debug("Error parsing date header: value={}", headerValue, ex);
            }
        }
    }

    return _date;
}
 
开发者ID:bazaarvoice,项目名称:dropwizard-caching-bundle,代码行数:23,代码来源:CacheResponseContext.java

示例7: filter

import com.sun.jersey.spi.container.ContainerResponse; //导入依赖的package包/类
@Override
public ContainerResponse filter(ContainerRequest request, ContainerResponse response) {

  Collection<Object> contentTypes = response.getHttpHeaders().get("Content-Type");
  //LOGGER.debug("content types {}", contentTypes);
  if (null != contentTypes) {
    for (Object contentType : contentTypes) {
      if (contentType.equals(APPLICATION_X_PROTOBUF_TYPE) && !shouldSkipWrapping(response.getEntity())) {
        LOGGER.debug("Content type is x-protobuf, wrap response entity");
        ResponseCodeEntityWrapper<Object> wrapper = new ResponseCodeEntityWrapper<>(response.getStatus(), response.getEntity());
        response.setEntity(wrapper, response.getEntityType());
        break;
      }
    }

  }

  return response;
}
 
开发者ID:Wadpam,项目名称:guja,代码行数:20,代码来源:ProtoWrapperResponseFilter.java

示例8: filter

import com.sun.jersey.spi.container.ContainerResponse; //导入依赖的package包/类
@Override
public ContainerResponse filter(ContainerRequest request, ContainerResponse response)
{
	if (!isCorsNeeded(request))
		return response;

	MultivaluedMap<String, Object> headers = response.getHttpHeaders();

	headers.add("Access-Control-Allow-Origin", "*");
	headers.add("Access-Control-Allow-Methods", "GET, POST, OPTIONS");

	String acrh = request.getHeaderValue("Access-Control-Request-Headers");
	if (acrh != null && !acrh.isEmpty())
		headers.add("Access-Control-Allow-Headers", acrh);

	return response;
}
 
开发者ID:zach-m,项目名称:gae-jersey-guice-jsf,代码行数:18,代码来源:CorsFilter.java

示例9: commonLogLine

import com.sun.jersey.spi.container.ContainerResponse; //导入依赖的package包/类
private String commonLogLine(ContainerRequest request, ContainerResponse response) {
	// 127.0.0.1 user-identifier frank [10/Oct/2000:13:55:36 -0700] "GET /apache_pb.gif HTTP/1.0" 200 2326
	return MessageFormat.format(//
			"{0} {1} {2} [{3}] \"{4} /{5} {6}\" {7} {8}", //
			"?", //
			// req.getRemoteAddr(),//
			"-", //
			"?", //
			// req.getRemoteUser(),//
			new DateTime().toString("dd/MMM/yyyy:HH:mm:ss ZZ"), //
			request.getMethod(), //
			request.getPath(), //
			"?", //
			// req.getProtocol(),//
			response.getStatus(), //
			"?"//
	);
}
 
开发者ID:HuygensING,项目名称:elaborate4-backend,代码行数:19,代码来源:LoggingResourceFilter.java

示例10: filter

import com.sun.jersey.spi.container.ContainerResponse; //导入依赖的package包/类
@Override
public ContainerResponse filter(ContainerRequest req,
		ContainerResponse contResp) {

	//String method = req.getMethod();
	
	ResponseBuilder resp = Response.fromResponse(contResp.getResponse());
	
	resp.header("Access-Control-Allow-Origin", "*");
	resp.header("Access-Control-Allow-Headers", "origin, content-type, accept, authorization, x-requested-with");
	resp.header("Access-Control-Allow-Credentials", "true");
	resp.header("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS, HEAD");
	resp.header("Access-Control-Max-Age", "1209600");

	contResp.setResponse(resp.build());
	return contResp;
}
 
开发者ID:GLORIA-project,项目名称:gloria-core,代码行数:18,代码来源:ResponseCorsFilter.java

示例11: filter

import com.sun.jersey.spi.container.ContainerResponse; //导入依赖的package包/类
@Override
public ContainerResponse filter(ContainerRequest req,
		ContainerResponse contResp) {

	ResponseBuilder resp = Response.fromResponse(contResp.getResponse());
	resp.header("Access-Control-Allow-Origin", "*").header(
			"Access-Control-Allow-Methods", "GET, POST, OPTIONS");

	String reqHead = req.getHeaderValue("Access-Control-Request-Headers");

	if (null != reqHead && !reqHead.equals(null)) {
		resp.header("Access-Control-Allow-Headers", reqHead);
	}

	contResp.setResponse(resp.build());
	return contResp;
}
 
开发者ID:srdc,项目名称:semanticMDR,代码行数:18,代码来源:ResponseCorsFilter.java

示例12: addRequestIdToResponse

import com.sun.jersey.spi.container.ContainerResponse; //导入依赖的package包/类
/**
 * Private helper that adds the request-id to the response payload.
 * @param response
 */
private void addRequestIdToResponse(ContainerResponse response) {
	
	// The request-id to be injected in the response
	String requestId = StaashRequestContext.getRequestId();
	
	// The key response attributes
	int status = response.getStatus();
	MediaType mediaType = response.getMediaType();
	
	if (mediaType.equals(MediaType.APPLICATION_JSON_TYPE)) {
		
		String message = (String)response.getEntity();
		JsonObject json = new JsonObject(message);
		json.putString("request-id", requestId);
		
		Response newJerseyResponse = Response.status(status).type(mediaType).entity(json.toString()).build();
		response.setResponse(newJerseyResponse);
	}
		
	// Add the request id to the response regardless of the media type, 
	// this allows non json responses to have a request id in the response
	response.getHttpHeaders().add("x-nflx-staash-request-id", requestId);
}
 
开发者ID:Netflix,项目名称:staash,代码行数:28,代码来源:StaashAuditFilter.java

示例13: filter

import com.sun.jersey.spi.container.ContainerResponse; //导入依赖的package包/类
@Override
public ContainerResponse filter(ContainerRequest request, ContainerResponse response) {
    Integer status = response.getStatus();

    Counter counter = counters.get(status);
    if (counter == null) {
        // despite the method name, this actually will return a previously created metric with the same name
        Counter newCounter = metricsRegistry.counter(
            MetricRegistry.name(resourceClass, metricBaseName + " " + status + " counter"));
        Counter otherCounter = counters.putIfAbsent(status, newCounter);
        if (otherCounter != null) {
            // we lost the race to set that counter, but shouldn't create a duplicate since Metrics.newCounter will do the right thing
            counter = otherCounter;
        } else {
            counter = newCounter;
        }
    }

    counter.inc();

    return response;
}
 
开发者ID:palominolabs,项目名称:jersey-metrics-filter,代码行数:23,代码来源:HttpStatusCodeCounterResourceFilter.java

示例14: filter

import com.sun.jersey.spi.container.ContainerResponse; //导入依赖的package包/类
@Override
public ContainerResponse filter(ContainerRequest request, ContainerResponse response) {
    String incomingOrigin = request.getHeaderValue(CorsHeaders.ORIGIN);
    if (incomingOrigin == null) {
        return response;
    }

    MultivaluedMap<String, Object> h = response.getHttpHeaders();
    putIfNotPresent(h, CorsHeaders.ALLOW_ORIGIN, allowOrigin);
    putIfNotPresent(h, CorsHeaders.MAX_AGE, Integer.toString(maxAge));
    if (!allowMethods.isEmpty()) {
        putIfNotPresent(h, CorsHeaders.ALLOW_METHODS, allowMethods);
    }
    if (!allowHeaders.isEmpty()) {
        putIfNotPresent(h, CorsHeaders.ALLOW_HEADERS, allowHeaders);
    }
    if (allowCredentials) {
        putIfNotPresent(h, CorsHeaders.ALLOW_CREDENTIALS, Boolean.toString(allowCredentials));
    }
    return response;
}
 
开发者ID:palominolabs,项目名称:jersey-cors-filter,代码行数:22,代码来源:CorsPreflightResponseResourceFilter.java

示例15: filter

import com.sun.jersey.spi.container.ContainerResponse; //导入依赖的package包/类
@Override
public ContainerResponse filter(ContainerRequest request, ContainerResponse response) {
    String incomingOrigin = request.getHeaderValue(CorsHeaders.ORIGIN);
    if (incomingOrigin == null) {
        return response;
    }

    MultivaluedMap<String, Object> h = response.getHttpHeaders();
    putIfNotPresent(h, CorsHeaders.ALLOW_ORIGIN, allowOrigin);
    if (!exposeHeaders.isEmpty()) {
        putIfNotPresent(h, CorsHeaders.EXPOSE_HEADERS, exposeHeaders);
    }
    if (allowCredentials) {
        putIfNotPresent(h, CorsHeaders.ALLOW_CREDENTIALS, Boolean.toString(allowCredentials));
    }
    return response;
}
 
开发者ID:palominolabs,项目名称:jersey-cors-filter,代码行数:18,代码来源:CorsResourceResponseResourceFilter.java


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