Author: enridaga
Date: Thu Oct 17 19:34:07 2013
New Revision: 1533225

URL: http://svn.apache.org/r1533225
Log:
Issue STANBOL-1173 -  removed dependencies to jersey. Used clerezza utils to 
parse multipart requests.

Modified:
    stanbol/branches/commons-ng/rules/web/pom.xml
    
stanbol/branches/commons-ng/rules/web/src/main/java/org/apache/stanbol/rules/web/resources/RefactorResource.java
    
stanbol/branches/commons-ng/rules/web/src/main/java/org/apache/stanbol/rules/web/resources/RulesResource.java

Modified: stanbol/branches/commons-ng/rules/web/pom.xml
URL: 
http://svn.apache.org/viewvc/stanbol/branches/commons-ng/rules/web/pom.xml?rev=1533225&r1=1533224&r2=1533225&view=diff
==============================================================================
--- stanbol/branches/commons-ng/rules/web/pom.xml (original)
+++ stanbol/branches/commons-ng/rules/web/pom.xml Thu Oct 17 19:34:07 2013
@@ -141,7 +141,7 @@
       <groupId>commons-lang</groupId>
       <artifactId>commons-lang</artifactId>
     </dependency>
-    
+    <!--
     <dependency>
       <groupId>com.sun.jersey</groupId>
       <artifactId>jersey-server</artifactId>
@@ -160,7 +160,7 @@
       <version>1.15</version>
       <scope>compile</scope>
     </dependency>
-   
+   -->
 
     <!-- OSGi tax -->
     <dependency>
@@ -181,7 +181,12 @@
       <groupId>org.apache.clerezza</groupId>
       <artifactId>rdf.core</artifactId>
     </dependency>
-       
+       
+    <dependency>
+      <groupId>org.apache.clerezza</groupId>
+      <artifactId>jaxrs.utils</artifactId>
+    </dependency>
+   
        <!-- Tests -->
     <dependency>
         <groupId>junit</groupId>

Modified: 
stanbol/branches/commons-ng/rules/web/src/main/java/org/apache/stanbol/rules/web/resources/RefactorResource.java
URL: 
http://svn.apache.org/viewvc/stanbol/branches/commons-ng/rules/web/src/main/java/org/apache/stanbol/rules/web/resources/RefactorResource.java?rev=1533225&r1=1533224&r2=1533225&view=diff
==============================================================================
--- 
stanbol/branches/commons-ng/rules/web/src/main/java/org/apache/stanbol/rules/web/resources/RefactorResource.java
 (original)
+++ 
stanbol/branches/commons-ng/rules/web/src/main/java/org/apache/stanbol/rules/web/resources/RefactorResource.java
 Thu Oct 17 19:34:07 2013
@@ -32,6 +32,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.io.ByteArrayInputStream;
 import java.io.InputStream;
 import java.net.URI;
 import java.net.URISyntaxException;
@@ -52,6 +53,7 @@ import javax.ws.rs.core.Response;
 import javax.ws.rs.core.Response.ResponseBuilder;
 //import javax.ws.rs.core.Response.Status;
 
+import org.apache.clerezza.jaxrs.utils.form.MultiPartBody;
 import org.apache.clerezza.rdf.core.TripleCollection;
 import org.apache.clerezza.rdf.core.UriRef;
 import org.apache.felix.scr.annotations.Reference;
@@ -76,8 +78,8 @@ import org.semanticweb.owlapi.model.OWLO
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import com.sun.jersey.api.view.ImplicitProduces;
-import com.sun.jersey.multipart.FormDataParam;
+//import com.sun.jersey.api.view.ImplicitProduces;
+//import com.sun.jersey.multipart.FormDataParam;
 
 /**
  * 
@@ -86,7 +88,7 @@ import com.sun.jersey.multipart.FormData
  */
 
 @Path("/refactor")
