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