use of org.apache.stanbol.commons.web.viewable.Viewable in project stanbol by apache.
the class SparqlEndpointResource method sparql.
//TODO re-enable
/*@OPTIONS
public Response handleCorsPreflight(@Context HttpHeaders headers) {
ResponseBuilder res = Response.ok();
enableCORS(servletContext, res, headers);
return res.build();
}*/
/**
* HTTP GET service to execute SPARQL queries on {@link Graph}s registered to OSGi environment.
* If a <code>null</code>, it is assumed that the request is coming from the HTML interface of SPARQL
* endpoint. Otherwise the query is executed on the triple collection specified by <code>graphUri</code>.
* But, if no graph uri is passed, then the triple collection having highest service.ranking value is
* chosen.
*
* Type of the result is determined according to type of the query such that if the specified query is
* either a <b>describe query</b> or <b>construct query</b>, results are returned in
* <b>application/rdf+xml</b> format, otherwise in <b>pplication/sparql-results+xml</b> format.
*
* @param graphUri
* the URI of the graph on which the SPARQL query will be executed.
* @param sparqlQuery
* SPARQL query to be executed
* @param headers
* HTTP request Headers
* @throws InvalidSyntaxException Invalid SPARQL Syntax Exception
* @return Http Response
*/
@GET
@Consumes(APPLICATION_FORM_URLENCODED)
@Produces({ TEXT_HTML + ";qs=2", "application/sparql-results+xml", "application/rdf+xml" })
public Response sparql(@QueryParam(value = "graphuri") String graphUri, @QueryParam(value = "query") String sparqlQuery, @Context HttpHeaders headers) throws InvalidSyntaxException {
if (sparqlQuery == null) {
populateGraphList(getServices(null));
return Response.ok(new Viewable("index", this), TEXT_HTML).build();
}
String mediaType = "application/sparql-results+xml";
Graph tripleCollection = getGraph(graphUri);
ResponseBuilder rb;
if (tripleCollection != null) {
Object result;
try {
result = tcManager.executeSparqlQuery(sparqlQuery, tripleCollection);
if (result instanceof Graph) {
mediaType = "application/rdf+xml";
}
rb = Response.ok(result, mediaType);
} catch (ParseException e) {
rb = Response.status(Status.BAD_REQUEST).entity(e.getMessage());
}
} else {
rb = Response.status(Status.NOT_FOUND).entity(String.format("There is no registered graph with given uri: %s", graphUri));
}
//addCORSOrigin(servletContext, rb, headers);
return rb.build();
}
use of org.apache.stanbol.commons.web.viewable.Viewable in project stanbol by apache.
the class JobsResource method get.
/**
* To read a /reasoners job output.
*
* @param id
* @return
*/
@GET
@Path("/{jid}")
public Response get(@PathParam("jid") String id, @Context HttpHeaders headers) {
log.info("Pinging job {}", id);
// No id
if (id == null || id.equals("")) {
ResponseBuilder rb = Response.status(Status.BAD_REQUEST);
return rb.build();
}
JobManager m = getJobManager();
// If the job exists
if (m.hasJob(id)) {
log.info("Found job with id {}", id);
Future<?> f = m.ping(id);
if (f.isDone() && (!f.isCancelled())) {
/**
* We return OK with the result
*/
Object o;
try {
o = f.get();
if (o instanceof ReasoningServiceResult) {
log.debug("Is a ReasoningServiceResult");
ReasoningServiceResult<?> result = (ReasoningServiceResult<?>) o;
return new ResponseTaskBuilder(new JobResultResource(uriInfo, headers)).build(result);
} else {
log.error("Job {} does not belong to reasoners", id);
throw new WebApplicationException(Response.Status.NOT_FOUND);
}
} catch (InterruptedException e) {
log.error("Error: ", e);
throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
} catch (ExecutionException e) {
log.error("Error: ", e);
throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
}
} else {
/**
* We return 404 with additional info
*/
String jobService = new StringBuilder().append(getPublicBaseUri()).append("jobs/").append(id).toString();
this.jobLocation = jobService;
Viewable viewable = new Viewable("404.ftl", this);
ResponseBuilder rb = Response.status(Status.NOT_FOUND);
rb.header(HttpHeaders.CONTENT_TYPE, MediaType.TEXT_HTML + "; charset=utf-8");
rb.entity(viewable);
return rb.build();
}
} else {
log.info("No job found with id {}", id);
ResponseBuilder rb = Response.status(Status.NOT_FOUND);
rb.header(HttpHeaders.CONTENT_TYPE, MediaType.TEXT_HTML + "; charset=utf-8");
return rb.build();
}
}
use of org.apache.stanbol.commons.web.viewable.Viewable in project stanbol by apache.
the class ReasoningServicesResource method getServiceDocumentation.
@GET
@Produces(TEXT_HTML)
@Path("{service}")
public Response getServiceDocumentation(@PathParam(value = "service") String serviceID, @Context HttpHeaders headers) {
try {
this.service = this.getServicesManager().get(serviceID);
} catch (UnboundReasoningServiceException e) {
log.info("Service {} is not bound", serviceID);
ResponseBuilder rb = Response.status(Status.NOT_FOUND);
rb.header(HttpHeaders.CONTENT_TYPE, TEXT_HTML + "; charset=utf-8");
return rb.build();
}
ResponseBuilder rb = Response.ok(new Viewable("service", this));
rb.header(HttpHeaders.CONTENT_TYPE, TEXT_HTML + "; charset=utf-8");
return rb.build();
}
use of org.apache.stanbol.commons.web.viewable.Viewable 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();
}
use of org.apache.stanbol.commons.web.viewable.Viewable 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();
}
}
Aggregations