cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r756792 - in /cxf/trunk: rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/ systests/src/test/java/org/apache/cxf/systest/jaxrs/ systests/src/test/java/org/apache/cxf/syst...
Date Fri, 20 Mar 2009 22:41:42 GMT
Author: sergeyb
Date: Fri Mar 20 22:41:41 2009
New Revision: 756792

URL: http://svn.apache.org/viewvc?rev=756792&view=rev
Log:
JAXRS: XMLSource buffering mode

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/Messages.properties
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/XMLSource.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/XMLSourceTest.java
    cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java
    cxf/trunk/systests/src/test/java/org/apache/cxf/systest/rest/RestClientServerBookTest.java
    cxf/trunk/systests/src/test/java/org/apache/cxf/systest/rest/RestClientServerHttpBindingTest.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/Messages.properties
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/Messages.properties?rev=756792&r1=756791&r2=756792&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/Messages.properties
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/Messages.properties
Fri Mar 20 22:41:41 2009
@@ -31,4 +31,5 @@
 NO_MSG_READER =.No message body reader found for request class : {0}, ContentType : {1}.
 NO_SUBRESOURCE_METHOD_FOUND=No operation matching request path {0} is found on subresource,
ContentType : {1}, Accept : {2}.
 NO_OP_EXC =.No operation matching request path {0} is found, ContentType : {1}, Accept :
{2}.
-MULTTIPART_ID_NOT_FOUND=No multipart with content id {0} found, request content type : {1}
\ No newline at end of file
+MULTTIPART_ID_NOT_FOUND=No multipart with content id {0} found, request content type : {1}
+NO_SOURCE_MARK=InputStream used by XMLSource does not support buffering mode
\ No newline at end of file

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/XMLSource.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/XMLSource.java?rev=756792&r1=756791&r2=756792&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/XMLSource.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/XMLSource.java Fri
Mar 20 22:41:41 2009
@@ -18,6 +18,7 @@
  */
 package org.apache.cxf.jaxrs.utils;
 
+import java.io.IOException;
 import java.io.InputStream;
 import java.lang.reflect.Array;
 import java.net.URI;
@@ -25,6 +26,8 @@
 import java.util.Iterator;
 import java.util.LinkedHashMap;
 import java.util.Map;
+import java.util.ResourceBundle;
+import java.util.logging.Logger;
 
 import javax.xml.bind.JAXBContext;
 import javax.xml.bind.Unmarshaller;
@@ -41,7 +44,10 @@
 
 import org.xml.sax.InputSource;
 
