本文整理汇总了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());
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
}
示例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;
}
示例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;
}
示例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;
}
示例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(), //
"?"//
);
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}