本文整理匯總了Java中javax.ws.rs.container.ContainerResponseContext.getStatus方法的典型用法代碼示例。如果您正苦於以下問題:Java ContainerResponseContext.getStatus方法的具體用法?Java ContainerResponseContext.getStatus怎麽用?Java ContainerResponseContext.getStatus使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.ws.rs.container.ContainerResponseContext
的用法示例。
在下文中一共展示了ContainerResponseContext.getStatus方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: filter
import javax.ws.rs.container.ContainerResponseContext; //導入方法依賴的package包/類
@Override
public void filter(ContainerRequestContext request, ContainerResponseContext response) {
String duration = "unknown";
try {
Long requestStartTime = (Long)request.getProperty(START_TIME);
if (requestStartTime != null && requestStartTime > 0)
duration = Long.toString(System.currentTimeMillis() - requestStartTime);
} catch (Exception x) {
log.warn("Could not get request start time {}", x);
}
ArrayList<String> httpHeaders = getHeadersToLog(request);
ArrayList<String> cookies = getCookiesToLog(request);
String agent = request.getHeaderString(HttpHeaders.USER_AGENT);
log.info("Request: {} {} agent={} status={} duration={} HTTP Headers={}, Cookies={}",
request.getMethod(), getUrlToLog(request.getUriInfo().getRequestUri().toString()), agent, response.getStatus(), duration, httpHeaders, cookies);
if (! "unknown".equals(duration)) {
Metrics.reportWSApiCallDurationStats(agent, request.getUriInfo().getRequestUri().toString(), request.getMethod(), Long.parseLong(duration));
}
if (response.getStatus() >= 400) {
Metrics.reportWSFailedResponseStats(agent, request.getUriInfo().getRequestUri().toString(), request.getMethod());
}
MDC.remove(USERNAME);
}
示例2: filter
import javax.ws.rs.container.ContainerResponseContext; //導入方法依賴的package包/類
@Override
public void filter(final ContainerRequestContext requestContext, final ContainerResponseContext responseContext) {
if (responseContext.getStatus() == Status.NO_CONTENT.getStatusCode()) {
// No entity returned
for (final Annotation annotation : responseContext.getEntityAnnotations()) {
if (annotation.annotationType() == OnNullReturn404.class) {
// Explicit management of null result -> return a 404 status code
replaceResponse(requestContext, responseContext);
return;
}
}
}
}