Package javax.ws.rs.core.Response

Examples of javax.ws.rs.core.Response.ResponseBuilder


    if (LOG.isDebugEnabled()) {
      LOG.debug("GET " + uriInfo.getAbsolutePath());
    }
    servlet.getMetrics().incrementRequests(1);
    try {
      ResponseBuilder response = Response.ok(getTableList());
      response.cacheControl(cacheControl);
      servlet.getMetrics().incrementSucessfulGetRequests(1);
      return response.build();
    } catch (IOException e) {
      servlet.getMetrics().incrementFailedGetRequests(1);
      return Response.status(Response.Status.SERVICE_UNAVAILABLE)
        .type(MIMETYPE_TEXT).entity("Unavailable" + CRLF)
        .build();
View Full Code Here


@Provider
public class RestfulObjectsApplicationExceptionMapper implements ExceptionMapper<RestfulObjectsApplicationException> {

    @Override
    public Response toResponse(final RestfulObjectsApplicationException ex) {
        final ResponseBuilder builder = Response.status(ex.getHttpStatusCode().getJaxrsStatusType());

        // body and content-type
        final JsonRepresentation bodyRepr = ex.getBody();
        final Throwable cause = ex.getCause();
        if (bodyRepr != null) {
            final String body = bodyRepr.toString();
            builder.entity(body);
            builder.type(MediaType.APPLICATION_JSON); // generic; the spec doesn't define what the media type should be
        } else if(cause == null) {
            builder.type(MediaType.APPLICATION_JSON); // generic; the spec doesn't define what the media type should be
        } else {
            String body;
            try {
                body = JsonMapper.instance().write(ExceptionPojo.create(cause));
            } catch (final Exception e) {
                // fallback
                body = "{ \"exception\": \"" + ExceptionUtils.getFullStackTrace(cause) + "\" }";
            }
            builder.entity(body);
            builder.type(RestfulMediaType.APPLICATION_JSON_ERROR);
        }

        final String message = ex.getMessage();
        if (message != null) {
            builder.header(RestfulResponse.Header.WARNING.getName(), RestfulResponse.Header.WARNING.render(message));
        }
        return builder.build();
    }
View Full Code Here

    public Response objectRepresentation() {
        final DomainObjectReprRenderer renderer = new DomainObjectReprRenderer(resourceContext, null, JsonRepresentation.newMap());
        renderer.with(objectAdapter).includesSelf();

        final ResponseBuilder respBuilder = ResourceAbstract.responseOfOk(renderer, Caching.NONE);

        final Version version = objectAdapter.getVersion();
        if (version != null && version.getTime() != null) {
            respBuilder.tag(ETAG_FORMAT.format(version.getTime()));
        }
        return respBuilder.build();
    }
View Full Code Here

        // response (void)
        final ActionResultReprRenderer renderer = new ActionResultReprRenderer(resourceContext, null, selfLink, JsonRepresentation.newMap());

        renderer.with(new ObjectAndActionInvocation(objectAdapter, action, arguments, returnedAdapter)).using(adapterLinkTo);

        final ResponseBuilder respBuilder = ResourceAbstract.responseOfOk(renderer, Caching.NONE);

        final Version version = objectAdapter.getVersion();
        ResourceAbstract.addLastModifiedAndETagIfAvailable(respBuilder, version);

        return respBuilder.build();
    }
View Full Code Here

        return responseOfOk(renderer, caching, null);
    }

    public static ResponseBuilder responseOfOk(final ReprRenderer<?, ?> renderer, final Caching caching, final Version version) {
        final MediaType mediaType = renderer.getMediaType();
        final ResponseBuilder response = responseOf(HttpStatusCode.OK).type(mediaType).cacheControl(caching.getCacheControl()).entity(jsonFor(renderer.render()));
        return addLastModifiedAndETagIfAvailable(response, version);
    }
View Full Code Here

            throw new WebApplicationException(e, Response.Status.BAD_REQUEST);
        }

        if (!ifMatchHeader.isMatch(tag)) {
            // none of the tags matches the etag
            ResponseBuilder responseBuilder = delegate.createResponseBuilder();
            responseBuilder.status(HttpServletResponse.SC_PRECONDITION_FAILED).tag(tag);
            return responseBuilder;
        }
        return null;
    }
View Full Code Here

            throw new WebApplicationException(e, Response.Status.BAD_REQUEST);
        }

        if (ifNoneMatchHeader.isMatch(tag)) {
            // some tag matched
            ResponseBuilder responseBuilder = delegate.createResponseBuilder();
            String method = getMethod();
            if (method.equalsIgnoreCase("GET") || method.equalsIgnoreCase("HEAD")) {
                responseBuilder.status(HttpServletResponse.SC_NOT_MODIFIED).tag(tag);
            } else {
                responseBuilder.status(HttpServletResponse.SC_PRECONDITION_FAILED).tag(tag);
            }
            return responseBuilder;
        }
        return null;
    }
View Full Code Here

    private ResponseBuilder evalueateIfUnmodifiedSince(Date lastModified, String headerValue) {

        Date date = dateHeaderDelegate.fromString(headerValue);
        if (lastModified.after(date)) {
            ResponseBuilder responseBuilder = delegate.createResponseBuilder();
            responseBuilder.status(HttpServletResponse.SC_PRECONDITION_FAILED);
            return responseBuilder;
        }
        return null;
    }
View Full Code Here

    private ResponseBuilder evaluateIfModifiedSince(Date lastModified, String headerValue) {
        Date date = dateHeaderDelegate.fromString(headerValue);
        if (lastModified.after(date)) {
            return null;
        }
        ResponseBuilder responseBuilder = delegate.createResponseBuilder();
        responseBuilder.status(HttpServletResponse.SC_NOT_MODIFIED);
        return responseBuilder;
    }
View Full Code Here

            return evaluateIfMatch(tag, ifMatch);
        }
        String ifNoneMatch = getHeaderValue(HttpHeaders.IF_NONE_MATCH);
        String ifModifiedSince = getHeaderValue(HttpHeaders.IF_MODIFIED_SINCE);
        if (ifNoneMatch != null) {
            ResponseBuilder isNoneMatch = evaluateIfNoneMatch(tag, ifNoneMatch);
            if (isNoneMatch != null && ifModifiedSince != null
                && evaluateIfModifiedSince(lastModified, ifModifiedSince) == null) {
                // although isNoneMatch is not null, but need to proceed because
                // of IfModifiedSince
                // requires to proceed
View Full Code Here

TOP

Related Classes of javax.ws.rs.core.Response.ResponseBuilder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.