Package javax.ws.rs.core.Response

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


   
   
    public static Response handleException(MessageContext mc,
                                           Exception e,
                                           int status) {
        ResponseBuilder builder = Response.status(status);
        if (MessageUtils.isTrue(mc.getContextualProperty(REPORT_FAILURE_DETAILS))) {
            boolean asHeader = MessageUtils.isTrue(
                mc.getContextualProperty(REPORT_FAILURE_DETAILS_AS_HEADER));
            String text = null;
            if (e instanceof OAuthProblemException) {
                OAuthProblemException problem = (OAuthProblemException)e;
                if (asHeader && problem.getProblem() != null) {
                    text = problem.getProblem();
                }
            }
            if (text == null) {
                text = e.getMessage();
            }
            if (asHeader) {
                builder.header("oauth_problem", text);
            } else {
                builder.entity(e.getMessage());   
            }
        }
        return builder.build();
    }
View Full Code Here


        throw new UnsupportedOperationException(
                "Call of fromResponse() method is not expected in RestServiceExceptionMapper");
    }

    private Response getCompositeExceptionResponse(final SyncopeClientCompositeErrorException ex) {
        ResponseBuilder responseBuilder = Response.status(ex.getStatusCode().value());
        for (SyncopeClientException sce : ex.getExceptions()) {
            responseBuilder.header(EXCEPTION_TYPE_HEADER, sce.getType().getHeaderValue());

            for (String attributeName : sce.getElements()) {
                responseBuilder.header(sce.getType().getElementHeaderName(), attributeName);
            }
        }
        return responseBuilder.build();
    }
View Full Code Here

        }
        return responseBuilder.build();
    }

    private Response processServerErrorExceptions(final Exception ex) {
        ResponseBuilder responseBuilder = Response.status(Response.Status.INTERNAL_SERVER_ERROR);
        if (ex instanceof org.apache.ibatis.exceptions.PersistenceException) {
            return buildResponse(responseBuilder, SyncopeClientExceptionType.Workflow, getMessage(ex,
                    "Currently unavailable. Please try later."));
        } else if (ex instanceof JpaSystemException) {
            return buildResponse(responseBuilder, SyncopeClientExceptionType.DataIntegrityViolation, getExMessage(ex));
View Full Code Here

        return null;
    }

    private Response processNotFoundExceptions(final Exception ex) {
        ResponseBuilder responseBuilder = Response.status(Response.Status.NOT_FOUND);

        if (ex instanceof javax.ws.rs.NotFoundException) {
            return buildResponse(responseBuilder, SyncopeClientExceptionType.NotFound, getExMessage(ex));

        } else if (ex instanceof NotFoundException) {
View Full Code Here

        }
        return null;
    }

    private Response processBadRequestExceptions(final Exception ex) {
        ResponseBuilder responseBuilder = Response.status(Response.Status.BAD_REQUEST);

        if (ex instanceof BadRequestException) {
            if (((BadRequestException) ex).getResponse() == null) {
                return responseBuilder.build();
            } else {
                return ((BadRequestException) ex).getResponse();
            }

        } else if (ex instanceof InvalidEntityException) {
            SyncopeClientExceptionType exType = SyncopeClientExceptionType.valueOf("Invalid"
                    + ((InvalidEntityException) ex).getEntityClassSimpleName());

            responseBuilder.header(SyncopeClientErrorHandler.EXCEPTION_TYPE_HEADER, exType.getHeaderValue());

            for (@SuppressWarnings("rawtypes") Map.Entry<Class, Set<EntityViolationType>> violation
                    : ((InvalidEntityException) ex).getViolations().entrySet()) {

                for (EntityViolationType violationType : violation.getValue()) {
                    responseBuilder.header(exType.getElementHeaderName(),
                            violation.getClass().getSimpleName() + ": " + violationType);
                }
            }
            return responseBuilder.build();
        } else if (ex instanceof WorkflowException) {
            return buildResponse(responseBuilder, SyncopeClientExceptionType.Workflow, getExMessage(ex));
        } else if (ex instanceof PropagationException) {
            return buildResponse(responseBuilder, SyncopeClientExceptionType.Propagation, getMessage(ex,
                    ((PropagationException) ex).getResourceName()));
View Full Code Here

    if (error.code == null) {
      error.code = e.getClass().getSimpleName();
    }

    ResponseBuilder response = Response.status(Response.Status.INTERNAL_SERVER_ERROR);
    response.entity(error);
    return response.build();

    // VariantListBuilder variantListBuilder = VariantListBuilder.newInstance();
    // variantListBuilder.mediaTypes(MediaType.APPLICATION_JSON_TYPE, MediaType.APPLICATION_XML_TYPE);
    // List<Variant> variants = variantListBuilder.build();
    //
View Full Code Here

    }

    String responseData = download.getContent();
    String contentType = download.getContentType();

    ResponseBuilder rBuild = Response.ok(responseData, contentType);
    return rBuild.build();
  }
View Full Code Here

            } else {
                throw new RuntimeException("Unknown client side exception");
            }
        }
        int status = responseCode.intValue();
        ResponseBuilder currentResponseBuilder = Response.status(status);
       
        for (Map.Entry<String, List<String>> entry : conn.getHeaderFields().entrySet()) {
            if (null == entry.getKey()) {
                continue;
            }
            if (entry.getValue().size() > 0) {
                if (HttpUtils.isDateRelatedHeader(entry.getKey())) {
                    currentResponseBuilder.header(entry.getKey(), entry.getValue().get(0));
                    continue;                   
                }
                boolean splitPossible = !(HttpHeaders.SET_COOKIE.equalsIgnoreCase(entry.getKey())
                                          && entry.getValue().get(0).contains(HttpHeaders.EXPIRES));
                for (String val : entry.getValue()) {
                    String[] values = splitPossible ? val.split(",") : new String[]{val};
                    for (String s : values) {
                        String theValue = s.trim();
                        if (theValue.length() > 0) {
                            currentResponseBuilder.header(entry.getKey(), theValue);
                        }
                    }
                }
            }
        }
        InputStream mStream = null;
        if (inMessage != null) {
            mStream = inMessage.getContent(InputStream.class);
        }
        if (status >= 400) {
            try {
                InputStream errorStream = mStream == null ? conn.getErrorStream() : mStream;
                currentResponseBuilder.entity(errorStream);
            } catch (Exception ex) {
                // nothing we can do really
            }
        } else {
            try {
                InputStream stream = mStream == null ? conn.getInputStream() : mStream;
                currentResponseBuilder.entity(stream);
            } catch (Exception ex) {
                // it may that the successful response has no response body
            }
        }
        ResponseBuilder rb = currentResponseBuilder.clone();
        state.setResponseBuilder(currentResponseBuilder);
        return rb;
    }
View Full Code Here

                                                   requestType.toString(),
                                                   convertTypesToString(acceptContentTypes));
        if (!"OPTIONS".equalsIgnoreCase(httpMethod) && logNow) {
            LOG.warning(errorMsg.toString());
        }
        ResponseBuilder rb = createResponseBuilder(resource, status, methodMatched == 0);
        throw new WebApplicationException(rb.build());
       
    }   
View Full Code Here

                                                   convertTypesToString(ori.getProduceTypes()));
        LOG.fine(errorMsg.toString());
    }

    public static ResponseBuilder createResponseBuilder(ClassResourceInfo cri, int status, boolean addAllow) {
        ResponseBuilder rb = Response.status(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");
            }
        }
        return rb;
    }
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.