Java Code Examples for org.restlet.Response#setLocationRef()

The following examples show how to use org.restlet.Response#setLocationRef() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IsFinishedResponseProcessor.java    From container with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public void process(final Exchange exchange) throws Exception {

    IsFinishedResponseProcessor.LOG.debug("Processing IsFinished response....");

    final String requestID = exchange.getIn().getHeader(InvocationRoute.ID, String.class);

    IsFinishedResponseProcessor.LOG.debug("RequestID: {}", requestID);

    final Response response = exchange.getIn().getHeader(RestletConstants.RESTLET_RESPONSE, Response.class);

    if (exchange.getIn().getBody() instanceof Exception) {

        response.setStatus(Status.CLIENT_ERROR_NOT_FOUND);
        response.setEntity(exchange.getIn().getBody(String.class), MediaType.TEXT_ALL);
    } else {

        final Boolean isFinished = exchange.getIn().getBody(Boolean.class);

        if (isFinished) {
            IsFinishedResponseProcessor.LOG.debug("Invocation has finished, send location of result.");

            response.setStatus(Status.REDIRECTION_SEE_OTHER);
            response.setLocationRef(InvocationRoute.GET_RESULT_ENDPOINT.replace(InvocationRoute.ID_PLACEHODLER,
                requestID));
        } else {
            IsFinishedResponseProcessor.LOG.debug("Invocation has not finished yet.");

            final JSONObject obj = new JSONObject();
            obj.put("status", "PENDING");

            response.setStatus(Status.SUCCESS_OK);
            response.setEntity(obj.toJSONString(), MediaType.APPLICATION_JSON);
        }
        exchange.getOut().setBody(response);
    }
}
 
Example 2
Source File: IsFinishedResponseProcessor.java    From container with Apache License 2.0 5 votes vote down vote up
@Override
public void process(final Exchange exchange) throws Exception {

    IsFinishedResponseProcessor.LOG.debug("Processing IsFinished response....");

    final String requestID = exchange.getIn().getHeader(Route.ID, String.class);

    IsFinishedResponseProcessor.LOG.debug("RequestID: {}", requestID);

    final Response response = exchange.getIn().getHeader(RestletConstants.RESTLET_RESPONSE, Response.class);

    if (exchange.getIn().getBody() instanceof Exception) {

        response.setStatus(Status.CLIENT_ERROR_NOT_FOUND);
        response.setEntity(exchange.getIn().getBody(String.class), MediaType.TEXT_ALL);
    } else {

        final Boolean isFinished = exchange.getIn().getBody(Boolean.class);

        if (isFinished) {
            IsFinishedResponseProcessor.LOG.debug("Invocation has finished, send location of result.");

            response.setStatus(Status.REDIRECTION_SEE_OTHER);
            response.setLocationRef(Route.GET_RESULT_ENDPOINT.replace(Route.ID_PLACEHODLER, requestID));
        } else {
            IsFinishedResponseProcessor.LOG.debug("Invocation has not finished yet.");

            final JSONObject obj = new JSONObject();
            obj.put("status", "PENDING");

            response.setStatus(Status.SUCCESS_OK);
            response.setEntity(obj.toJSONString(), MediaType.APPLICATION_JSON);
        }
        exchange.getOut().setBody(response);
    }
}
 
Example 3
Source File: InvocationResponseProcessor.java    From container with Apache License 2.0 5 votes vote down vote up
@Override
public void process(final Exchange exchange) throws Exception {

    InvocationResponseProcessor.LOG.debug("Processing Invocation response....");

    final String requestID = exchange.getIn().getBody(String.class);

    InvocationResponseProcessor.LOG.debug("RequestID: {}", requestID);

    final Response response = exchange.getIn().getHeader(RestletConstants.RESTLET_RESPONSE, Response.class);
    response.setStatus(Status.SUCCESS_ACCEPTED);
    response.setLocationRef(Route.POLL_ENDPOINT.replace(Route.ID_PLACEHODLER, requestID));
    exchange.getOut().setBody(response);
}
 
