Search in sources :

Example 76 with ResponseBuilder

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

the class SiteManagerRootResource method executeQuery.

/**
     * Executes the query parsed by {@link #queryEntities(String, File, HttpHeaders)} or created based
     * {@link #findEntity(String, String, String, int, int, HttpHeaders)}
     * 
     * @param manager The {@link SiteManager}
     * @param query
     *            The query to execute
     * @param headers the request headers
     * @return the response (results of error)
     */
private Response executeQuery(SiteManager manager, FieldQuery query, MediaType mediaType, HttpHeaders headers) throws WebApplicationException {
    if (query instanceof LDPathSelect && ((LDPathSelect) query).getLDPathSelect() != null) {
        //use the LDPath variant to process this query
        return executeLDPathQuery(manager, query, ((LDPathSelect) query).getLDPathSelect(), mediaType, headers);
    } else {
        //use the default query execution
        QueryResultList<Representation> result = manager.find(query);
        ResponseBuilder rb = Response.ok(result);
        rb.header(HttpHeaders.CONTENT_TYPE, mediaType + "; charset=utf-8");
        //addCORSOrigin(servletContext, rb, headers);
        return rb.build();
    }
}
Also used : Representation(org.apache.stanbol.entityhub.servicesapi.model.Representation) LDPathSelect(org.apache.stanbol.entityhub.ldpath.query.LDPathSelect) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder)

Example 77 with ResponseBuilder

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

the class BaseGoogleRefineReconcileResource method sendMetadata.

/**
     * Called on requests for the Metadata for the Reconciliation service
     * @param callback
     * @param header
     * @return
     * @throws JSONException
     */
protected Response sendMetadata(String siteId, String callback, HttpHeaders header) throws JSONException {
    //TODO: implement!!
    JSONObject jMetadata = new JSONObject();
    jMetadata.put("name", "Stanbol Entityhub: " + getSiteName(siteId));
    StringBuilder callbackString = new StringBuilder(callback);
    callbackString.append('(');
    callbackString.append(jMetadata.toString());
    callbackString.append(')');
    ResponseBuilder rb = Response.ok(callbackString.toString()).type(MediaType.APPLICATION_JSON_TYPE);
    //CorsHelper.addCORSOrigin(servletContext, rb, header);
    return rb.build();
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder)

Example 78 with ResponseBuilder

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

the class EntityhubRootResource method get.

@GET
@Produces(TEXT_HTML)
public Response get(@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)

Example 79 with ResponseBuilder

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

the class EntityhubRootResource method getMapping.

@GET
@Path("mapping")
@Produces({ APPLICATION_JSON, RDF_XML, N3, TURTLE, X_TURTLE, RDF_JSON, N_TRIPLE, TEXT_HTML })
public Response getMapping(@QueryParam("id") String reference, @Context HttpHeaders headers) throws WebApplicationException {
    log.debug("get mapping for request > id : {} > accept: {}", reference, headers.getAcceptableMediaTypes());
    Set<String> supported = new HashSet<String>(JerseyUtils.REPRESENTATION_SUPPORTED_MEDIA_TYPES);
    supported.add(TEXT_HTML);
    MediaType acceptedMediaType = getAcceptableMediaType(headers, supported, APPLICATION_JSON_TYPE);
    if (reference == null || reference.isEmpty()) {
        //if HTML -> print the docu of the restfull service
        if (TEXT_HTML_TYPE.isCompatible(acceptedMediaType)) {
            ResponseBuilder rb = Response.ok(new Viewable("mapping", this));
            rb.header(HttpHeaders.CONTENT_TYPE, TEXT_HTML + "; charset=utf-8");
        //addCORSOrigin(servletContext, rb, headers);
        } else {
            return Response.status(Status.BAD_REQUEST).entity("The mapping id (URI) is missing.\n").header(HttpHeaders.ACCEPT, acceptedMediaType).build();
        }
    }
    //Entityhub entityhub = ContextHelper.getServiceFromContext(Entityhub.class, servletContext);
    Entity mapping;
    try {
        mapping = entityhub.getMappingById(reference);
    } catch (EntityhubException e) {
        log.error("error while getting the mapping for {}", reference, e);
        return Response.status(Status.INTERNAL_SERVER_ERROR).build();
    }
    if (mapping == null) {
        return Response.status(Status.NOT_FOUND).entity("No mapping found for '" + reference + "'.\n").header(HttpHeaders.ACCEPT, acceptedMediaType).build();
    } else {
        ResponseBuilder rb = Response.ok(mapping);
        rb.header(HttpHeaders.CONTENT_TYPE, acceptedMediaType + "; charset=utf-8");
        //addCORSOrigin(servletContext, rb, headers);
        return rb.build();
    }
}
Also used : Entity(org.apache.stanbol.entityhub.servicesapi.model.Entity) Viewable(org.apache.stanbol.commons.web.viewable.Viewable) MediaType(javax.ws.rs.core.MediaType) MediaTypeUtil.getAcceptableMediaType(org.apache.stanbol.commons.web.base.utils.MediaTypeUtil.getAcceptableMediaType) EntityhubException(org.apache.stanbol.entityhub.servicesapi.EntityhubException) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) HashSet(java.util.HashSet) Path(javax.ws.rs.Path) EntityhubLDPath(org.apache.stanbol.entityhub.ldpath.EntityhubLDPath) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 80 with ResponseBuilder

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