-@ImplicitProduces(MediaType.TEXT_HTML + ";qs=2")
+//@ImplicitProduces(MediaType.TEXT_HTML + ";qs=2")
 public class RefactorResource extends BaseStanbolResource {
 
     private Logger log = LoggerFactory.getLogger(getClass());
@@ -117,9 +119,23 @@ public class RefactorResource extends Ba
     @Path("/apply")
     @Consumes(MediaType.MULTIPART_FORM_DATA)
     @Produces(value = {TURTLE, RDF_XML, MANCHESTER_OWL, FUNCTIONAL_OWL, 
OWL_XML, RDF_JSON, X_TURTLE})
-    public Response applyRefactoring(@FormDataParam("recipe") String recipe,
-                                     @FormDataParam("input") InputStream input,
+    public Response applyRefactoring(MultiPartBody data,
                                      @Context HttpHeaders headers) {
+        
+        String recipe = null;
+        InputStream input = null;
+        
+        if(data.getTextParameterValues(recipe) != null){
+            recipe = data.getTextParameterValues(recipe) [0];
+        }
+        if(data.getFormFileParameterValues("input") != null){
+            input = new 
ByteArrayInputStream(data.getFormFileParameterValues("input") [0].getContent());
+        }
+        
+        if(recipe == null || input == null){
+            throw new WebApplicationException(BAD_REQUEST);
+        }
+        
         ResponseBuilder rb;
         OWLOntology output = null;
         try {
@@ -153,9 +169,22 @@ public class RefactorResource extends Ba
     @Path("/applyfile")
     @Consumes(MediaType.MULTIPART_FORM_DATA)
     @Produces(value = {TURTLE, RDF_XML, MANCHESTER_OWL, FUNCTIONAL_OWL, 
OWL_XML, RDF_JSON, X_TURTLE})
-    public Response applyRefactoringFromRuleFile(@FormDataParam("recipe") 
InputStream recipeStream,
-                                                 @FormDataParam("input") 
InputStream input,
+    public Response applyRefactoringFromRuleFile(MultiPartBody data,
                                                  @Context HttpHeaders headers) 
{
+        InputStream recipeStream = null;
+        InputStream input = null;
+        
+        if(data.getFormFileParameterValues("recipe") != null){
+            recipeStream = new 
ByteArrayInputStream(data.getFormFileParameterValues("recipe") 
[0].getContent());
+        }
+        if(data.getFormFileParameterValues("input") != null){
+            input = new 
ByteArrayInputStream(data.getFormFileParameterValues("input") [0].getContent());
+        }
+        
+        if(recipeStream == null || input == null){
+            throw new WebApplicationException(BAD_REQUEST);
+        }
+        
         ResponseBuilder rb;
         OWLOntology output = null;
         try {
@@ -228,10 +257,22 @@ public class RefactorResource extends Ba
     @POST
     @Consumes(MediaType.MULTIPART_FORM_DATA)
     @Produces(value = {TURTLE, RDF_XML, MANCHESTER_OWL, FUNCTIONAL_OWL, 
OWL_XML, RDF_JSON, X_TURTLE})
-    public Response performRefactoring(@FormDataParam("recipe") String recipe,
-                                       @FormDataParam("input") InputStream 
input,
+    public Response performRefactoring(MultiPartBody data,
                                        @Context HttpHeaders headers) {
 
+        String recipe = null;
+        InputStream input = null;
+        
+        if(data.getTextParameterValues("recipe") != null){
+            recipe = data.getTextParameterValues("recipe") [0];
+        }
+        if(data.getFormFileParameterValues("input") != null){
+            input = new 
ByteArrayInputStream(data.getFormFileParameterValues("input") [0].getContent());
+        }
+        
+        if(recipe == null || input == null){
+            throw new WebApplicationException(BAD_REQUEST);
+        }
         // Refactorer semionRefactorer = 
semionManager.getRegisteredRefactorer();
         ResponseBuilder rb;
         Recipe rcp;

Modified: 
stanbol/branches/commons-ng/rules/web/src/main/java/org/apache/stanbol/rules/web/resources/RulesResource.java
URL: 
http://svn.apache.org/viewvc/stanbol/branches/commons-ng/rules/web/src/main/java/org/apache/stanbol/rules/web/resources/RulesResource.java?rev=1533225&r1=1533224&r2=1533225&view=diff
==============================================================================
--- 
stanbol/branches/commons-ng/rules/web/src/main/java/org/apache/stanbol/rules/web/resources/RulesResource.java
 (original)
+++ 
stanbol/branches/commons-ng/rules/web/src/main/java/org/apache/stanbol/rules/web/resources/RulesResource.java
 Thu Oct 17 19:34:07 2013
@@ -22,9 +22,11 @@
 package org.apache.stanbol.rules.web.resources;
 
 import static javax.ws.rs.core.MediaType.TEXT_HTML;
+import static javax.ws.rs.core.Response.Status.BAD_REQUEST;
 //import static org.apache.stanbol.commons.web.base.CorsHelper.addCORSOrigin;
 //import static org.apache.stanbol.commons.web.base.CorsHelper.enableCORS;
 
+import java.io.ByteArrayInputStream;
 import java.io.InputStream;
 import java.net.URI;
 import java.net.URISyntaxException;
@@ -41,6 +43,7 @@ import javax.ws.rs.Path;
 import javax.ws.rs.PathParam;
 import javax.ws.rs.Produces;
 import javax.ws.rs.QueryParam;
+import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.Context;
 import javax.ws.rs.core.HttpHeaders;
 import javax.ws.rs.core.MediaType;
@@ -48,6 +51,7 @@ import javax.ws.rs.core.Response;
 import javax.ws.rs.core.Response.ResponseBuilder;
 import javax.ws.rs.core.Response.Status;
 
+import org.apache.clerezza.jaxrs.utils.form.MultiPartBody;
 import org.apache.clerezza.rdf.core.UriRef;
 import org.apache.felix.scr.annotations.Reference;
 import org.apache.stanbol.commons.web.viewable.Viewable;
@@ -76,8 +80,8 @@ import org.codehaus.jettison.json.JSONOb
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import com.sun.jersey.api.view.ImplicitProduces;
-import com.sun.jersey.multipart.FormDataParam;
+//import com.sun.jersey.api.view.ImplicitProduces;
+//import com.sun.jersey.multipart.FormDataParam;
 
 /**
  * 
@@ -85,7 +89,7 @@ import com.sun.jersey.multipart.FormData
  * 
  */
 @Path("/rules")
-@ImplicitProduces(MediaType.TEXT_HTML + ";qs=2")
+//@ImplicitProduces(MediaType.TEXT_HTML + ";qs=2")
 public class RulesResource extends BaseStanbolResource {
 
     private Logger log = LoggerFactory.getLogger(getClass());
@@ -474,10 +478,23 @@ public class RulesResource extends BaseS
     @Produces(value = {KRFormat.TEXT_PLAIN, KRFormat.RDF_JSON})
     @Path("/recipe/{recipe:.+}")
     public Response addRulesToRecipe(@PathParam(value = "recipe") String 
recipe,
-                                     @FormDataParam(value = "rules") 
InputStream rules,
-                                     @FormDataParam(value = "description") 
String description,
+                                     MultiPartBody data,
                                      @Context HttpHeaders headers) {
 
+        String description = null;
+        InputStream rules = null;
+
+        if(data.getTextParameterValues("description") != null){
+            description = data.getTextParameterValues("description") [0];
+        }
+        if(data.getFormFileParameterValues("rules") != null){
+            rules = new 
ByteArrayInputStream(data.getFormFileParameterValues("rules") [0].getContent());
+        }
+        
+        if(recipe == null || rules == null  || description == null){
+            throw new WebApplicationException(BAD_REQUEST);
+        }
+        
         ResponseBuilder responseBuilder;
 
         Recipe rcp;


Reply via email to