Package javax.ws.rs.core.Response

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


        // Check If-Match. If it is not available proceed to checking If-Not-Modified-Since
        // if it is available and the preconditions are not met - return, otherwise:
        // Check If-Not-Match. If it is not available proceed to checking If-Modified-Since
        // otherwise return the evaluation result
       
        ResponseBuilder rb = evaluateIfMatch(eTag, lastModified);
        if (rb == null) {
            rb = evaluateIfNonMatch(eTag, lastModified);
        }
        return rb;
    }
View Full Code Here


   
    public ResponseBuilder evaluatePreconditions(Date lastModified) {
        if (lastModified == null) {
            throw new IllegalArgumentException("Date is null");
        }
        ResponseBuilder rb = evaluateIfNotModifiedSince(lastModified);
        if (rb == null) {
            rb = evaluateIfModifiedSince(lastModified);
        }
        return rb;
    }
View Full Code Here

        doCancel(HttpUtils.getHttpDateFormat().format(retryAfter));
    }
   
    private synchronized void doCancel(String retryAfterHeader) {
        checkSuspended();
        ResponseBuilder rb = Response.status(503);
        if (retryAfterHeader != null) {
            rb.header(HttpHeaders.RETRY_AFTER, retryAfterHeader);
        }
        doResume(rb.build());
        cancelled = true;
    }
View Full Code Here

        LOG.fine(errorMsg.toString());
    }

    public static Response createResponse(ClassResourceInfo cri, Message msg,
                                          String responseMessage, int status, boolean addAllow) {
        ResponseBuilder rb = toResponseBuilder(status);
        if (addAllow) {
            Set<String> allowedMethods = cri.getAllowedMethods();
            for (String m : allowedMethods) {
                rb.header("Allow", m);
            }
            // "OPTIONS" are supported all the time really
            if (!allowedMethods.contains("OPTIONS")) {
                rb.header("Allow", "OPTIONS");
            }
            if (!allowedMethods.contains("HEAD") && allowedMethods.contains("GET")) {
                rb.header("Allow", "HEAD");
            }
        }
        if (msg != null && MessageUtils.isTrue(msg.getContextualProperty(REPORT_FAULT_MESSAGE_PROPERTY))) {
            rb.type(MediaType.TEXT_PLAIN_TYPE).entity(responseMessage);
        }
        return rb.build();
    }
View Full Code Here

    public static ResponseBuilder toResponseBuilder(Response.Status status) {
        return toResponseBuilder(status.getStatusCode());
    }
   
    public static ResponseBuilder fromResponse(Response response) {
        ResponseBuilder rb = toResponseBuilder(response.getStatus());
        rb.entity(response.getEntity());
        for (Map.Entry<String, List<Object>> entry : response.getMetadata().entrySet()) {
            List<Object> values = entry.getValue();
            for (Object value : values) {
                rb.header(entry.getKey(), value);
            }
        }
        return rb;
    }
View Full Code Here

    protected Response getResponse(Message inMessage) {
        Response resp = inMessage.getExchange().get(Response.class);
        if (resp != null) {
            return resp;
        }
        ResponseBuilder rb = Response.status((Integer)inMessage.get(Message.RESPONSE_CODE));
        rb.entity(inMessage.get(InputStream.class));
       
        @SuppressWarnings("unchecked")
        Map<String, List<String>> protocolHeaders =
            (Map<String, List<String>>)inMessage.get(Message.PROTOCOL_HEADERS);
        for (Map.Entry<String, List<String>> entry : protocolHeaders.entrySet()) {
            if (null == entry.getKey()) {
                continue;
            }
            if (entry.getValue().size() > 0) {
                for (String val : entry.getValue()) {
                    rb.header(entry.getKey(), val);
                }
            }
        }
       
               
        return rb.build();
    }
