You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stanbol.apache.org by al...@apache.org on 2012/07/04 17:16:05 UTC
svn commit: r1357301 - in
/incubator/stanbol/trunk/ontologymanager/web/src/main:
java/org/apache/stanbol/ontologymanager/web/resources/SessionManagerResource.java
resources/org/apache/stanbol/ontologymanager/web/templates/imports/inc_sessionmgr.ftl
Author: alexdma
Date: Wed Jul 4 15:16:04 2012
New Revision: 1357301
URL: http://svn.apache.org/viewvc?rev=1357301&view=rev
Log:
STANBOL-247 : added POST method on the /ontonet/session endpoint for creating a session without having to decide its ID. Updated some RESTful documentation as well.
Modified:
incubator/stanbol/trunk/ontologymanager/web/src/main/java/org/apache/stanbol/ontologymanager/web/resources/SessionManagerResource.java
incubator/stanbol/trunk/ontologymanager/web/src/main/resources/org/apache/stanbol/ontologymanager/web/templates/imports/inc_sessionmgr.ftl
Modified: incubator/stanbol/trunk/ontologymanager/web/src/main/java/org/apache/stanbol/ontologymanager/web/resources/SessionManagerResource.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/web/src/main/java/org/apache/stanbol/ontologymanager/web/resources/SessionManagerResource.java?rev=1357301&r1=1357300&r2=1357301&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/web/src/main/java/org/apache/stanbol/ontologymanager/web/resources/SessionManagerResource.java (original)
+++ incubator/stanbol/trunk/ontologymanager/web/src/main/java/org/apache/stanbol/ontologymanager/web/resources/SessionManagerResource.java Wed Jul 4 15:16:04 2012
@@ -18,6 +18,7 @@ package org.apache.stanbol.ontologymanag
import static javax.ws.rs.core.MediaType.TEXT_HTML;
import static javax.ws.rs.core.MediaType.TEXT_PLAIN;
+import static javax.ws.rs.core.Response.Status.FORBIDDEN;
import static javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR;
import static org.apache.stanbol.commons.web.base.CorsHelper.addCORSOrigin;
import static org.apache.stanbol.commons.web.base.format.KRFormat.FUNCTIONAL_OWL;
@@ -30,6 +31,7 @@ import static org.apache.stanbol.commons
import static org.apache.stanbol.commons.web.base.format.KRFormat.TURTLE;
import static org.apache.stanbol.commons.web.base.format.KRFormat.X_TURTLE;
+import java.net.URI;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
@@ -37,6 +39,7 @@ import java.util.Set;
import javax.servlet.ServletContext;
import javax.ws.rs.GET;
+import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.WebApplicationException;
@@ -51,6 +54,7 @@ import org.apache.stanbol.commons.web.ba
import org.apache.stanbol.commons.web.base.resource.BaseStanbolResource;
import org.apache.stanbol.commons.web.base.utils.MediaTypeUtil;
import org.apache.stanbol.ontologymanager.ontonet.api.session.Session;
+import org.apache.stanbol.ontologymanager.ontonet.api.session.SessionLimitException;
import org.apache.stanbol.ontologymanager.ontonet.api.session.SessionManager;
import org.semanticweb.owlapi.apibinding.OWLManager;
import org.semanticweb.owlapi.model.AddAxiom;
@@ -79,6 +83,23 @@ public class SessionManagerResource exte
servletContext);
}
+ @POST
+ public Response createSessionWithAutomaticId(@Context UriInfo uriInfo, @Context HttpHeaders headers) {
+ Session s;
+ try {
+ s = sessionManager.createSession();
+ } catch (SessionLimitException e) {
+ throw new WebApplicationException(e, FORBIDDEN);
+ }
+ String uri = uriInfo.getRequestUri().toString();
+ while (uri.endsWith("/"))
+ uri = uri.substring(0, uri.length() - 1);
+ uri += "/" + s.getID();
+ ResponseBuilder rb = Response.created(URI.create(uri));
+ addCORSOrigin(servletContext, rb, headers);
+ return rb.build();
+ }
+
@GET
@Produces(TEXT_HTML)
public Response getHtmlInfo(@Context HttpHeaders headers) {
Modified: incubator/stanbol/trunk/ontologymanager/web/src/main/resources/org/apache/stanbol/ontologymanager/web/templates/imports/inc_sessionmgr.ftl
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/web/src/main/resources/org/apache/stanbol/ontologymanager/web/templates/imports/inc_sessionmgr.ftl?rev=1357301&r1=1357300&r2=1357301&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/web/src/main/resources/org/apache/stanbol/ontologymanager/web/templates/imports/inc_sessionmgr.ftl (original)
+++ incubator/stanbol/trunk/ontologymanager/web/src/main/resources/org/apache/stanbol/ontologymanager/web/templates/imports/inc_sessionmgr.ftl Wed Jul 4 15:16:04 2012
@@ -17,45 +17,80 @@
<h4>Subresource ontonet/session</h4>
<p>Service to manage the set of active OntoNet sessions.
-<h4> POST ontonet/session</h4>
+<h4> GET ontonet/session</h4>
<table>
<tbody>
<tr>
<th>Description</th>
- <td>Service to add an ontology to a session space, creating the session if it does not exist.</td>
+ <td>Gets an RDF graph that describes the registered sessions.</td>
</tr>
<tr>
<th>Request</th>
- <td>POST <code>/ontonet/session</code></td>
+ <td>GET <code>/ontonet/session</code></td>
</tr>
<tr>
<th>Parameters</th>
- <td><code>input</code>: the OWL file to be loaded. This parameter is mutually exclusive with <code>location</code>.</td>
+ <td><i>none</i></td>
</tr>
<tr>
- <th></th>
- <td><code>location</code>: the physical URL of the OWL file to be loaded. This parameter is mutually exclusive with <code>input</code>.</td>
+ <th>Produces</th>
+ <td>
+ <tt>application/owl+xml</tt>,
+ <tt>application/rdf+json</tt>,
+ <tt>application/rdf+xml</tt>,
+ <tt>application/x-turtle</tt>,
+ <tt>text/owl+functional</tt>,
+ <tt>text/owl+manchester</tt>,
+ <tt>text/plain</tt>,
+ <tt>text/rdf+n3</tt>,
+ <tt>text/rdf+n3</tt>,
+ <tt>text/turtle</tt>
+ </td>
</tr>
+ </tbody>
+</table>
+
+<h5>Example</h5>
+
+<pre>curl -X GET -H "Accept: text/turtle" ${it.publicBaseUri}ontonet/session</pre>
+
+<h4> PUT ontonet/session/[id]</h4>
+Creates a session with the specified ID, if not used already.
+
+<h4> POST ontonet/session</h4>
+<table>
+ <tbody>
<tr>
- <th></th>
- <td><code>scope</code>: the ID of the scope whose session space will contain the ontology.</td>
+ <th>Description</th>
+ <td>Creates a session and lets Stanbol choose its identifier.</td>
</tr>
<tr>
- <th></th>
- <td><code>session</code>: the ID of the session to add the ontology. If it does not exist it will be created, along with corresponding session spaces for all active scopes.</td>
+ <th>Request</th>
+ <td>POST <code>/ontonet/session</code></td>
+ </tr>
+ <tr>
+ <th>Parameters</th>
+ <td><i>none</i></td>
</tr>
<tr>
<th>Produces</th>
- <td>Nothing. Returns Status 200 if successful, 500 otherwise.</td>
+ <td><ul>
+ <li>201 CREATED, with the session URI in the Location response header.
+ <li>503 FORBIDDEN if the session could not be created due to session quota exceeded.
+ </ul></td>
</tr>
</tbody>
</table>
<h5>Example</h5>
-<pre>curl -X POST "${it.publicBaseUri}ontonet/session?scope=[scope_id]&session=[session_id]&location=[location]"</pre>
+<pre>curl -X POST ${it.publicBaseUri}ontonet/session
+HTTP/1.1 201 Created
+Location: ${it.publicBaseUri}ontonet/session/1341413780858
+</pre>
+<!--
<h4> DELETE ontonet/session</h4>
<table>
<tbody>
@@ -88,4 +123,5 @@
<h5>Example</h5>
-<pre>curl -X DELETE "${it.publicBaseUri}ontonet/session?scope=[scope_id]&session=[session_id]&delete=[ontology_id]"</pre>
\ No newline at end of file
+<pre>curl -X DELETE "${it.publicBaseUri}ontonet/session?scope=[scope_id]&session=[session_id]&delete=[ontology_id]"</pre>
+-->
\ No newline at end of file