Example 4
Source File: IsFinishedResponseProcessor.java    From container with Apache License 2.0 4 votes vote down vote up
@Override
public void process(final Exchange exchange) throws Exception {

    IsFinishedResponseProcessor.LOG.debug("Processing IsFinished response....");

    final String requestID = exchange.getIn().getHeader(Route.ID, String.class);

    IsFinishedResponseProcessor.LOG.debug("RequestID: {}", requestID);

    final Response response = exchange.getIn().getHeader(RestletConstants.RESTLET_RESPONSE, Response.class);

    if (exchange.getIn().getBody() instanceof Exception) {

        response.setStatus(Status.CLIENT_ERROR_NOT_FOUND);
        response.setEntity(exchange.getIn().getBody(String.class), MediaType.TEXT_ALL);
    } else {

        final Boolean isFinished = exchange.getIn().getBody(Boolean.class);

        if (isFinished) {
            IsFinishedResponseProcessor.LOG.debug("Invocation has finished, send location of result.");

            final String pollingURI = exchange.getIn().getHeader(Exchange.HTTP_URI, String.class);
            final String getResultURI =
                pollingURI + Route.GET_RESULT_ENDPOINT_SUFFIX.replace(Route.ID_PLACEHODLER, requestID);

            IsFinishedResponseProcessor.LOG.debug("GetResult URI: {}", getResultURI);

            response.setStatus(Status.REDIRECTION_SEE_OTHER);
            response.setLocationRef(getResultURI);
        } else {
            IsFinishedResponseProcessor.LOG.debug("Invocation has not finished yet.");

            final String acceptContentType = exchange.getIn().getHeader(Exchange.ACCEPT_CONTENT_TYPE, String.class);

            IsFinishedResponseProcessor.LOG.debug("AcceptContentType: {}", acceptContentType);

            if (acceptContentType.equals(MediaType.APPLICATION_JSON)) {

                final JSONObject obj = new JSONObject();
                obj.put("status", "PENDING");

                response.setStatus(Status.SUCCESS_OK);
                response.setEntity(obj.toJSONString(), MediaType.APPLICATION_JSON);
            } else if (acceptContentType.equals(MediaType.APPLICATION_XML)) {

                response.setStatus(Status.SUCCESS_OK);
                response.setEntity("<status>PENDING</status>", MediaType.APPLICATION_XML);
            } else {
                IsFinishedResponseProcessor.LOG.warn("The requested entity media type is not supported.");
                throw new ApplicationBusExternalException("The requested entity media type is not supported.",
                    Status.CLIENT_ERROR_UNSUPPORTED_MEDIA_TYPE.getCode());
            }
        }
        exchange.getOut().setBody(response);
    }
}
 
Example 5
Source File: InvocationResponseProcessor.java    From container with Apache License 2.0 4 votes vote down vote up
@Override
public void process(final Exchange exchange) throws Exception {

    InvocationResponseProcessor.LOG.debug("Processing Invocation response....");

    final String requestID = exchange.getIn().getBody(String.class);

    InvocationResponseProcessor.LOG.debug("RequestID: {}", requestID);

    final String invokeURI = exchange.getIn().getHeader(Exchange.HTTP_URI, String.class);
    final String pollingURI = invokeURI + Route.POLL_ENDPOINT_SUFFIX.replace(Route.ID_PLACEHODLER, requestID);

    InvocationResponseProcessor.LOG.debug("Polling URI: {}", pollingURI);

    final Response response = exchange.getIn().getHeader(RestletConstants.RESTLET_RESPONSE, Response.class);
    response.setStatus(Status.SUCCESS_ACCEPTED);
    response.setLocationRef(pollingURI);
    exchange.getOut().setBody(response);
}
 
Example 6
Source File: InvocationResponseProcessor.java    From container with Apache License 2.0 3 votes vote down vote up
@Override
public void process(final Exchange exchange) throws Exception {

    InvocationResponseProcessor.LOG.debug("Processing Invocation response....");

    final String requestID = exchange.getIn().getBody(String.class);

    InvocationResponseProcessor.LOG.debug("RequestID: {}", requestID);

    final Response response = exchange.getIn().getHeader(RestletConstants.RESTLET_RESPONSE, Response.class);
    response.setStatus(Status.SUCCESS_ACCEPTED);
    response.setLocationRef(InvocationRoute.POLL_ENDPOINT.replace(InvocationRoute.ID_PLACEHODLER, requestID));

    exchange.getOut().setBody(response);
}