Search in sources :

Example 1 with ReasoningServiceExecutor

use of org.apache.stanbol.reasoners.web.utils.ReasoningServiceExecutor in project stanbol by apache.

the class ReasoningServiceTaskResource method processBackgroundRequest.

/**
     * Process a background request. This service use the Stanbol Commons Jobs API to start a background job.
     * Returns 201 on success, with HTTP header Location pointing to the Job resource.
     * 
     * @return
     */
private Response processBackgroundRequest() {
    // If parameters is empty it's a bad request...
    if (this.parameters.isEmpty()) {
        log.error("Cannot start job without input parameters... sending BAD REQUEST");
        throw new WebApplicationException(Response.Status.BAD_REQUEST);
    }
    String target = getTarget();
    // Setup the input
    ReasoningServiceInputManager imngr = prepareInput();
    // The service executor
    ReasoningServiceExecutor executor = new ReasoningServiceExecutor(tcManager, imngr, getCurrentService(), getCurrentTask(), target, parameters);
    String jid = getJobManager().execute(executor);
    URI location = URI.create(getPublicBaseUri() + "jobs/" + jid);
    this.jobLocation = location.toString();
    /**
         * If everything went well, we return 201 Created We include the header Location: with the Job URL
         */
    Viewable view = new Viewable("created", this);
    return Response.created(location).entity(view).build();
}
Also used : ReasoningServiceExecutor(org.apache.stanbol.reasoners.web.utils.ReasoningServiceExecutor) ReasoningServiceInputManager(org.apache.stanbol.reasoners.servicesapi.ReasoningServiceInputManager) WebApplicationException(javax.ws.rs.WebApplicationException) Viewable(org.apache.stanbol.commons.web.viewable.Viewable) URI(java.net.URI)

Example 2 with ReasoningServiceExecutor

use of org.apache.stanbol.reasoners.web.utils.ReasoningServiceExecutor in project stanbol by apache.

the class ReasoningServiceTaskResource method processRealTimeRequest.

/**
     * Process a real-time operation. Returns 200 when the process is ready, 500 if some error occurs
     * 
     * @return
     */
private Response processRealTimeRequest() {
    // page
    if (this.parameters.isEmpty() && file == null) {
        log.debug("no parameters no input file, show default index page");
        // return Response.ok(new Viewable("index", this)).build();
        ResponseBuilder rb = Response.ok(new Viewable("index", this));
        rb.header(HttpHeaders.CONTENT_TYPE, TEXT_HTML + "; charset=utf-8");
        return rb.build();
    }
    try {
        String target = getTarget();
        // Setup the input
        ReasoningServiceInputManager imngr = prepareInput();
        // The service executor
        ReasoningServiceExecutor executor = new ReasoningServiceExecutor(tcManager, imngr, getCurrentService(), getCurrentTask(), target, parameters);
        ReasoningServiceResult<?> result = executor.call();
        return new ResponseTaskBuilder(new ReasoningTaskResult(uriInfo, headers)).build(result);
    } catch (Exception e) {
        if (e instanceof RuntimeException) {
            throw (RuntimeException) e;
        }
        throw new WebApplicationException(e, Response.Status.INTERNAL_SERVER_ERROR);
    }
}
Also used : ReasoningServiceExecutor(org.apache.stanbol.reasoners.web.utils.ReasoningServiceExecutor) ReasoningServiceInputManager(org.apache.stanbol.reasoners.servicesapi.ReasoningServiceInputManager) WebApplicationException(javax.ws.rs.WebApplicationException) Viewable(org.apache.stanbol.commons.web.viewable.Viewable) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) ResponseTaskBuilder(org.apache.stanbol.reasoners.web.utils.ResponseTaskBuilder) WebApplicationException(javax.ws.rs.WebApplicationException) UnboundReasoningServiceException(org.apache.stanbol.reasoners.servicesapi.UnboundReasoningServiceException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Aggregations

WebApplicationException (javax.ws.rs.WebApplicationException)2 Viewable (org.apache.stanbol.commons.web.viewable.Viewable)2 ReasoningServiceInputManager (org.apache.stanbol.reasoners.servicesapi.ReasoningServiceInputManager)2 ReasoningServiceExecutor (org.apache.stanbol.reasoners.web.utils.ReasoningServiceExecutor)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 URI (java.net.URI)1 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)1 UnboundReasoningServiceException (org.apache.stanbol.reasoners.servicesapi.UnboundReasoningServiceException)1 ResponseTaskBuilder (org.apache.stanbol.reasoners.web.utils.ResponseTaskBuilder)1