Search in sources :

Example 36 with ResponseBuilder

use of javax.ws.rs.core.Response.ResponseBuilder in project stanbol by apache.

the class ReasoningServicesResource method getDocumentation.

@GET
@Produces(TEXT_HTML)
public Response getDocumentation(@Context HttpHeaders headers) {
    ResponseBuilder rb = Response.ok(new Viewable("index", this));
    rb.header(HttpHeaders.CONTENT_TYPE, TEXT_HTML + "; charset=utf-8");
    return rb.build();
}
Also used : Viewable(org.apache.stanbol.commons.web.viewable.Viewable) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 37 with ResponseBuilder

use of javax.ws.rs.core.Response.ResponseBuilder in project stanbol by apache.

the class ResponseTaskBuilder method build.

/**
     * Process the given object (result content output),
     * returning an HTML representation or delegating the rendering to jersey writers.
     * 
     * @param object
     * @return
     */
private Response build(Object object) {
    if (isHTML()) {
        OutputStream out = stream(object);
        this.result.setResult(out);
        ResponseBuilder rb = Response.ok(new Viewable("result", result));
        rb.header(HttpHeaders.CONTENT_TYPE, TEXT_HTML + "; charset=utf-8");
        //            addCORSOrigin(context, rb, headers);
        return rb.build();
    /*    return Response.ok(
                    new Viewable("result",
                            new ReasoningPrettyResultResource(
                                    context, info, out)),
                    TEXT_HTML).build();*/
    } else {
        //return Response.ok(object).build();
        ResponseBuilder rb = Response.ok(object);
        //            addCORSOrigin(context, rb, headers);
        return rb.build();
    }
}
Also used : OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Viewable(org.apache.stanbol.commons.web.viewable.Viewable) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder)

Example 38 with ResponseBuilder

use of javax.ws.rs.core.Response.ResponseBuilder in project stanbol by apache.

the class ScopeResource method getCoreSpaceOWL.

@GET
@Path("/core")
@Produces(value = { RDF_XML, TURTLE, X_TURTLE, MANCHESTER_OWL, FUNCTIONAL_OWL, OWL_XML, TEXT_PLAIN })
public Response getCoreSpaceOWL(@PathParam("scopeid") String scopeid, @DefaultValue("false") @QueryParam("merge") boolean merge, @Context UriInfo uriInfo, @Context HttpHeaders headers) {
    scope = onm.getScope(scopeid);
    OntologySpace space = scope.getCoreSpace();
    IRI prefix = IRI.create(getPublicBaseUri() + "ontonet/ontology/");
    OWLOntology o = space.export(OWLOntology.class, merge, prefix);
    ResponseBuilder rb = Response.ok(o);
    // addCORSOrigin(servletContext, rb, headers);
    return rb.build();
}
Also used : IRI(org.semanticweb.owlapi.model.IRI) OntologySpace(org.apache.stanbol.ontologymanager.servicesapi.scope.OntologySpace) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 39 with ResponseBuilder

use of javax.ws.rs.core.Response.ResponseBuilder in project stanbol by apache.

the class ScopeResource method manageOntology.

/**
     * Tells the scope that it should manage the ontology obtained by parsing the supplied content.<br>
     * <br>
     * Note that the PUT method cannot be used, as it is not possible to predict what ID the ontology will
     * have until it is parsed.
     * 
     * @param content
     *            the ontology content
     * @return {@link Status#OK} if the addition was successful, {@link Status#NOT_FOUND} if there is no such
     *         session at all, {@link Status#FORBIDDEN} if the session is locked or cannot modified for some
     *         other reason, {@link Status#INTERNAL_SERVER_ERROR} if some other error occurs.
     */