View Full Code Here

        String op = (String)m.getExchange().get(CrossOriginResourceSharingFilter.class.getName());
        if (op == null || op == PREFLIGHT_FAILED) {
            return response;
        }
        
        ResponseBuilder rbuilder = Response.fromResponse(response);
       
        /* Common to simple and preflight */
        rbuilder.header(CorsHeaderConstants.HEADER_AC_ALLOW_ORIGIN,
                        m.getExchange().get(CorsHeaderConstants.HEADER_ORIGIN));
        rbuilder.header(CorsHeaderConstants.HEADER_AC_ALLOW_CREDENTIALS,
                        m.getExchange().get(CorsHeaderConstants.HEADER_AC_ALLOW_CREDENTIALS));
       
        if (SIMPLE_REQUEST.equals(op)) {
            /* 5.1.4 expose headers */
            List<String> effectiveExposeHeaders
                = getHeadersFromInput(m, CorsHeaderConstants.HEADER_AC_EXPOSE_HEADERS);
            if (effectiveExposeHeaders != null) {
                addHeaders(rbuilder, CorsHeaderConstants.HEADER_AC_EXPOSE_HEADERS,
                           effectiveExposeHeaders, false);
            }
            // if someone wants to clear the cache, we can't help them.
            return rbuilder.build();
        } else {
            // 5.2.8 max-age
            String maValue = (String)m.getExchange().get(CorsHeaderConstants.HEADER_AC_MAX_AGE);
            if (maValue != null) {
                rbuilder.header(CorsHeaderConstants.HEADER_AC_MAX_AGE, maValue);
            }
            // 5.2.9 add allowed methods
            /*
             * Currently, input side just lists the one requested method, and spec endorses that.
             */
            addHeaders(rbuilder, CorsHeaderConstants.HEADER_AC_ALLOW_METHODS,
                       getHeadersFromInput(m, CorsHeaderConstants.HEADER_AC_ALLOW_METHODS), false);
            // 5.2.10 add allowed headers
            List<String> rqAllowedHeaders = getHeadersFromInput(m,
                                                                CorsHeaderConstants.HEADER_AC_ALLOW_HEADERS);
            if (rqAllowedHeaders != null) {
                addHeaders(rbuilder, CorsHeaderConstants.HEADER_AC_ALLOW_HEADERS, rqAllowedHeaders, false);
            }
            return rbuilder.build();

        }
    }
View Full Code Here

    protected void reportInvalidClient() {
        reportInvalidClient(new OAuthError(OAuthConstants.INVALID_CLIENT));
    }
   
    protected void reportInvalidClient(OAuthError error) {
        ResponseBuilder rb = JAXRSUtils.toResponseBuilder(401);
        throw ExceptionUtils.toNotAuthorizedException(null,
            rb.type(MediaType.APPLICATION_JSON_TYPE).entity(error).build());
    }
View Full Code Here

    public static void throwAuthorizationFailure(Set<String> challenges) {
        throwAuthorizationFailure(challenges, null);
    }
   
    public static void throwAuthorizationFailure(Set<String> challenges, String realm) {
        ResponseBuilder rb = JAXRSUtils.toResponseBuilder(401);
       
        StringBuilder sb = new StringBuilder();
        for (String challenge : challenges) {
            if ("*".equals(challenge)) {
                continue;
            }
            if (sb.length() > 0) {
                sb.append(",");
            }
            sb.append(challenge);
        }
        if (sb.length() > 0) {
            if (realm != null) {
                sb.append(" realm=\"" + realm + "\"");
            }
            rb.header(HttpHeaders.WWW_AUTHENTICATE, sb.toString());
        }
        Response r = rb.build();
        throw ExceptionUtils.toNotAuthorizedException(null, r);
    }
View Full Code Here

    private Date modified;

    public Response perform(final Request request) {
        final Date lastModified = getLastModified();
        final EntityTag entityTag = getEntityTag();
        ResponseBuilder rb = request.evaluatePreconditions(lastModified, entityTag);
        if (rb == null) {
            rb = Response.ok();
        } else {
            // okay
        }
        return rb.build();
    }
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.