當前位置: 首頁>>代碼示例>>Java>>正文


Java ContainerResponseContext.getStatus方法代碼示例

本文整理匯總了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);
}
 
開發者ID:Comcast,項目名稱:redirector,代碼行數:31,代碼來源:SimpleAccessLoggingFilter.java

示例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;
			}
		}
	}
}
 
開發者ID:ligoj,項目名稱:bootstrap,代碼行數:14,代碼來源:NotFoundResponseFilter.java


注:本文中的javax.ws.rs.container.ContainerResponseContext.getStatus方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。