@POST
@Consumes(value = { RDF_XML, OWL_XML, N_TRIPLE, N3, TURTLE, X_TURTLE, FUNCTIONAL_OWL, MANCHESTER_OWL, RDF_JSON })
public Response manageOntology(InputStream content, @PathParam("scopeid") String scopeid, @Context HttpHeaders headers) {
    long before = System.currentTimeMillis();
    ResponseBuilder rb;
    scope = onm.getScope(scopeid);
    if (// Always check session first
    scope == null)
        // Always check session first
        rb = Response.status(NOT_FOUND);
    else
        try {
            MediaType mt = headers.getMediaType();
            log.debug("POST content claimed to be of type {}.", mt);
            OWLOntologyID key = scope.getCustomSpace().addOntology(/*
             * For the time being, REST services operate in-memory (i.e. no TcProvider is supplied to the
             * input source). This means that only the final processed graph is stored.
             * 
             * TODO : we might find a reason to change that in the future.
             */
            new GraphContentInputSource(content, mt.toString(), ontologyProvider.getStore()));
            if (key == null || key.isAnonymous()) {
                log.error("FAILED parse with media type {}.", mt);
                throw new WebApplicationException(INTERNAL_SERVER_ERROR);
            }
            // FIXME ugly but will have to do for the time being
            log.debug("SUCCESS parse with media type {}.", mt);
            // key.split("::")[1];
            String uri = OntologyUtils.encode(key);
            // uri = uri.substring((ontologyProvider.getGraphPrefix() + "::").length());
            URI created = null;
            if (uri != null && !uri.isEmpty()) {
                created = getCreatedResource(uri);
                rb = Response.created(created);
            } else
                rb = Response.ok();
            log.info("POST request for ontology addition completed in {} ms.", (System.currentTimeMillis() - before));
            log.info("New resource URL is {}", created);
        } catch (UnmodifiableOntologyCollectorException e) {
            throw new WebApplicationException(e, FORBIDDEN);
        }
    // addCORSOrigin(servletContext, rb, headers);
    return rb.build();
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) UnmodifiableOntologyCollectorException(org.apache.stanbol.ontologymanager.servicesapi.collector.UnmodifiableOntologyCollectorException) GraphContentInputSource(org.apache.stanbol.ontologymanager.sources.clerezza.GraphContentInputSource) OWLOntologyID(org.semanticweb.owlapi.model.OWLOntologyID) MediaType(javax.ws.rs.core.MediaType) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) URI(java.net.URI) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes)

Example 40 with ResponseBuilder

use of javax.ws.rs.core.Response.ResponseBuilder in project stanbol by apache.

the class SessionManagerResource method getHtmlInfo.

@GET
@Produces(TEXT_HTML)
public Response getHtmlInfo(@Context HttpHeaders headers) {
    ResponseBuilder rb = Response.ok(new Viewable("index", this));
    rb.header(HttpHeaders.CONTENT_TYPE, TEXT_HTML + "; charset=utf-8");
    //        addCORSOrigin(servletContext, rb, headers);
    return rb.build();
}
Also used : Viewable(org.apache.stanbol.commons.web.viewable.Viewable) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)175 GET (javax.ws.rs.GET)84 Produces (javax.ws.rs.Produces)81 Path (javax.ws.rs.Path)69 WebApplicationException (javax.ws.rs.WebApplicationException)47 Viewable (org.apache.stanbol.commons.web.viewable.Viewable)40 IOException (java.io.IOException)30 MediaType (javax.ws.rs.core.MediaType)29 POST (javax.ws.rs.POST)23 IRI (org.semanticweb.owlapi.model.IRI)22 EntityhubLDPath (org.apache.stanbol.entityhub.ldpath.EntityhubLDPath)21 Response (javax.ws.rs.core.Response)20 MediaTypeUtil.getAcceptableMediaType (org.apache.stanbol.commons.web.base.utils.MediaTypeUtil.getAcceptableMediaType)19 URI (java.net.URI)18 Consumes (javax.ws.rs.Consumes)18 OWLOntology (org.semanticweb.owlapi.model.OWLOntology)18 ByteArrayInputStream (java.io.ByteArrayInputStream)16 OWLOntologyID (org.semanticweb.owlapi.model.OWLOntologyID)16 HashSet (java.util.HashSet)14 ImmutableGraph (org.apache.clerezza.commons.rdf.ImmutableGraph)12