Package javax.ws.rs.core.Response

Examples of javax.ws.rs.core.Response.ResponseBuilder.type()


        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) {
View Full Code Here


            } 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));
View Full Code Here

            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();
    }
   
    private static boolean matchHttpMethod(String expectedMethod, String httpMethod) {
View Full Code Here

            }
            String msg = "No Book with id " + id + " is available";
            ResponseBuilder builder = Response.status(returnCode).header("BOOK-HEADER", msg);
           
            if (returnCode == 404) {
                builder.type("text/plain").entity(msg);
            }
            throw new WebApplicationException(builder.build());
        }
       
        if (!invocationInProcess) {
View Full Code Here

            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();
    }
   
    private static boolean matchHttpMethod(String expectedMethod, String httpMethod) {
View Full Code Here

            }
            String msg = "No Book with id " + id + " is available";
            ResponseBuilder builder = Response.status(returnCode).header("BOOK-HEADER", msg);
           
            if (returnCode == 404) {
                builder.type("text/plain").entity(msg);
            }
            throw new WebApplicationException(builder.build());
        }
       
        if (!invocationInProcess) {
View Full Code Here

    }
   
    private static WebApplicationException newErrorException(Status statusCode, String message, String mimeType) {
        ResponseBuilder responseBuilder = Response.status(statusCode);
        if (mimeType != null)
            responseBuilder.type(mimeType);
        responseBuilder.entity(message);
        Response response = responseBuilder.build();
        WebApplicationException webAPPEx = new WebApplicationException(response);
        return webAPPEx;
    }
View Full Code Here

     */
    public static Response buildOkResponse(Object obj, String mimeType) {
        ResponseBuilder responseBuilder = Response.status(Status.OK);
        responseBuilder.entity(obj);
        if (mimeType != null)
            responseBuilder.type(mimeType);
        return responseBuilder.build();
    }
   
    /*
    public static Response buildErrorResponse() {
View Full Code Here

     */
    public static Response buildResponse(Status statusCode, Object msg) {
        ResponseBuilder responseBuilder = Response.status(statusCode);
        responseBuilder.entity(msg);
        if (String.class.isAssignableFrom(msg.getClass())) {
            responseBuilder.type(MediaType.TEXT_PLAIN);
        }
        return responseBuilder.build();
    }

    public static Response buildRedirectionResponse(String uri) {
View Full Code Here

            return ResponseUtils.notAcceptable(_snapshotInfo.getMediaTypes());
        }
        final ResponseBuilder builder = makeResponseBuilder();
        // Add Vary header
        builder.variants(MediaTypeUtils.asVariants(_snapshotInfo.getMediaTypes()));
        builder.type(MediaTypeUtils.toJaxRSMediaType(mediaType));
        return ResponseUtils.buildStreamingEntity(builder, _getSnapshot(mediaType));
    }

    /**
     * Deletes the snapshot.
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.