本文整理汇总了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;
}
}
}
}