cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1299747 - in /cxf/trunk: rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ systests/jaxrs/src/test/java/org/a...
Date Mon, 12 Mar 2012 17:24:23 GMT
Author: sergeyb
Date: Mon Mar 12 17:24:22 2012
New Revision: 1299747

URL: http://svn.apache.org/viewvc?rev=1299747&view=rev
Log:
[CXF-4172] Adding tests for Source and Document

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServiceImpl.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/SourceProvider.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/SourceProviderTest.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSpring.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServiceImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServiceImpl.java?rev=1299747&r1=1299746&r2=1299747&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServiceImpl.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServiceImpl.java Mon
Mar 12 17:24:22 2012
@@ -29,6 +29,7 @@ import java.util.concurrent.Executor;
 
 import javax.ws.rs.core.Response;
 import javax.xml.namespace.QName;
+import javax.xml.transform.Source;
 
 import org.apache.cxf.common.util.PackageUtils;
 import org.apache.cxf.configuration.Configurable;
@@ -151,7 +152,7 @@ public class JAXRSServiceImpl extends Ab
 
     private void createMessagePartInfo(OperationInfo oi, Class<?> type, QName qname,
Method m,
                                        boolean input) {
-        if (type == void.class) {
+        if (type == void.class || Source.class.isAssignableFrom(type)) {
             return;
         }
         if (InjectionUtils.isPrimitive(type) || Response.class == type) {

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/SourceProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/SourceProvider.java?rev=1299747&r1=1299746&r2=1299747&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/SourceProvider.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/SourceProvider.java
Mon Mar 12 17:24:22 2012
@@ -48,6 +48,7 @@ import org.apache.cxf.io.CachedOutputStr
 import org.apache.cxf.jaxrs.ext.MessageContext;
 import org.apache.cxf.jaxrs.ext.xml.XMLSource;
 import org.apache.cxf.jaxrs.utils.HttpUtils;
+import org.apache.cxf.staxutils.DepthExceededStaxException;
 import org.apache.cxf.staxutils.StaxSource;
 import org.apache.cxf.staxutils.StaxUtils;
 
@@ -92,6 +93,8 @@ public class SourceProvider<T> extends A
             try {
                 Document doc = StaxUtils.read(reader);
                 return source.cast(docRequired ? doc : new DOMSource(doc));
+            } catch (DepthExceededStaxException e) {
+                throw new WebApplicationException(413);
             } catch (Exception e) {
                 IOException ioex = new IOException("Problem creating a Source object");
                 ioex.setStackTrace(e.getStackTrace());
@@ -184,11 +187,12 @@ public class SourceProvider<T> extends A
     
     protected String getPreferredSource() {
         MessageContext mc = getContext();
+        String source = null;
         if (mc != null) {
-            return (String)mc.getContextualProperty(PREFERRED_FORMAT);
-        } else {
-            return "sax";
-        }
+            source = (String)mc.getContextualProperty(PREFERRED_FORMAT);
+        } 
+        return source != null ? source : "sax";
+        
     }
     
     protected MessageContext getContext() {

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/SourceProviderTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/SourceProviderTest.java?rev=1299747&r1=1299746&r2=1299747&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/SourceProviderTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/SourceProviderTest.java
Mon Mar 12 17:24:22 2012
@@ -76,7 +76,7 @@ public class SourceProviderTest extends 
     public void testReadFrom() throws Exception {
         SourceProvider<Object> p = new TestSourceProvider<Object>();
         assertSame(StreamSource.class, verifyRead(p, StreamSource.class).getClass());
-        assertSame(StreamSource.class, verifyRead(p, Source.class).getClass());
+        assertSame(StaxSource.class, verifyRead(p, Source.class).getClass());
         assertSame(StaxSource.class, verifyRead(p, SAXSource.class).getClass());
         assertSame(StaxSource.class, verifyRead(p, StaxSource.class).getClass());
         assertSame(DOMSource.class, verifyRead(p, DOMSource.class).getClass());

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSpring.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSpring.java?rev=1299747&r1=1299746&r2=1299747&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSpring.java
(original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSpring.java
Mon Mar 12 17:24:22 2012
@@ -20,6 +20,7 @@
 package org.apache.cxf.systest.jaxrs;
 
 
+import java.io.ByteArrayOutputStream;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -34,12 +35,17 @@ 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.MediaType;
 import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.UriInfo;
+import javax.xml.transform.Source;
+import javax.xml.transform.dom.DOMSource;
 
 import org.apache.cxf.annotations.Logging;
+import org.apache.cxf.staxutils.DepthExceededStaxException;
+import org.apache.cxf.staxutils.StaxUtils;
 
 @Path("/")
 @Produces("application/json")
@@ -147,6 +153,27 @@ public class BookStoreSpring {
     }
     
     @POST
+    @Path("depth-source")
+    @Consumes({"application/xml" })
+    public void postSourceBook(Source source) {
+        try {
+            StaxUtils.copy(source, new ByteArrayOutputStream());
+        } catch (DepthExceededStaxException ex) {
+            throw new WebApplicationException(413); 
+        } catch (Exception ex) {
+            // ignore for now
+        }
+        throw new WebApplicationException(500);
+    }
+    
+    @POST
+    @Path("depth-dom")
+    @Consumes({"application/xml" })
+    public void postDomBook(DOMSource source) {
+        // complete
+    }
+    
+    @POST
     @Path("depth-form")
     @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
     public void depthForm(MultivaluedMap<String, String> map) {

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java?rev=1299747&r1=1299746&r2=1299747&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java
(original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java
Mon Mar 12 17:24:22 2012
@@ -65,7 +65,7 @@ public class JAXRSClientServerSpringBook
     @BeforeClass
     public static void startServers() throws Exception {
         assertTrue("server did not launch correctly", 
-                   launchServer(BookServerSpring.class));
+                   launchServer(BookServerSpring.class, true));
     }
     
     @Test
@@ -232,6 +232,25 @@ public class JAXRSClientServerSpringBook
     }
     
     @Test
+    public void testBookDepthExceededXMLSource() throws Exception {
+        String endpointAddress =
+            "http://localhost:" + PORT + "/the/thebooks9/depth-source"; 
+        WebClient wc = WebClient.create(endpointAddress);
+        Response r = wc.post(new Book("CXF", 123L));
+        assertEquals(413, r.getStatus());
+    }
+    
+    @Test
+    public void testBookDepthExceededXMLDom() throws Exception {
+        String endpointAddress =
+            "http://localhost:" + PORT + "/the/thebooks9/depth-dom"; 
+        WebClient wc = WebClient.create(endpointAddress);
+        WebClient.getConfig(wc).getHttpConduit().getClient().setReceiveTimeout(1000000L);
+        Response r = wc.post(new Book("CXF", 123L));
+        assertEquals(413, r.getStatus());
+    }
+    
+    @Test
     public void testBookDepthExceededJettison() throws Exception {
         String endpointAddress =
             "http://localhost:" + PORT + "/the/thebooks10/depth"; 
@@ -259,7 +278,6 @@ public class JAXRSClientServerSpringBook
         WebClient client = WebClient.create(url);
         client.accept("application/json, application/x-javascript");
         client.query("_jsonp", "callback");
-        WebClient.getConfig(client).getHttpConduit().getClient().setReceiveTimeout(1000000L);
         Response r = client.get();
         assertEquals("application/x-javascript", r.getMetadata().getFirst("Content-Type"));
         assertEquals("callback({\"Book\":{\"id\":123,\"name\":\"CXF in Action\"}});",



Mime
View raw message