You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stanbol.apache.org by en...@apache.org on 2013/09/10 11:59:24 UTC

svn commit: r1521416 - /stanbol/branches/commons-ng/ontologymanager/web/src/main/java/org/apache/stanbol/ontologymanager/web/resources/

Author: enridaga
Date: Tue Sep 10 09:59:23 2013
New Revision: 1521416

URL: http://svn.apache.org/r1521416
Log:
STANBOL-1152 Added scr component annotations to resources Moved path params to methods to have default public constructors Removed some unused method parameters Resources are alive on simple http lookup, template rendering looks ok 

Modified:
    stanbol/branches/commons-ng/ontologymanager/web/src/main/java/org/apache/stanbol/ontologymanager/web/resources/OntoNetRootResource.java
    stanbol/branches/commons-ng/ontologymanager/web/src/main/java/org/apache/stanbol/ontologymanager/web/resources/RegistryManagerResource.java
    stanbol/branches/commons-ng/ontologymanager/web/src/main/java/org/apache/stanbol/ontologymanager/web/resources/ScopeManagerResource.java
    stanbol/branches/commons-ng/ontologymanager/web/src/main/java/org/apache/stanbol/ontologymanager/web/resources/ScopeResource.java
    stanbol/branches/commons-ng/ontologymanager/web/src/main/java/org/apache/stanbol/ontologymanager/web/resources/SessionManagerResource.java
    stanbol/branches/commons-ng/ontologymanager/web/src/main/java/org/apache/stanbol/ontologymanager/web/resources/SessionResource.java

Modified: stanbol/branches/commons-ng/ontologymanager/web/src/main/java/org/apache/stanbol/ontologymanager/web/resources/OntoNetRootResource.java
URL: http://svn.apache.org/viewvc/stanbol/branches/commons-ng/ontologymanager/web/src/main/java/org/apache/stanbol/ontologymanager/web/resources/OntoNetRootResource.java?rev=1521416&r1=1521415&r2=1521416&view=diff
==============================================================================
--- stanbol/branches/commons-ng/ontologymanager/web/src/main/java/org/apache/stanbol/ontologymanager/web/resources/OntoNetRootResource.java (original)
+++ stanbol/branches/commons-ng/ontologymanager/web/src/main/java/org/apache/stanbol/ontologymanager/web/resources/OntoNetRootResource.java Tue Sep 10 09:59:23 2013
@@ -61,7 +61,6 @@ import java.util.Set;
 import java.util.SortedSet;
 import java.util.TreeSet;
 
-import javax.servlet.ServletContext;
 import javax.ws.rs.Consumes;
 import javax.ws.rs.DELETE;
 import javax.ws.rs.DefaultValue;
@@ -91,7 +90,10 @@ import org.apache.clerezza.rdf.core.impl
 import org.apache.clerezza.rdf.core.serializedform.Parser;
 import org.apache.clerezza.rdf.core.serializedform.UnsupportedFormatException;
 import org.apache.clerezza.rdf.ontologies.OWL;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Property;
 import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.Service;
 import org.apache.stanbol.commons.owl.util.OWL2Constants;
 import org.apache.stanbol.commons.owl.util.OWLUtils;
 import org.apache.stanbol.commons.owl.util.URIUtils;
@@ -142,6 +144,9 @@ import java.security.PrivilegedAction;
  * @author anuzzolese, alexdma
  *
  */
