Return-Path: Delivered-To: apmail-cxf-commits-archive@www.apache.org Received: (qmail 85405 invoked from network); 20 Mar 2009 22:42:06 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 20 Mar 2009 22:42:06 -0000 Received: (qmail 50863 invoked by uid 500); 20 Mar 2009 22:42:06 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 50802 invoked by uid 500); 20 Mar 2009 22:42:06 -0000 Mailing-List: contact commits-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list commits@cxf.apache.org Received: (qmail 50793 invoked by uid 99); 20 Mar 2009 22:42:06 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 20 Mar 2009 15:42:06 -0700 X-ASF-Spam-Status: No, hits=-1998.5 required=10.0 tests=ALL_TRUSTED,WEIRD_PORT X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 20 Mar 2009 22:42:03 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 823E0238896C; Fri, 20 Mar 2009 22:41:42 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@cxf.apache.org From: sergeyb@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090320224142.823E0238896C@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 getNode(String expression, Class 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 = ""; + InputStream is = new ByteArrayInputStream(data.getBytes()); + XMLSource xp = new XMLSource(is); + xp.setBuffering(true); + Map map = new LinkedHashMap(); + 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 = ""; 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