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


Java ContainerResponseContext.setStatus方法代碼示例

本文整理匯總了Java中javax.ws.rs.container.ContainerResponseContext.setStatus方法的典型用法代碼示例。如果您正苦於以下問題:Java ContainerResponseContext.setStatus方法的具體用法?Java ContainerResponseContext.setStatus怎麽用?Java ContainerResponseContext.setStatus使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.ws.rs.container.ContainerResponseContext的用法示例。


在下文中一共展示了ContainerResponseContext.setStatus方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: processResponse

import javax.ws.rs.container.ContainerResponseContext; //導入方法依賴的package包/類
@Override
public void processResponse(ContainerRequestContext requestContext, ContainerResponseContext responseContext,
		ResourceInfo resourceInfo) {
	MediaType mediaType = responseContext.getMediaType();
	if (mediaType != null && MediaType.APPLICATION_JSON_TYPE.equals(mediaType)) {
		Object responseData = responseContext.getEntity();
		WrapperResponseEntity jsonResponse;

		if (responseData instanceof WrapperResponseEntity) {
			jsonResponse = (WrapperResponseEntity) responseData;
		} else {
			jsonResponse = new WrapperResponseEntity(ResponseCode.OK);
			jsonResponse.setData(responseData);
		}
		responseContext.setStatus(ResponseCode.OK.getCode());

		responseContext.setEntity(jsonResponse);

	}
}
 
開發者ID:vakinge,項目名稱:jeesuite-libs,代碼行數:21,代碼來源:ResponseWrapperHandler.java

示例2: populateResponse

import javax.ws.rs.container.ContainerResponseContext; //導入方法依賴的package包/類
public void populateResponse(ContainerResponseContext responseContext) {
    if (hasResponseContent) {
        responseContext.setEntity(responseContent);
    }
    if (hasResponseContentType) {
        responseContext.getHeaders().putSingle(HttpHeaders.CONTENT_TYPE, responseContentType);
    }
    if (hasResponseStatus) {
        responseContext.setStatus(responseStatus);
    }
    for (Entry<String, String> headers : responseHeaders.entrySet()) {
        responseContext.getHeaders().putSingle(headers.getKey(), headers.getValue());
    }
    for (NewCookie cookie : responseCookies) {
        responseContext.getHeaders().add(HttpHeaders.SET_COOKIE, cookie);
    }
}
 
開發者ID:pac4j,項目名稱:jax-rs-pac4j,代碼行數:18,代碼來源:JaxRsContext.java

示例3: processResponse

import javax.ws.rs.container.ContainerResponseContext; //導入方法依賴的package包/類
@Override
public void processResponse(ContainerRequestContext requestContext,
                            ContainerResponseContext responseContext,
                            ResourceInfo resourceInfo) {
    MediaType mediaType = responseContext.getMediaType();
    if (mediaType != null && MediaType.APPLICATION_JSON_TYPE.equals(mediaType)) {
        Object responseData = responseContext.getEntity();
        WrapperResponseEntity jsonResponse;

        if (responseData instanceof WrapperResponseEntity) {
            jsonResponse = (WrapperResponseEntity) responseData;
        } else {
            jsonResponse = new WrapperResponseEntity(ResponseCode.OK);
            jsonResponse.setData(responseData);
        }
        responseContext.setStatus(ResponseCode.OK.getCode());

        responseContext.setEntity(jsonResponse);

    }
}
 
開發者ID:warlock-china,項目名稱:azeroth,代碼行數:22,代碼來源:ResponseWrapperHandler.java

示例4: replaceResponse

import javax.ws.rs.container.ContainerResponseContext; //導入方法依賴的package包/類
/**
 * Set the entity response to a 404 JSON entity.
 */
private void replaceResponse(final ContainerRequestContext requestContext, final ContainerResponseContext responseContext) {
	final ServerError serverError = new ServerError();
	if (requestContext.getUriInfo().getPathParameters().size() == 1) {
		// Single parameter ---> entity identifier or whatever identifying a data
		serverError.setCode("entity");
		serverError.setMessage(requestContext.getUriInfo().getPathParameters().values().iterator().next().get(0));
	} else {
		serverError.setCode("data");
	}
	responseContext.setStatus(Status.NOT_FOUND.getStatusCode());
	responseContext.setEntity(toEntity(serverError), responseContext.getEntityAnnotations(), MediaType.APPLICATION_JSON_TYPE);

}
 
開發者ID:ligoj,項目名稱:bootstrap,代碼行數:17,代碼來源:NotFoundResponseFilter.java

示例5: filter

import javax.ws.rs.container.ContainerResponseContext; //導入方法依賴的package包/類
@Override
public void filter(
		ContainerRequestContext containerRequestContext,
		ContainerResponseContext containerResponseContext)
	throws IOException {

	Object entity = containerResponseContext.getEntity();

	if (entity instanceof Try.Failure) {
		Try.Failure failure = (Try.Failure)entity;

		Exception exception = failure.getException();

		Optional<APIError> optional = _exceptionConverterManager.convert(
			exception);

		APIError apiError = optional.orElseThrow(
			() -> new MustHaveExceptionConverter(exception.getClass()));

		if (_apioLogger != null) {
			_apioLogger.error(apiError);
		}

		ErrorMessageMapper errorMessageMapper =
			_errorMessageMapperManager.getErrorMessageMapper(
				apiError, _httpHeaders);

		String result = ErrorWriter.writeError(
			errorMessageMapper, apiError, _httpHeaders);

		MultivaluedMap<String, Object> headers =
			containerResponseContext.getHeaders();

		headers.remove("Content-Type");
		headers.add("Content-Type", errorMessageMapper.getMediaType());

		containerResponseContext.setEntity(result);
		containerResponseContext.setStatus(apiError.getStatusCode());
	}
}
 
開發者ID:liferay,項目名稱:com-liferay-apio-architect,代碼行數:41,代碼來源:FailureFilter.java

示例6: filter

import javax.ws.rs.container.ContainerResponseContext; //導入方法依賴的package包/類
@Override
public void filter(ContainerRequestContext req, ContainerResponseContext resp) throws IOException {

    if (resp.hasEntity() && (resp.getEntity() instanceof Status)) {
        Status status = (Status) resp.getEntity();
        int code = (Status.State.UP == status.getState()) ? 200 : 503;
        resp.setStatus(code);
        resp.setEntity(status.toJson());
        resp.getHeaders().putSingle("Content-Type", MediaType.APPLICATION_JSON);
    }
}
 
開發者ID:wildfly-swarm,項目名稱:wildfly-swarm,代碼行數:12,代碼來源:HealthResponseFilter.java


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