本文整理了Java中javax.ws.rs.container.ContainerResponseContext.setStatusInfo()
方法的一些代码示例,展示了ContainerResponseContext.setStatusInfo()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ContainerResponseContext.setStatusInfo()
方法的具体详情如下:
包路径:javax.ws.rs.container.ContainerResponseContext
类名称:ContainerResponseContext
方法名:setStatusInfo
[英]Set the complete status information (status code and reason phrase) associated with the response.
[中]设置与响应关联的完整状态信息(状态代码和原因短语)。
代码示例来源:origin: Graylog2/graylog2-server
@Override
public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) throws IOException {
final Response.StatusType responseStatus = responseContext.getStatusInfo();
final String requestPath = requestContext.getUriInfo().getAbsolutePath().getPath();
final List<MediaType> acceptableMediaTypes = requestContext.getAcceptableMediaTypes();
final boolean acceptsHtml = acceptableMediaTypes.stream()
.anyMatch(mediaType -> mediaType.isCompatible(MediaType.TEXT_HTML_TYPE) || mediaType.isCompatible(MediaType.APPLICATION_XHTML_XML_TYPE));
final boolean isGetRequest = "get".equalsIgnoreCase(requestContext.getMethod());
if (isGetRequest
&& responseStatus == Response.Status.NOT_FOUND
&& acceptsHtml
&& !requestPath.startsWith("/" + HttpConfiguration.PATH_API)) {
final String entity = indexHtmlGenerator.get(requestContext.getHeaders());
responseContext.setStatusInfo(Response.Status.OK);
responseContext.setEntity(entity, new Annotation[0], MediaType.TEXT_HTML_TYPE);
responseContext.getHeaders().putSingle("X-UA-Compatible", "IE=edge");
}
}
}
代码示例来源:origin: stackoverflow.com
@ResponseStatusCreated
@Provider
class StatusCreatedFilter implements ContainerResponseFilter {
@Override
public void filter(ContainerRequestContext requestContext,
ContainerResponseContext responseContext) throws IOException {
responseContext.setStatusInfo(Response.Status.CREATED)
String location = "..."; // set based on responseContext.getEntity()
// or any other properties
responseContext.getHeaders().putSingle("Location", location);
}
}
代码示例来源:origin: org.graylog2/graylog2-server
@Override
public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) throws IOException {
final Response.StatusType responseStatus = responseContext.getStatusInfo();
final String requestPath = requestContext.getUriInfo().getAbsolutePath().getPath();
final List<MediaType> acceptableMediaTypes = requestContext.getAcceptableMediaTypes();
final boolean acceptsHtml = acceptableMediaTypes.stream()
.anyMatch(mediaType -> mediaType.isCompatible(MediaType.TEXT_HTML_TYPE) || mediaType.isCompatible(MediaType.APPLICATION_XHTML_XML_TYPE));
final boolean isGetRequest = "get".equalsIgnoreCase(requestContext.getMethod());
if (isGetRequest
&& responseStatus == Response.Status.NOT_FOUND
&& acceptsHtml
&& requestPath.startsWith(webAppPrefix)) {
final String entity = indexHtmlGenerator.get();
responseContext.setStatusInfo(Response.Status.OK);
responseContext.setEntity(entity, new Annotation[0], MediaType.TEXT_HTML_TYPE);
responseContext.getHeaders().putSingle("X-UA-Compatible", "IE=edge");
}
}
}
代码示例来源:origin: robeio/robe
LOGGER.debug("Now: " + DateTime.now().toDate().toString());
responseContext.getHeaders().putSingle("Set-Cookie", getTokenSentence(null));
responseContext.setStatusInfo(Response.Status.UNAUTHORIZED);
responseContext.setEntity("Token expired. Please login again.");
LOGGER.info("Token expired. Please login again.");
responseContext.setStatusInfo(Response.Status.UNAUTHORIZED);
代码示例来源:origin: io.robe/robe-auth
LOGGER.debug("Now: " + DateTime.now().toDate().toString());
responseContext.getHeaders().putSingle("Set-Cookie", getTokenSentence(""));
responseContext.setStatusInfo(Response.Status.UNAUTHORIZED);
responseContext.setEntity("Token expired. Please login again.");
LOGGER.info("Token expired. Please login again.");
responseContext.setStatusInfo(Response.Status.UNAUTHORIZED);
代码示例来源:origin: com.oracle.ozark/ozark
responseContext.setStatusInfo(OK); // Needed for method returning void
} else {
throw new ServerErrorException("Response entity is null. Missing @View annotation? "
if (view.startsWith(REDIRECT)) {
final String uri = uriInfo.getBaseUri() + view.substring(REDIRECT.length() + 1);
responseContext.setStatusInfo(FOUND);
responseContext.getHeaders().putSingle(LOCATION_HEADER, uri);
responseContext.setEntity(null);
代码示例来源:origin: icode/ameba
/**
* <p>applyStreaming.</p>
*
* @param requestContext a {@link javax.ws.rs.container.ContainerRequestContext} object.
* @param context a {@link javax.ws.rs.ext.WriterInterceptorContext} object.
* @throws java.io.IOException if any.
*/
protected void applyStreaming(ContainerRequestContext requestContext, WriterInterceptorContext context)
throws IOException {
Object entity = context.getEntity();
StreamingProcess<Object> process = MessageHelper.getStreamingProcess(context.getEntity(), manager);
if (process != null) {
ContainerResponseContext responseContext =
(ContainerResponseContext) requestContext.getProperty(RESP_PROP_N);
responseContext.setStatusInfo(Response.Status.PARTIAL_CONTENT);
context.getHeaders().putSingle(ACCEPT_RANGES, BYTES_RANGE);
context.setType(StreamingOutput.class);
context.setEntity(new MediaStreaming(
entity,
requestContext.getHeaderString(MediaStreaming.RANGE),
process,
context.getMediaType(),
context.getHeaders()
)
);
}
}
代码示例来源:origin: org.mvc-spec.ozark/ozark-core
responseContext.setStatusInfo(Response.Status.OK);
final String uri = uriInfo.getBaseUri() + noStartingSlash(noPrefix(view, REDIRECT));
if (view.startsWith(REDIRECT)) {
responseContext.setStatusInfo(SEE_OTHER);
responseContext.getHeaders().putSingle(HttpHeaders.LOCATION, uri);
responseContext.setEntity(null);
代码示例来源:origin: org.glassfish.ozark/ozark
responseContext.setStatusInfo(OK); // Needed for method returning void
} else if (returnType == Void.class) {
throw new ServerErrorException(messages.get("VoidControllerNoView", resourceInfo.getResourceMethod()),
final String uri = uriInfo.getBaseUri() + noStartingSlash(noPrefix(view, REDIRECT));
if (view.startsWith(REDIRECT)) {
responseContext.setStatusInfo(SEE_OTHER);
responseContext.getHeaders().putSingle(HttpHeaders.LOCATION, uri);
responseContext.setEntity(null);
内容来源于网络,如有侵权,请联系作者删除!