+import org.apache.cxf.common.i18n.BundleUtils;
+import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.helpers.CastUtils;
+import org.apache.cxf.helpers.IOUtils;
 import org.apache.cxf.jaxrs.provider.JAXBElementProvider;
 
 /**
@@ -49,18 +55,27 @@
  *
  */
 public class XMLSource {
+    private static final Logger LOG = LogUtils.getL7dLogger(XMLSource.class);
+    private static final ResourceBundle BUNDLE = BundleUtils.getBundle(XMLSource.class);
     
     private static final String XML_NAMESPACE = "http://www.w3.org/XML/1998/namespace"; 
     
-    private InputSource source; 
-    private RuntimeException exceptionToThrow;
+    private InputStream stream; 
+    private boolean buffering;
     
     public XMLSource(InputStream is) {
-        source = new InputSource(is);
+        stream = is;
     }
     
-    public void setException(RuntimeException ex) {
-        exceptionToThrow = ex; 
+    public void setBuffering(boolean enable) {
+        buffering = enable;
+        if (!stream.markSupported()) {
+            try {
+                stream = IOUtils.loadIntoBAIS(stream);
+            } catch (IOException ex) {
+                LOG.warning(new org.apache.cxf.common.i18n.Message("NO_SOURCE_MARK", BUNDLE).toString());
+            }
+        }
     }
     
     public <T> T getNode(String expression, Class<T> cls) {
@@ -71,11 +86,8 @@
         XPath xpath = XPathFactory.newInstance().newXPath();
         xpath.setNamespaceContext(new NamespaceContextImpl(namespaces));
         try {
-            Node node = (Node)xpath.evaluate(expression, source, XPathConstants.NODE);
+            Node node = (Node)xpath.evaluate(expression, getSource(), XPathConstants.NODE);
             if (node == null) {
-                if (exceptionToThrow != null) {
-                    throw exceptionToThrow;
-                }
                 return null;
             }
             DOMSource ds = new DOMSource(node);
@@ -94,11 +106,8 @@
         XPath xpath = XPathFactory.newInstance().newXPath();
         xpath.setNamespaceContext(new NamespaceContextImpl(namespaces));
         try {
-            NodeList nodes = (NodeList)xpath.evaluate(expression, source, XPathConstants.NODESET);
+            NodeList nodes = (NodeList)xpath.evaluate(expression, getSource(), XPathConstants.NODESET);
             if (nodes == null || nodes.getLength() == 0) {
-                if (exceptionToThrow != null) {
-                    throw exceptionToThrow;
-                }
                 return null;
             }
             T[] values = (T[])Array.newInstance(cls, nodes.getLength());
@@ -138,7 +147,7 @@
         XPath xpath = XPathFactory.newInstance().newXPath();
         xpath.setNamespaceContext(new NamespaceContextImpl(namespaces));
         try {
-            return (String)xpath.evaluate(expression, source, XPathConstants.STRING);
+            return (String)xpath.evaluate(expression, getSource(), XPathConstants.STRING);
         } catch (XPathExpressionException ex) {
             throw new IllegalArgumentException("Illegal XPath expression '" + expression
+ "'", ex);
         }
@@ -187,4 +196,16 @@
             throw new RuntimeException(ex);
         }
     }
+    
+    private InputSource getSource() {
+        try {
+            if (buffering) {
+                stream.reset();
+                stream.mark(stream.available());
+            }
+        } catch (IOException ex) {
+            LOG.warning(new org.apache.cxf.common.i18n.Message("NO_SOURCE_MARK", BUNDLE).toString());
+        }
+        return new InputSource(stream);
+    }
 }

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/XMLSourceTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/XMLSourceTest.java?rev=756792&r1=756791&r2=756792&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/XMLSourceTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/XMLSourceTest.java
Fri Mar 20 22:41:41 2009
@@ -51,6 +51,20 @@
     }
     
     @Test
+    public void testGetNodeBuffering() {
+        String data = "<x:foo xmlns:x=\"http://baz\"><x:bar/></x:foo>";

+        InputStream is = new ByteArrayInputStream(data.getBytes());
+        XMLSource xp = new XMLSource(is);
+        xp.setBuffering(true);
+        Map<String, String> map = new LinkedHashMap<String, String>();
+        map.put("x", "http://baz");
+        Bar2 bar = xp.getNode("/x:foo/x:bar", map, Bar2.class);
+        assertNotNull(bar);
+        bar = xp.getNode("/x:foo/x:bar", map, Bar2.class);
+        assertNotNull(bar);
+    }
+    
+    @Test
     public void testGetNodeNamespace2() {
         String data = "<z:foo xmlns:z=\"http://baz\"><z:bar/></z:foo>";

         InputStream is = new ByteArrayInputStream(data.getBytes());

Modified: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java?rev=756792&r1=756791&r2=756792&view=diff
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java (original)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java Fri
Mar 20 22:41:41 2009
@@ -105,7 +105,12 @@
         String baseAddress = "http://localhost:9092/test/services/rest";
         WebClient client = WebClient.create(baseAddress);
         client.path("/bookstore/123").accept(MediaType.APPLICATION_XML_TYPE);
-        Book b = client.get(XMLSource.class).getNode("/Book", Book.class);
+        XMLSource source = client.get(XMLSource.class);
+        source.setBuffering(true);
+        Book b = source.getNode("/Book", Book.class);
+        assertEquals(123, b.getId());
+        assertEquals("CXF in Action", b.getName());
+        b = source.getNode("/Book", Book.class);
         assertEquals(123, b.getId());
         assertEquals("CXF in Action", b.getName());
     }

Modified: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/rest/RestClientServerBookTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/rest/RestClientServerBookTest.java?rev=756792&r1=756791&r2=756792&view=diff
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/rest/RestClientServerBookTest.java
(original)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/rest/RestClientServerBookTest.java
Fri Mar 20 22:41:41 2009
@@ -55,7 +55,7 @@
 
     @BeforeClass
     public static void startServers() throws Exception {
-        assertTrue("server did not launch correctly", launchServer(BookServer.class));
+        assertTrue("server did not launch correctly", launchServer(BookServer.class, true));
     }
 
     @Test

Modified: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/rest/RestClientServerHttpBindingTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/rest/RestClientServerHttpBindingTest.java?rev=756792&r1=756791&r2=756792&view=diff
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/rest/RestClientServerHttpBindingTest.java
(original)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/rest/RestClientServerHttpBindingTest.java
Fri Mar 20 22:41:41 2009
@@ -55,7 +55,7 @@
    
     @BeforeClass
     public static void startServers() throws Exception {
-        assertTrue("server did not launch correctly", launchServer(HttpBindingServer.class));
+        assertTrue("server did not launch correctly", launchServer(HttpBindingServer.class,
true));
     }
    
     @Test



Mime
View raw message