本文整理了Java中javax.ws.rs.core.Response.fromResponse
方法的一些代码示例,展示了Response.fromResponse
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Response.fromResponse
方法的具体详情如下:
包路径:javax.ws.rs.core.Response
类名称:Response
方法名:fromResponse
[英]Create a new ResponseBuilder by performing a shallow copy of an existing Response.
The returned builder has its own #getHeaders()but the header values are shared with the original Response instance. The original response entity instance reference is set in the new response builder.
Note that if the entity is backed by an un-consumed input stream, the reference to the stream is copied. In such case make sure to #bufferEntity() the entity stream of the original response instance before passing it to this method.
[中]通过执行现有响应的浅拷贝来创建新的响应生成器。
返回的生成器有自己的#getHeaders(),但头值与原始响应实例共享。原始响应实体实例引用在新的响应生成器中设置。
请注意,如果实体由未使用的输入流支持,则复制对该流的引用。在这种情况下,在将原始响应实例的实体流传递给此方法之前,请确保#bufferEntity()将其保存。
代码示例来源:origin: Graylog2/graylog2-server
@Override
public Response toResponse(WebApplicationException e) {
final ApiError apiError = ApiError.create(e.getMessage());
return Response.fromResponse(e.getResponse())
.type(MediaType.APPLICATION_JSON_TYPE)
.entity(apiError).build();
}
}
代码示例来源:origin: dropwizard/dropwizard
@Override
public Response toResponse(E exception) {
// If we're dealing with a web exception, we can service certain types of request (like
// redirection or server errors) better and also propagate properties of the inner response.
if (exception instanceof WebApplicationException) {
final Response response = ((WebApplicationException) exception).getResponse();
Response.Status.Family family = response.getStatusInfo().getFamily();
if (family.equals(Response.Status.Family.REDIRECTION)) {
return response;
}
if (family.equals(Response.Status.Family.SERVER_ERROR)) {
logException(exception);
}
return Response.fromResponse(response)
.type(MediaType.APPLICATION_JSON_TYPE)
.entity(new ErrorMessage(response.getStatus(), exception.getLocalizedMessage()))
.build();
}
// Else the thrown exception is a not a web exception, so the exception is most likely
// unexpected. We'll create a unique id in the server error response that is also logged for
// correlation
final long id = logException(exception);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode())
.type(MediaType.APPLICATION_JSON_TYPE)
.entity(new ErrorMessage(formatErrorMessage(id, exception)))
.build();
}
代码示例来源:origin: traccar/traccar
@Override
public Response toResponse(Exception e) {
if (e instanceof WebApplicationException) {
WebApplicationException exception = (WebApplicationException) e;
String message;
if (exception.getCause() != null) {
message = Log.exceptionStack(exception.getCause());
} else {
message = Log.exceptionStack(exception);
}
return Response.fromResponse(exception.getResponse()).entity(message).build();
} else {
return Response.status(Response.Status.BAD_REQUEST).entity(Log.exceptionStack(e)).build();
}
}
代码示例来源:origin: apache/hive
fields.remove("columns");
fields.put("column", found);
return Response.fromResponse(res).entity(fields).build();
代码示例来源:origin: graphhopper/graphhopper
sw.stop();
logger.info("took: " + sw.getSeconds() + ", visited nodes:" + isochrone.getVisitedNodes() + ", " + uriInfo.getQueryParameters());
return Response.fromResponse(jsonSuccessResponse(buckets, sw.getSeconds()))
.header("X-GH-Took", "" + sw.getSeconds() * 1000)
.build();
return Response.fromResponse(jsonSuccessResponse(features, sw.getSeconds()))
.header("X-GH-Took", "" + sw.getSeconds() * 1000)
.build();
代码示例来源:origin: com.atlassian.plugins.rest/atlassian-rest-common
/**
* Adds the appropriate cors response headers to the response of
* <a href="http://www.w3.org/TR/cors/#resource-requests">cors requests</a>
* from a whitelisted origin.
*
* @param request the request.
* @param containerResponse the response.
* @return containerResponse
*/
public ContainerResponse filter(ContainerRequest request, ContainerResponse containerResponse) {
if (request.getProperties().containsKey(CORS_PREFLIGHT_FAILED) ||
request.getProperties().containsKey(CORS_PREFLIGHT_SUCCEEDED) ||
extractOrigin(request) == null) {
return containerResponse;
}
Iterable<CorsDefaults> defaults = pluginModuleTracker.getModules();
try {
String origin = validateSingleOriginInWhitelist(defaults, request);
Iterable<CorsDefaults> defaultsWithAllowedOrigin = allowsOrigin(defaults, origin);
Response.ResponseBuilder response = Response.fromResponse(containerResponse.getResponse());
addAccessControlAllowOrigin(response, origin);
conditionallyAddAccessControlAllowCredentials(response, origin, defaultsWithAllowedOrigin);
addAccessControlExposeHeaders(response, getAllowedResponseHeaders(defaultsWithAllowedOrigin, origin));
containerResponse.setResponse(response.build());
return containerResponse;
} catch (PreflightFailedException ex) {
log.info("Unable to add CORS headers to response: " + ex.getMessage());
}
return containerResponse;
}
代码示例来源:origin: org.graylog2/graylog2-server
@Override
public Response toResponse(WebApplicationException e) {
final ApiError apiError = new ApiError(e.getMessage());
return Response.fromResponse(e.getResponse()).type(MediaType.APPLICATION_JSON_TYPE).entity(apiError).build();
}
}
代码示例来源:origin: org.graylog2/graylog2-shared
@Override
public Response toResponse(WebApplicationException e) {
final ApiError apiError = new ApiError(e.getMessage());
return Response.fromResponse(e.getResponse()).type(MediaType.APPLICATION_JSON_TYPE).entity(apiError).build();
}
}
代码示例来源:origin: com.moodysalem.java/jaxrs-lib
@Override
public Response toResponse(WebApplicationException e) {
final Set<RequestError> requestErrors = new HashSet<>(Collections.singletonList(new RequestError(e.getMessage())));
final ErrorResponse response = new ErrorResponse(e.getResponse().getStatus(), requestErrors);
return Response.fromResponse(e.getResponse())
.entity(response)
.header(RequestProcessingExceptionMapper.NUMBER_OF_ERRORS_HEADER, requestErrors.size())
.build();
}
}
代码示例来源:origin: io.syndesis.rest/rest-endpoint
@Override
public Response toResponse(final ClientErrorException exception) {
final Response response = exception.getResponse();
final RestError error = new RestError(exception.getMessage(), "Given request is not acceptable", null,
response.getStatus());
return Response.fromResponse(response).type(MediaType.APPLICATION_JSON_TYPE).entity(error).build();
}
代码示例来源:origin: icode/ameba
protected Response notFound() {
Throwable e = new NotFoundException();
return Response.fromResponse(mappers.get().findMapping(e).toResponse(e))
.type(MediaType.TEXT_HTML_TYPE).build();
}
代码示例来源:origin: org.fcrepo/fcrepo-http-commons
@Override
public Response toResponse(final ServerErrorException e) {
debugException(this, e, LOGGER);
return fromResponse(e.getResponse()).entity(e.getMessage()).type(TEXT_PLAIN_WITH_CHARSET).build();
}
}
代码示例来源:origin: org.fcrepo/fcrepo-http-commons
@Override
public Response toResponse(final ClientErrorException e) {
debugException(this, e, LOGGER);
return fromResponse(e.getResponse()).entity(e.getMessage()).type(TEXT_PLAIN_WITH_CHARSET).build();
}
}
代码示例来源:origin: net.roboconf/roboconf-dm-rest-api
@Override
public ContainerResponse filter( ContainerRequest req, ContainerResponse contResp ) {
ResponseBuilder resp = Response.fromResponse( contResp.getResponse());
resp
.header( "Access-Control-Allow-Origin", "*" )
.header( "Access-Control-Allow-Methods", "GET, DELETE, POST, OPTIONS" );
String reqHead = req.getHeaderValue( "Access-Control-Request-Headers" );
if( ! Utils.isEmptyOrWhitespaces( reqHead ))
resp.header( "Access-Control-Allow-Headers", reqHead );
contResp.setResponse( resp.build());
return contResp;
}
}
代码示例来源:origin: org.fcrepo/fcrepo-http-commons
@Override
public Response toResponse(final ParamException e) {
LOGGER.error("ParamException intercepted by ParamExceptionMapper: {}\n", e.getMessage());
debugException(this, e, LOGGER);
final String msg = "Error parsing parameter: " + e.getParameterName() + ", of type: " +
e.getParameterType().getSimpleName();
return fromResponse(e.getResponse()).entity(msg).type(TEXT_PLAIN_WITH_CHARSET).build();
}
代码示例来源:origin: org.mycore/mycore-restapi
public Response toResponse(NotAuthorizedException ex) {
if (ex.getMessage()==null || ex.getResponse().getEntity() != null){
return ex.getResponse();
}
return Response.fromResponse(ex.getResponse())
.header(HttpHeaders.CONTENT_TYPE, MediaType.TEXT_PLAIN+ ";charset=utf-8")
.entity(ex.getMessage())
.build();
}
}
代码示例来源:origin: org.mycore/mycore-restapi
public Response toResponse(ForbiddenException ex) {
String userID = MCRSessionMgr.getCurrentSession().getUserInformation().getUserID();
if (userID.equals(MCRSystemUserInformation.getGuestInstance().getUserID())) {
LogManager.getLogger().warn("Guest detected");
return Response.fromResponse(ex.getResponse())
.status(Response.Status.UNAUTHORIZED)
.header(HttpHeaders.WWW_AUTHENTICATE, MCRRestAPIUtil.getWWWAuthenticateHeader("Basic", null, app))
.build();
}
return ex.getResponse();
}
}
代码示例来源:origin: com.nesscomputing.components/ness-jersey
@Override
public ContainerResponse filter(ContainerRequest request, ContainerResponse response)
{
if (MediaType.APPLICATION_JSON_TYPE.isCompatible(response.getMediaType()) || TEXT_JSON.isCompatible(response.getMediaType())) {
response.setResponse(Response.fromResponse(response.getResponse()).type(APPLICATION_JSON_UTF8_TYPE).build());
}
return response;
}
}
代码示例来源:origin: com.atlassian.applinks/applinks-plugin-core
@Override
public void intercept(MethodInvocation methodInvocation) throws IllegalAccessException, InvocationTargetException
{
methodInvocation.invoke();
Response response = methodInvocation.getHttpContext().getResponse().getResponse();
Response noCacheResponse = Response.fromResponse(response).header("Cache-Control", "no-cache").build();
methodInvocation.getHttpContext().getResponse().setResponse(noCacheResponse);
}
}
代码示例来源:origin: com.atlassian.applinks/applinks-common
@Override
public void intercept(MethodInvocation methodInvocation) throws IllegalAccessException, InvocationTargetException {
methodInvocation.invoke();
Response response = methodInvocation.getHttpContext().getResponse().getResponse();
Response noCacheResponse = Response.fromResponse(response).header(HttpHeaders.CACHE_CONTROL, "no-cache").build();
methodInvocation.getHttpContext().getResponse().setResponse(noCacheResponse);
}
}
内容来源于网络,如有侵权,请联系作者删除!