the class EntityhubRootResource method getEntityMapping.

@GET
@Path("mapping/entity")
@Produces({ APPLICATION_JSON, RDF_XML, N3, TURTLE, X_TURTLE, RDF_JSON, N_TRIPLE, TEXT_HTML })
public Response getEntityMapping(@QueryParam("id") String entity, @Context HttpHeaders headers) throws WebApplicationException {
    log.debug("getEntityMapping() POST Request > entity: {} > accept: {}", entity, headers.getAcceptableMediaTypes());
    Set<String> supported = new HashSet<String>(JerseyUtils.REPRESENTATION_SUPPORTED_MEDIA_TYPES);
    supported.add(TEXT_HTML);
    MediaType acceptedMediaType = getAcceptableMediaType(headers, supported, APPLICATION_JSON_TYPE);
    if (entity == null || entity.isEmpty()) {
        //if HTML -> print the docu of the restfull service
        if (TEXT_HTML_TYPE.isCompatible(acceptedMediaType)) {
            ResponseBuilder rb = Response.ok(new Viewable("mapping_entity", this));
            rb.header(HttpHeaders.CONTENT_TYPE, TEXT_HTML + "; charset=utf-8");
        //addCORSOrigin(servletContext, rb, headers);
        } else {
            return Response.status(Status.BAD_REQUEST).entity("No entity given. Missing parameter id.\n").header(HttpHeaders.ACCEPT, acceptedMediaType).build();
        }
    }
    //Entityhub entityhub = ContextHelper.getServiceFromContext(Entityhub.class, servletContext);
    Entity mapping;
    try {
        mapping = entityhub.getMappingBySource(entity);
    } catch (EntityhubException e) {
        throw new WebApplicationException(e, INTERNAL_SERVER_ERROR);
    }
    if (mapping == null) {
        return Response.status(Status.NOT_FOUND).entity("No mapping found for entity '" + entity + "'.\n").header(HttpHeaders.ACCEPT, acceptedMediaType).build();
    } else {
        ResponseBuilder rb = Response.ok(mapping);
        rb.header(HttpHeaders.CONTENT_TYPE, acceptedMediaType + "; charset=utf-8");
        //addCORSOrigin(servletContext, rb, headers);
        return rb.build();
    }
}
Also used : Entity(org.apache.stanbol.entityhub.servicesapi.model.Entity) WebApplicationException(javax.ws.rs.WebApplicationException) Viewable(org.apache.stanbol.commons.web.viewable.Viewable) MediaType(javax.ws.rs.core.MediaType) MediaTypeUtil.getAcceptableMediaType(org.apache.stanbol.commons.web.base.utils.MediaTypeUtil.getAcceptableMediaType) EntityhubException(org.apache.stanbol.entityhub.servicesapi.EntityhubException) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) HashSet(java.util.HashSet) Path(javax.ws.rs.Path) EntityhubLDPath(org.apache.stanbol.entityhub.ldpath.EntityhubLDPath) 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