use of org.apache.stanbol.commons.web.viewable.Viewable in project stanbol by apache.
the class SiteManagerRootResource method getSitesPage.
@GET
@Produces(MediaType.TEXT_HTML)
public Response getSitesPage(@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();
}
use of org.apache.stanbol.commons.web.viewable.Viewable in project stanbol by apache.
the class SiteManagerRootResource method getEntityById.
/**
* Cool URI handler for Signs.
*
* @param id
* The id of the entity (required)
* @param headers
* the request headers used to get the requested {@link MediaType}
* @return a redirection to either a browser view, the RDF meta data or the raw binary content
*/
@GET
@Path("/entity")
public Response getEntityById(@QueryParam(value = "id") String id, @Context HttpHeaders headers) {
log.debug("getSignById() request\n\t> id : {}\n\t> accept : {}\n\t> mediaType: {}", new Object[] { id, headers.getAcceptableMediaTypes(), headers.getMediaType() });
Collection<String> supported = new HashSet<String>(JerseyUtils.ENTITY_SUPPORTED_MEDIA_TYPES);
supported.add(TEXT_HTML);
final MediaType acceptedMediaType = getAcceptableMediaType(headers, supported, MediaType.APPLICATION_JSON_TYPE);
if (id == null || id.isEmpty()) {
if (MediaType.TEXT_HTML_TYPE.isCompatible(acceptedMediaType)) {
ResponseBuilder rb = Response.ok(new Viewable("entity", this));
rb.header(HttpHeaders.CONTENT_TYPE, TEXT_HTML + "; charset=utf-8");
//addCORSOrigin(servletContext, rb, headers);
return rb.build();
} else {
return Response.status(Status.BAD_REQUEST).entity("No or empty ID was parsed. Missing parameter id.\n").header(HttpHeaders.ACCEPT, acceptedMediaType).build();
}
}
Entity sign = referencedSiteManager.getEntity(id);
if (sign != null) {
ResponseBuilder rb = Response.ok(sign);
rb.header(HttpHeaders.CONTENT_TYPE, acceptedMediaType + "; charset=utf-8");
//addCORSOrigin(servletContext, rb, headers);
return rb.build();
} else {
// TODO: How to parse an ErrorMessage?
// create an Response with the the Error?
log.info("getSignById() entity {} not found on any referenced site");
return Response.status(Status.NOT_FOUND).entity("Entity with ID '" + id + "' not found an any referenced site\n").header(HttpHeaders.ACCEPT, acceptedMediaType).build();
}
}
use of org.apache.stanbol.commons.web.viewable.Viewable 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();
}
use of org.apache.stanbol.commons.web.viewable.Viewable 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();
}
}
use of org.apache.stanbol.commons.web.viewable.Viewable 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();
}
}
Aggregations