+@Component
+@Service(Object.class)
+@Property(name="javax.ws.rs", boolValue=true)
 @Path("/ontonet")
 @ImplicitProduces(MediaType.TEXT_HTML + ";qs=2")
 public class OntoNetRootResource extends AbstractOntologyAccessResource {

Modified: stanbol/branches/commons-ng/ontologymanager/web/src/main/java/org/apache/stanbol/ontologymanager/web/resources/RegistryManagerResource.java
URL: http://svn.apache.org/viewvc/stanbol/branches/commons-ng/ontologymanager/web/src/main/java/org/apache/stanbol/ontologymanager/web/resources/RegistryManagerResource.java?rev=1521416&r1=1521415&r2=1521416&view=diff
==============================================================================
--- stanbol/branches/commons-ng/ontologymanager/web/src/main/java/org/apache/stanbol/ontologymanager/web/resources/RegistryManagerResource.java (original)
+++ stanbol/branches/commons-ng/ontologymanager/web/src/main/java/org/apache/stanbol/ontologymanager/web/resources/RegistryManagerResource.java Tue Sep 10 09:59:23 2013
@@ -34,7 +34,10 @@ import javax.ws.rs.core.Response;
 import javax.ws.rs.core.Response.ResponseBuilder;
 import javax.ws.rs.core.UriInfo;
 
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Property;
 import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.Service;
 import org.apache.stanbol.commons.web.viewable.Viewable;
 //import org.apache.stanbol.commons.web.base.ContextHelper;
 import org.apache.stanbol.commons.web.base.resource.BaseStanbolResource;
@@ -44,6 +47,9 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 
+@Component
+@Service(Object.class)
+@Property(name="javax.ws.rs", boolValue=true)
 @Path("/ontonet/registry")
 public class RegistryManagerResource extends BaseStanbolResource {
 
@@ -51,11 +57,8 @@ public class RegistryManagerResource ext
     @Reference
     protected RegistryManager regMgr;
 
-    // bind the registry manager by looking it up from the servlet request context
-    public RegistryManagerResource( @Context UriInfo uriInfo) {
+    public RegistryManagerResource() {
         super();
-//        regMgr = ContextHelper.getServiceFromContext(RegistryManager.class, context);
-        this.uriInfo = uriInfo;
     }
 
     @GET

Modified: stanbol/branches/commons-ng/ontologymanager/web/src/main/java/org/apache/stanbol/ontologymanager/web/resources/ScopeManagerResource.java
URL: http://svn.apache.org/viewvc/stanbol/branches/commons-ng/ontologymanager/web/src/main/java/org/apache/stanbol/ontologymanager/web/resources/ScopeManagerResource.java?rev=1521416&r1=1521415&r2=1521416&view=diff
==============================================================================
--- stanbol/branches/commons-ng/ontologymanager/web/src/main/java/org/apache/stanbol/ontologymanager/web/resources/ScopeManagerResource.java (original)
+++ stanbol/branches/commons-ng/ontologymanager/web/src/main/java/org/apache/stanbol/ontologymanager/web/resources/ScopeManagerResource.java Tue Sep 10 09:59:23 2013
@@ -47,7 +47,10 @@ import javax.ws.rs.core.Response;
 import javax.ws.rs.core.Response.ResponseBuilder;
 
 import org.apache.clerezza.rdf.core.access.TcManager;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Property;
 import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.Service;
 import org.apache.stanbol.commons.web.viewable.Viewable;
 //import org.apache.stanbol.commons.web.base.ContextHelper;
 import org.apache.stanbol.commons.web.base.resource.BaseStanbolResource;
@@ -70,6 +73,9 @@ import org.slf4j.LoggerFactory;
  * @author alexdma
  * 
  */
+@Component
+@Service(Object.class)
+@Property(name="javax.ws.rs", boolValue=true)
 @Path("/ontonet/ontology")
 public class ScopeManagerResource extends BaseStanbolResource {
 
@@ -84,10 +90,7 @@ public class ScopeManagerResource extend
     @Reference
     protected TcManager tcManager;
 
-    public ScopeManagerResource(@Context ServletContext servletContext) {
-//        this.servletContext = servletContext;
-//        this.onm = (ScopeManager) ContextHelper.getServiceFromContext(ScopeManager.class, servletContext);
-//        this.tcManager = (TcManager) ContextHelper.getServiceFromContext(TcManager.class, servletContext);
+    public ScopeManagerResource() {
     }
 
     /**

Modified: stanbol/branches/commons-ng/ontologymanager/web/src/main/java/org/apache/stanbol/ontologymanager/web/resources/ScopeResource.java
URL: http://svn.apache.org/viewvc/stanbol/branches/commons-ng/ontologymanager/web/src/main/java/org/apache/stanbol/ontologymanager/web/resources/ScopeResource.java?rev=1521416&r1=1521415&r2=1521416&view=diff
==============================================================================
--- stanbol/branches/commons-ng/ontologymanager/web/src/main/java/org/apache/stanbol/ontologymanager/web/resources/ScopeResource.java (original)
+++ stanbol/branches/commons-ng/ontologymanager/web/src/main/java/org/apache/stanbol/ontologymanager/web/resources/ScopeResource.java Tue Sep 10 09:59:23 2013
@@ -85,7 +85,10 @@ import org.apache.clerezza.rdf.core.Trip
 import org.apache.clerezza.rdf.core.access.TcProvider;
 import org.apache.clerezza.rdf.core.serializedform.Parser;
 import org.apache.clerezza.rdf.core.serializedform.UnsupportedFormatException;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Property;
 import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.Service;
 import org.apache.stanbol.commons.owl.util.OWLUtils;
 import org.apache.stanbol.commons.owl.util.URIUtils;
 import org.apache.stanbol.commons.web.viewable.Viewable;
@@ -130,6 +133,9 @@ import com.sun.jersey.multipart.FormData
  * @author alexdma
  * 
  */
+@Component
+@Service(Object.class)
+@Property(name="javax.ws.rs", boolValue=true)
 @Path("/ontonet/ontology/{scopeid}")
 public class ScopeResource extends AbstractOntologyAccessResource {
 
@@ -151,9 +157,10 @@ public class ScopeResource extends Abstr
 
     protected Scope scope;
 
-    public ScopeResource(@PathParam(value = "scopeid") String scopeId, @Context ServletContext servletContext) {
+    
+    public ScopeResource() {
         super();
-        log.info("<init> with scope {}", scopeId);
+//        log.info("<init> with scope {}", scopeId);
 //
 //        this.servletContext = servletContext;
 //        this.onm = (ScopeManager) ContextHelper.getServiceFromContext(ScopeManager.class, servletContext);
@@ -162,11 +169,11 @@ public class ScopeResource extends Abstr
 //        this.ontologyProvider = (OntologyProvider<TcProvider>) ContextHelper.getServiceFromContext(
 //            OntologyProvider.class, servletContext);
 
-        if (scopeId == null || scopeId.isEmpty()) {
-            log.error("Missing path parameter scopeid={}", scopeId);
-            throw new WebApplicationException(NOT_FOUND);
-        }
-        scope = onm.getScope(scopeId);
+//        if (scopeId == null || scopeId.isEmpty()) {
+//            log.error("Missing path parameter scopeid={}", scopeId);
+//            throw new WebApplicationException(NOT_FOUND);
+//        }
+//        scope = onm.getScope(scopeId);
 
         // // Skip null checks: the scope might be created with a PUT
         // if (scope == null) {
@@ -180,6 +187,9 @@ public class ScopeResource extends Abstr
     public Response asOntologyGraph(@PathParam("scopeid") String scopeid,
                                     @DefaultValue("false") @QueryParam("merge") boolean merge,
                                     @Context HttpHeaders headers) {
+
+        scope = onm.getScope(scopeid);
+        
         if (scope == null) return Response.status(NOT_FOUND).build();
         IRI prefix = IRI.create(getPublicBaseUri() + "ontonet/ontology/");
         // Export to Clerezza Graph, which can be rendered as JSON-LD.
@@ -193,6 +203,8 @@ public class ScopeResource extends Abstr
     public Response asOntologyMixed(@PathParam("scopeid") String scopeid,
                                     @DefaultValue("false") @QueryParam("merge") boolean merge,
                                     @Context HttpHeaders headers) {
+        scope = onm.getScope(scopeid);
+        
         if (scope == null) return Response.status(NOT_FOUND).build();
         // Export smaller graphs to OWLOntology due to the more human-readable rendering.
         ResponseBuilder rb;
@@ -208,6 +220,8 @@ public class ScopeResource extends Abstr
     public Response asOntologyOWL(@PathParam("scopeid") String scopeid,
                                   @DefaultValue("false") @QueryParam("merge") boolean merge,
                                   @Context HttpHeaders headers) {
+        scope = onm.getScope(scopeid);
+        
         if (scope == null) return Response.status(NOT_FOUND).build();
         IRI prefix = IRI.create(getPublicBaseUri() + "ontonet/ontology/");
         // Export to OWLOntology due to the more human-readable rendering.
@@ -221,6 +235,8 @@ public class ScopeResource extends Abstr
                                     @Context UriInfo uriInfo,
                                     @Context HttpHeaders headers,
                                     @Context ServletContext servletContext) {
+        scope = onm.getScope(scopeid);
+        
         onm.deregisterScope(scope);
         scope = null;
         ResponseBuilder rb = Response.ok();
@@ -242,6 +258,8 @@ public class ScopeResource extends Abstr
                                       @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/");
         Graph o = space.export(Graph.class, merge, prefix);
@@ -257,6 +275,8 @@ public class ScopeResource extends Abstr
                                     @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);
@@ -283,6 +303,8 @@ public class ScopeResource extends Abstr
                                         @DefaultValue("false") @QueryParam("merge") boolean merge,
                                         @Context UriInfo uriInfo,
                                         @Context HttpHeaders headers) {
+        scope = onm.getScope(scopeid);
+        
         OntologySpace space = scope.getCustomSpace();
         IRI prefix = IRI.create(getPublicBaseUri() + "ontonet/ontology/");
         Graph o = space.export(Graph.class, merge, prefix);
@@ -298,6 +320,8 @@ public class ScopeResource extends Abstr
                                       @DefaultValue("false") @QueryParam("merge") boolean merge,
                                       @Context UriInfo uriInfo,
                                       @Context HttpHeaders headers) {
+        scope = onm.getScope(scopeid);
+        
         OntologySpace space = scope.getCustomSpace();
         IRI prefix = IRI.create(getPublicBaseUri() + "ontonet/ontology/");
         OWLOntology o = space.export(OWLOntology.class, merge, prefix);
@@ -308,8 +332,10 @@ public class ScopeResource extends Abstr
 
     @GET
     @Produces(TEXT_HTML)
-    public Response getHtmlInfo(@Context HttpHeaders headers) {
+    public Response getHtmlInfo(@PathParam("scopeid") String scopeid, @Context HttpHeaders headers) {
         ResponseBuilder rb;
+        scope = onm.getScope(scopeid);
+        
         if (scope == null) rb = Response.status(NOT_FOUND);
         else rb = Response.ok(new Viewable("index", this)); // TODO move to a dedicated class
         rb.header(HttpHeaders.CONTENT_TYPE, TEXT_HTML + "; charset=utf-8");
@@ -389,13 +415,16 @@ public class ScopeResource extends Abstr
     @GET
     @Path("/{ontologyId:.+}")
     @Produces(value = {APPLICATION_JSON, N3, N_TRIPLE, RDF_JSON})
-    public Response managedOntologyGetGraph(@PathParam("ontologyId") String ontologyId,
+    public Response managedOntologyGetGraph(@PathParam("scopeid") String scopeid,
+                                            @PathParam("ontologyId") String ontologyId,
                                             @DefaultValue("false") @QueryParam("merge") boolean merge,
                                             @Context UriInfo uriInfo,
                                             @Context HttpHeaders headers) {
         log.debug("Absolute URL Path {}", uriInfo.getRequestUri());
         log.debug("Ontology ID {}", ontologyId);
         ResponseBuilder rb;
+        scope = onm.getScope(scopeid);
+        
         if (scope == null) rb = Response.status(NOT_FOUND);
         else {
             IRI prefix = IRI.create(getPublicBaseUri() + "ontonet/ontology/");
@@ -431,13 +460,17 @@ public class ScopeResource extends Abstr
     @GET
     @Path("/{ontologyId:.+}")
     @Produces(value = {RDF_XML, TURTLE, X_TURTLE, MANCHESTER_OWL, FUNCTIONAL_OWL, OWL_XML, TEXT_PLAIN})
-    public Response managedOntologyGetOWL(@PathParam("ontologyId") String ontologyId,
+    public Response managedOntologyGetOWL(
+                                          @PathParam("scopeid") String scopeid,
+                                          @PathParam("ontologyId") String ontologyId,
                                           @DefaultValue("false") @QueryParam("merge") boolean merge,
                                           @Context UriInfo uriInfo,
                                           @Context HttpHeaders headers) {
         log.debug("Absolute URL Path {}", uriInfo.getRequestUri());
         log.debug("Ontology ID {}", ontologyId);
         ResponseBuilder rb;
+        scope = onm.getScope(scopeid);
+        
         if (scope == null) rb = Response.status(NOT_FOUND);
         else {
             IRI prefix = IRI.create(getPublicBaseUri() + "ontonet/ontology/");
@@ -461,9 +494,12 @@ public class ScopeResource extends Abstr
     @GET
     @Path("/{ontologyId:.+}")
     @Produces(TEXT_HTML)
-    public Response managedOntologyShow(@PathParam("ontologyId") String ontologyId,
+    public Response managedOntologyShow(@PathParam("scopeid") String scopeid,
+                                        @PathParam("ontologyId") String ontologyId,
                                         @Context HttpHeaders headers) {
         ResponseBuilder rb;
+
+        scope = onm.getScope(scopeid);
         if (scope == null) rb = Response.status(NOT_FOUND);
         else if (ontologyId == null || ontologyId.isEmpty()) rb = Response.status(BAD_REQUEST);
         else if (!ontologyProvider.hasOntology(OntologyUtils.decode(ontologyId))) rb = Response
@@ -499,11 +535,13 @@ public class ScopeResource extends Abstr
      */
     @DELETE
     @Path("/{ontologyId:.+}")
-    public Response managedOntologyUnload(@PathParam("ontologyId") String ontologyId,
+    public Response managedOntologyUnload(@PathParam("scopeid") String scopeid,
+                                          @PathParam("ontologyId") String ontologyId,
                                           @PathParam("scopeid") String scopeId,
                                           @Context UriInfo uriInfo,
                                           @Context HttpHeaders headers) {
         ResponseBuilder rb;
+        scope = onm.getScope(scopeid);
         if (ontologyId != null && !ontologyId.trim().isEmpty()) {
             OWLOntologyID id = OntologyUtils.decode(ontologyId);
             OntologySpace cs = scope.getCustomSpace();
@@ -541,9 +579,10 @@ public class ScopeResource extends Abstr
     @POST
     @Consumes(value = {RDF_XML, OWL_XML, N_TRIPLE, N3, TURTLE, X_TURTLE, FUNCTIONAL_OWL, MANCHESTER_OWL,
                        RDF_JSON})
-    public Response manageOntology(InputStream content, @Context HttpHeaders headers) {
+    public Response manageOntology(InputStream content,@PathParam("scopeid") String scopeid, @Context HttpHeaders headers) {
         long before = System.currentTimeMillis();
         ResponseBuilder rb;
+        scope = onm.getScope(scopeid);
         if (scope == null) rb = Response.status(NOT_FOUND); // Always check session first
         else try {
             MediaType mt = headers.getMediaType();
@@ -594,8 +633,9 @@ public class ScopeResource extends Abstr
      */
     @POST
     @Consumes(value = MediaType.TEXT_PLAIN)
-    public Response manageOntology(String iri, @Context HttpHeaders headers) {
+    public Response manageOntology(String iri,@PathParam("scopeid") String scopeid, @Context HttpHeaders headers) {
         ResponseBuilder rb;
+        scope = onm.getScope(scopeid);
         if (scope == null) rb = Response.status(NOT_FOUND);
         else try {
             OWLOntologyID key = scope.getCustomSpace().addOntology(new RootOntologySource(IRI.create(iri)));
@@ -613,9 +653,10 @@ public class ScopeResource extends Abstr
     @POST
     @Consumes({MULTIPART_FORM_DATA})
     @Produces({TEXT_HTML, TEXT_PLAIN, RDF_XML, TURTLE, X_TURTLE, N3})
-    public Response postOntology(FormDataMultiPart data, @Context HttpHeaders headers) {
+    public Response postOntology(FormDataMultiPart data, @PathParam("scopeid") String scopeid, @Context HttpHeaders headers) {
         log.debug(" post(FormDataMultiPart data)");
         ResponseBuilder rb;
+        scope = onm.getScope(scopeid);
 
         // TODO remove and make sure it is set across the method
         rb = Response.status(BAD_REQUEST);
@@ -763,10 +804,10 @@ public class ScopeResource extends Abstr
                                   @QueryParam("corereg") final List<String> coreRegistries,
                                   @QueryParam("coreont") final List<String> coreOntologies,
                                   @DefaultValue("false") @QueryParam("activate") boolean activate,
-                                  @Context UriInfo uriInfo,
-                                  @Context HttpHeaders headers,
-                                  @Context ServletContext servletContext) {
+                                  @Context HttpHeaders headers) {
         log.debug("Request URI {}", uriInfo.getRequestUri());
+
+        scope = onm.getScope(scopeid);
         List<OntologyInputSource<?>> srcs = new ArrayList<OntologyInputSource<?>>(coreOntologies.size()
                                                                                   + coreRegistries.size());
         // First thing, check registry sources.

Modified: stanbol/branches/commons-ng/ontologymanager/web/src/main/java/org/apache/stanbol/ontologymanager/web/resources/SessionManagerResource.java
URL: http://svn.apache.org/viewvc/stanbol/branches/commons-ng/ontologymanager/web/src/main/java/org/apache/stanbol/ontologymanager/web/resources/SessionManagerResource.java?rev=1521416&r1=1521415&r2=1521416&view=diff
==============================================================================
--- stanbol/branches/commons-ng/ontologymanager/web/src/main/java/org/apache/stanbol/ontologymanager/web/resources/SessionManagerResource.java (original)
+++ stanbol/branches/commons-ng/ontologymanager/web/src/main/java/org/apache/stanbol/ontologymanager/web/resources/SessionManagerResource.java Tue Sep 10 09:59:23 2013
@@ -50,7 +50,10 @@ import javax.ws.rs.core.Response;
 import javax.ws.rs.core.Response.ResponseBuilder;
 import javax.ws.rs.core.UriInfo;
 
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Property;
 import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.Service;
 import org.apache.stanbol.commons.web.viewable.Viewable;
 //import org.apache.stanbol.commons.web.base.ContextHelper;
 import org.apache.stanbol.commons.web.base.resource.BaseStanbolResource;
@@ -70,6 +73,9 @@ import org.semanticweb.owlapi.model.OWLO
 import org.semanticweb.owlapi.model.OWLOntologyManager;
 
 
+@Component
+@Service(Object.class)
+@Property(name="javax.ws.rs", boolValue=true)
 @Path("/ontonet/session")
 public class SessionManagerResource extends BaseStanbolResource {
 

Modified: stanbol/branches/commons-ng/ontologymanager/web/src/main/java/org/apache/stanbol/ontologymanager/web/resources/SessionResource.java
URL: http://svn.apache.org/viewvc/stanbol/branches/commons-ng/ontologymanager/web/src/main/java/org/apache/stanbol/ontologymanager/web/resources/SessionResource.java?rev=1521416&r1=1521415&r2=1521416&view=diff
==============================================================================
--- stanbol/branches/commons-ng/ontologymanager/web/src/main/java/org/apache/stanbol/ontologymanager/web/resources/SessionResource.java (original)
+++ stanbol/branches/commons-ng/ontologymanager/web/src/main/java/org/apache/stanbol/ontologymanager/web/resources/SessionResource.java Tue Sep 10 09:59:23 2013
@@ -79,7 +79,10 @@ import javax.ws.rs.core.UriInfo;
 import org.apache.clerezza.rdf.core.Graph;
 import org.apache.clerezza.rdf.core.access.TcProvider;
 import org.apache.clerezza.rdf.core.serializedform.Parser;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Property;
 import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.Service;
 import org.apache.stanbol.commons.owl.util.OWLUtils;
 //import org.apache.stanbol.commons.viewable.Viewable;
 import org.apache.stanbol.commons.web.viewable.Viewable;
@@ -125,6 +128,9 @@ import com.sun.jersey.multipart.FormData
  * @author alexdma
  * 
  */
+@Component
+@Service(Object.class)
+@Property(name="javax.ws.rs", boolValue=true)
 @Path("/ontonet/session/{id}")
 public class SessionResource extends AbstractOntologyAccessResource {
 
@@ -150,7 +156,7 @@ public class SessionResource extends Abs
 
     protected Session session;
 
-    public SessionResource(@PathParam(value = "id") String sessionId) {
+    public SessionResource() {
 //        public SessionResource(@PathParam(value = "id") String sessionId, @Context ServletContext servletContext) {
 //        this.servletContext = servletContext;
 //        this.sesMgr = (SessionManager) ContextHelper.getServiceFromContext(SessionManager.class,
@@ -160,14 +166,16 @@ public class SessionResource extends Abs
 //        this.ontologyProvider = (OntologyProvider<TcProvider>) ContextHelper.getServiceFromContext(
 //            OntologyProvider.class, servletContext);
 //        this.onMgr = (ScopeManager) ContextHelper.getServiceFromContext(ScopeManager.class, servletContext);
-        session = sesMgr.getSession(sessionId);
+        
     }
 
     @GET
     @Produces(value = {APPLICATION_JSON, N3, N_TRIPLE, RDF_JSON})
-    public Response asOntologyGraph(@PathParam("scopeid") String scopeid,
+    public Response asOntologyGraph(@PathParam(value = "id") String sessionId,
+                                    @PathParam("scopeid") String scopeid,
                                     @DefaultValue("false") @QueryParam("merge") boolean merge,
                                     @Context HttpHeaders headers) {
+        session = sesMgr.getSession(sessionId);
         if (session == null) return Response.status(NOT_FOUND).build();
         IRI prefix = IRI.create(getPublicBaseUri() + "ontonet/session/");
         // Export to Clerezza Graph, which can be rendered as JSON-LD.
@@ -178,9 +186,11 @@ public class SessionResource extends Abs
 
     @GET
     @Produces(value = {RDF_XML, TURTLE, X_TURTLE})
-    public Response asOntologyMixed(@PathParam("scopeid") String scopeid,
+    public Response asOntologyMixed(@PathParam(value = "id") String sessionId,
+                                    @PathParam("scopeid") String scopeid,
                                     @DefaultValue("false") @QueryParam("merge") boolean merge,
                                     @Context HttpHeaders headers) {
+        session = sesMgr.getSession(sessionId);
         if (session == null) return Response.status(NOT_FOUND).build();
         ResponseBuilder rb;
         IRI prefix = IRI.create(getPublicBaseUri() + "ontonet/session/");
@@ -193,9 +203,11 @@ public class SessionResource extends Abs
 
     @GET
     @Produces(value = {MANCHESTER_OWL, FUNCTIONAL_OWL, OWL_XML, TEXT_PLAIN})
-    public Response asOntologyOWL(@PathParam("scopeid") String scopeid,
+    public Response asOntologyOWL(@PathParam(value = "id") String sessionId,
+                                  @PathParam("scopeid") String scopeid,
                                   @DefaultValue("false") @QueryParam("merge") boolean merge,
                                   @Context HttpHeaders headers) {
+        session = sesMgr.getSession(sessionId);
         if (session == null) return Response.status(NOT_FOUND).build();
         IRI prefix = IRI.create(getPublicBaseUri() + "ontonet/session/");
         // Export to OWLOntology, the only to support OWL formats.
@@ -216,7 +228,7 @@ public class SessionResource extends Abs
      */
     @PUT
     public Response createSession(@PathParam("id") String sessionId,
-                                  @Context UriInfo uriInfo,
+//                                  @Context UriInfo uriInfo,
                                   @Context HttpHeaders headers) {
         try {
             session = sesMgr.createSession(sessionId);
@@ -242,8 +254,9 @@ public class SessionResource extends Abs
      */
     @DELETE
     public Response deleteSession(@PathParam("id") String sessionId,
-                                  @Context UriInfo uriInfo,
+//                                  @Context UriInfo uriInfo,
                                   @Context HttpHeaders headers) {
+        session = sesMgr.getSession(sessionId);
         if (session == null) return Response.status(NOT_FOUND).build();
         sesMgr.destroySession(sessionId);
         session = null;
@@ -254,8 +267,9 @@ public class SessionResource extends Abs
 
     @POST
     @Produces({WILDCARD})
-    public Response emptyPost(@Context HttpHeaders headers) {
+    public Response emptyPost(@PathParam("id") String sessionId, @Context HttpHeaders headers) {
         log.debug(" post(no data)");
+        session = sesMgr.getSession(sessionId);
         for (Scope sc : getAllScopes()) { // First remove appended scopes not in the list
             String scid = sc.getID();
             if (getAppendedScopes().contains(scid)) {
@@ -301,8 +315,10 @@ public class SessionResource extends Abs
 
     @GET
     @Produces(TEXT_HTML)
-    public Response getHtmlInfo(@Context HttpHeaders headers) {
+    public Response getHtmlInfo(@PathParam("id") String sessionId, @Context HttpHeaders headers) {
         ResponseBuilder rb;
+
+        session = sesMgr.getSession(sessionId);
         if (session == null) rb = Response.status(NOT_FOUND);
         else rb = Response.ok(new Viewable("index", this));
         rb.header(HttpHeaders.CONTENT_TYPE, TEXT_HTML + "; charset=utf-8");
@@ -366,8 +382,10 @@ public class SessionResource extends Abs
     public Response managedOntologyGetGraph(@PathParam("id") String sessionId,
                                             @PathParam("ontologyId") String ontologyId,
                                             @DefaultValue("false") @QueryParam("merge") boolean merge,
-                                            @Context UriInfo uriInfo,
+//                                            @Context UriInfo uriInfo,
                                             @Context HttpHeaders headers) {
+
+        session = sesMgr.getSession(sessionId);
         if (session == null) return Response.status(NOT_FOUND).build();
         IRI prefix = IRI.create(getPublicBaseUri() + "ontonet/session/");
         Graph o = session.getOntology(OntologyUtils.decode(ontologyId), Graph.class, merge, prefix);
@@ -394,9 +412,11 @@ public class SessionResource extends Abs
     public Response managedOntologyGetMixed(@PathParam("id") String sessionId,
                                             @PathParam("ontologyId") String ontologyId,
                                             @DefaultValue("false") @QueryParam("merge") boolean merge,
-                                            @Context UriInfo uriInfo,
+//                                            @Context UriInfo uriInfo,
                                             @Context HttpHeaders headers) {
         ResponseBuilder rb;
+
+        session = sesMgr.getSession(sessionId);
         if (session == null) rb = Response.status(NOT_FOUND);
         else {
             IRI prefix = IRI.create(getPublicBaseUri() + "ontonet/session/");
@@ -431,8 +451,10 @@ public class SessionResource extends Abs
     public Response managedOntologyGetOWL(@PathParam("id") String sessionId,
                                           @PathParam("ontologyId") String ontologyId,
                                           @DefaultValue("false") @QueryParam("merge") boolean merge,
-                                          @Context UriInfo uriInfo,
+//                                          @Context UriInfo uriInfo,
                                           @Context HttpHeaders headers) {
+
+        session = sesMgr.getSession(sessionId);
         if (session == null) return Response.status(NOT_FOUND).build();
         IRI prefix = IRI.create(getPublicBaseUri() + "ontonet/session/");
         OWLOntology o = session.getOntology(OntologyUtils.decode(ontologyId), OWLOntology.class, merge,
@@ -490,9 +512,10 @@ public class SessionResource extends Abs
     @Path(value = "/{ontologyId:.+}")
     public Response managedOntologyUnload(@PathParam("id") String sessionId,
                                           @PathParam("ontologyId") String ontologyId,
-                                          @Context UriInfo uriInfo,
+//                                          @Context UriInfo uriInfo,
                                           @Context HttpHeaders headers) {
         ResponseBuilder rb;
+        session = sesMgr.getSession(sessionId);
         if (session == null) rb = Response.status(NOT_FOUND);
         else {
             OWLOntologyID id = OntologyUtils.decode(ontologyId);
@@ -527,9 +550,11 @@ public class SessionResource extends Abs
     @POST
     @Consumes(value = {RDF_XML, OWL_XML, N_TRIPLE, N3, TURTLE, X_TURTLE, FUNCTIONAL_OWL, MANCHESTER_OWL,
                        RDF_JSON})
-    public Response manageOntology(InputStream content, @Context HttpHeaders headers) {
+    public Response manageOntology(InputStream content, @PathParam("id") String sessionId, @Context HttpHeaders headers) {
         long before = System.currentTimeMillis();
         ResponseBuilder rb;
+
+        session = sesMgr.getSession(sessionId);
         String mt = headers.getMediaType().toString();
         if (session == null) rb = Response.status(NOT_FOUND); // Always check session first
         else try {
@@ -583,7 +608,9 @@ public class SessionResource extends Abs
      */
     @POST
     @Consumes(value = MediaType.TEXT_PLAIN)
-    public Response manageOntology(String iri, @Context HttpHeaders headers) {
+    public Response manageOntology(String iri, @PathParam("id") String sessionId, @Context HttpHeaders headers) {
+
+        session = sesMgr.getSession(sessionId);
         if (session == null) return Response.status(NOT_FOUND).build();
         try {
             session.addOntology(new RootOntologySource(IRI.create(iri)));