cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1349307 - in /cxf/trunk: 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/apache/cxf/systest/jaxrs/ systests/jaxrs/src/test/resou...
Date Tue, 12 Jun 2012 12:49:50 GMT
Author: sergeyb
Date: Tue Jun 12 12:49:50 2012
New Revision: 1349307

URL: http://svn.apache.org/viewvc?rev=1349307&view=rev
Log:
[CXF-4373] Updating JAXB providers to end the xml documents only on JAX-RS paths

Added:
    cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_soap_rest/WEB-INF/template.xsl   (with
props)
Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/XSLTJaxbProvider.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JAXBElementProviderTest.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/XSLTJaxbProviderTest.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java
    cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_soap_rest/WEB-INF/beans.xml

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java?rev=1349307&r1=1349306&r2=1349307&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
Tue Jun 12 12:49:50 2012
@@ -503,7 +503,9 @@ public class JAXBElementProvider<T> exte
                 mc.put(XMLStreamWriter.class.getName(), writer);    
             }
             marshalToWriter(ms, obj, writer, mt);
-            writer.writeEndDocument();
+            if (mc != null) { 
+                writer.writeEndDocument();
+            }
         } else {
             marshalToOutputStream(ms, obj, os, mt);
         }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/XSLTJaxbProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/XSLTJaxbProvider.java?rev=1349307&r1=1349306&r2=1349307&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/XSLTJaxbProvider.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/XSLTJaxbProvider.java
Tue Jun 12 12:49:50 2012
@@ -194,11 +194,11 @@ public class XSLTJaxbProvider<T> extends
         marshalToOutputStream(ms, obj, out, mt);
         
         StaxUtils.copy(new StreamSource(out.getInputStream()), writer);
-        if (getContext() == null) {
-            writer.writeEndDocument();
-            writer.flush();
-            writer.close();
-        }
+    }
+    
+    @Override
+    protected void addAttachmentMarshaller(Marshaller ms) {
+        // complete
     }
     
     @Override
@@ -211,14 +211,20 @@ public class XSLTJaxbProvider<T> extends
             return;
         }
         
-        TransformerHandler th = factory.newTransformerHandler(
-            createTemplates(getOutTemplates(mt), outParamsMap, outProperties));
+        TransformerHandler th = factory.newTransformerHandler(t);
         Result result = new StreamResult(os);
         if (systemId != null) {
             result.setSystemId(systemId);
         }
         th.setResult(result);
+        
+        if (getContext() == null) {
+            th.startDocument();
+        }
         ms.marshal(obj, th);
+        if (getContext() == null) {
+            th.endDocument();
+        }
     }
     
     public void setOutTemplate(String loc) {

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JAXBElementProviderTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JAXBElementProviderTest.java?rev=1349307&r1=1349306&r2=1349307&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JAXBElementProviderTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JAXBElementProviderTest.java
Tue Jun 12 12:49:50 2012
@@ -42,6 +42,7 @@ import java.util.TreeSet;
 import javax.ws.rs.GET;
 import javax.ws.rs.Path;
 import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Application;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
 import javax.xml.bind.JAXBContext;
@@ -66,7 +67,9 @@ import org.w3c.dom.Node;
 
 import org.xml.sax.ContentHandler;
 
+import org.apache.cxf.endpoint.Endpoint;
 import org.apache.cxf.helpers.CastUtils;
+import org.apache.cxf.jaxrs.ext.MessageContextImpl;
 import org.apache.cxf.jaxrs.ext.xml.XMLSource;
 import org.apache.cxf.jaxrs.fortest.jaxb.packageinfo.Book2;
 import org.apache.cxf.jaxrs.fortest.jaxb.packageinfo.Book2NoRootElement;
@@ -84,6 +87,11 @@ import org.apache.cxf.jaxrs.resources.Ta
 import org.apache.cxf.jaxrs.resources.Tags;
 import org.apache.cxf.jaxrs.utils.ParameterizedCollectionType;
 import org.apache.cxf.jaxrs.utils.ResourceUtils;
+import org.apache.cxf.message.Exchange;
+import org.apache.cxf.message.ExchangeImpl;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.message.MessageImpl;
+import org.easymock.EasyMock;
 
 import org.junit.Assert;
 import org.junit.Ignore;
@@ -775,6 +783,7 @@ public class JAXBElementProviderTest ext
 
         //Provider
         JAXBElementProvider<List<?>> provider = new JAXBElementProvider<List<?>>();
+        provider.setMessageContext(new MessageContextImpl(createMessage()));
         provider.setCollectionWrapperName("tagholders");
         Map<String, String> map = new HashMap<String, String>();
         map.put("{http://tags}*", "*");
@@ -1484,4 +1493,28 @@ public class JAXBElementProviderTest ext
             return null;
         }
     }
+    
+    private Message createMessage() {
+        ProviderFactory factory = ProviderFactory.getInstance();
+        Message m = new MessageImpl();
+        m.put(Message.ENDPOINT_ADDRESS, "http://localhost:8080/bar");
+        m.put("org.apache.cxf.http.case_insensitive_queries", false);
+        Exchange e = new ExchangeImpl();
+        m.setExchange(e);
+        e.setInMessage(m);
+        Endpoint endpoint = EasyMock.createMock(Endpoint.class);
+        endpoint.getEndpointInfo();
+        EasyMock.expectLastCall().andReturn(null).anyTimes();
+        endpoint.get(Application.class.getName());
+        EasyMock.expectLastCall().andReturn(null);
+        endpoint.size();
+        EasyMock.expectLastCall().andReturn(0).anyTimes();
+        endpoint.isEmpty();
+        EasyMock.expectLastCall().andReturn(true).anyTimes();
+        endpoint.get(ProviderFactory.class.getName());
+        EasyMock.expectLastCall().andReturn(factory).anyTimes();
+        EasyMock.replay(endpoint);
+        e.put(Endpoint.class, endpoint);
+        return m;
+    }
 }

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/XSLTJaxbProviderTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/XSLTJaxbProviderTest.java?rev=1349307&r1=1349306&r2=1349307&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/XSLTJaxbProviderTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/XSLTJaxbProviderTest.java
Tue Jun 12 12:49:50 2012
@@ -26,15 +26,23 @@ import java.io.StringReader;
 import java.util.ArrayList;
 import java.util.List;
 
+import javax.ws.rs.core.Application;
 import javax.ws.rs.core.MediaType;
 import javax.xml.bind.Unmarshaller;
 import javax.xml.stream.XMLStreamReader;
 import javax.xml.stream.XMLStreamWriter;
 
+import org.apache.cxf.endpoint.Endpoint;
+import org.apache.cxf.jaxrs.ext.MessageContextImpl;
 import org.apache.cxf.jaxrs.impl.MetadataMap;
 import org.apache.cxf.jaxrs.resources.Book;
 import org.apache.cxf.jaxrs.resources.SuperBook;
+import org.apache.cxf.message.Exchange;
+import org.apache.cxf.message.ExchangeImpl;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.message.MessageImpl;
 import org.apache.cxf.staxutils.StaxUtils;
+import org.easymock.EasyMock;
 
 import org.junit.Assert;
 import org.junit.Test;
@@ -87,7 +95,7 @@ public class XSLTJaxbProviderTest extend
     public void testWrite() throws Exception {
         XSLTJaxbProvider<Book> provider = new XSLTJaxbProvider<Book>();
         provider.setOutTemplate(TEMPLATE_LOCATION);
-        
+        provider.setMessageContext(new MessageContextImpl(createMessage()));
         Book b = new Book();
         b.setId(123L);
         b.setName("TheBook");
@@ -109,7 +117,7 @@ public class XSLTJaxbProviderTest extend
             }
         };
         provider.setOutTemplate(TEMPLATE_LOCATION);
-        
+        provider.setMessageContext(new MessageContextImpl(createMessage()));
         Book b = new Book();
         b.setId(123L);
         b.setName("TheBook");
@@ -225,4 +233,27 @@ public class XSLTJaxbProviderTest extend
         assertEquals("Transformation is bad", b, b2);
     }
     
+    private Message createMessage() {
+        ProviderFactory factory = ProviderFactory.getInstance();
+        Message m = new MessageImpl();
+        m.put(Message.ENDPOINT_ADDRESS, "http://localhost:8080/bar");
+        m.put("org.apache.cxf.http.case_insensitive_queries", false);
+        Exchange e = new ExchangeImpl();
+        m.setExchange(e);
+        e.setInMessage(m);
+        Endpoint endpoint = EasyMock.createMock(Endpoint.class);
+        endpoint.getEndpointInfo();
+        EasyMock.expectLastCall().andReturn(null).anyTimes();
+        endpoint.get(Application.class.getName());
+        EasyMock.expectLastCall().andReturn(null);
+        endpoint.size();
+        EasyMock.expectLastCall().andReturn(0).anyTimes();
+        endpoint.isEmpty();
+        EasyMock.expectLastCall().andReturn(true).anyTimes();
+        endpoint.get(ProviderFactory.class.getName());
+        EasyMock.expectLastCall().andReturn(factory).anyTimes();
+        EasyMock.replay(endpoint);
+        e.put(Endpoint.class, endpoint);
+        return m;
+    }
 }

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java?rev=1349307&r1=1349306&r2=1349307&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java
(original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java
Tue Jun 12 12:49:50 2012
@@ -78,6 +78,7 @@ import org.apache.cxf.systest.jaxrs.jaxw
 import org.apache.cxf.systest.jaxrs.jaxws.UserImpl;
 import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
 import org.apache.cxf.transport.http.HTTPConduit;
+import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;
 
 import org.junit.BeforeClass;
 import org.junit.Ignore;
@@ -89,7 +90,7 @@ public class JAXRSSoapBookTest extends A
     @BeforeClass
     public static void startServers() throws Exception {
         assertTrue("server did not launch correctly", 
-                   launchServer(BookServerRestSoap.class, true));
+                   launchServer(BookServerRestSoap.class));
     }
     
     @Test
@@ -115,21 +116,41 @@ public class JAXRSSoapBookTest extends A
     }
     
     @Test
-    public void testHelloSoapCustomDataBinding() throws Exception {
+    public void testHelloSoapCustomDataBindingJaxb() throws Exception {
+        final String address = "http://localhost:" + PORT + "/test/services/hello-soap-databinding-jaxb";
+        doTestHelloSoapCustomDataBinding(address);
+    }
+    
+    @Test
+    public void testHelloSoapCustomDataBindingJaxbXslt() throws Exception {
+        final String address = "http://localhost:" + PORT + "/test/services/hello-soap-databinding-xslt";
+        doTestHelloSoapCustomDataBinding(address);
+    }
+    
+    private void doTestHelloSoapCustomDataBinding(String address) throws Exception {
         final QName serviceName = new QName("http://hello.com", "HelloWorld");
         final QName portName = new QName("http://hello.com", "HelloWorldPort");
-        final String address = "http://localhost:" + PORT + "/test/services/hello-soap-databinding";
         
         Service service = Service.create(serviceName);
         service.addPort(portName, SOAPBinding.SOAP11HTTP_BINDING, address);
     
         HelloWorld hw = service.getPort(HelloWorld.class); 
+        
+        Client cl = ClientProxy.getClient(hw);
+        
+        HTTPConduit http = (HTTPConduit) cl.getConduit();
+         
+        HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
+        httpClientPolicy.setConnectionTimeout(0);
+        httpClientPolicy.setReceiveTimeout(0);
+         
+        http.setClient(httpClientPolicy);
     
         User user = new UserImpl("Barry");
         User user2 = hw.echoUser(user);
         
         assertNotSame(user, user2);
-        assertEquals("Barry", user.getName());
+        assertEquals("Barry", user2.getName());
     }
     
     private void useHelloService(HelloWorld service) {

Modified: cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_soap_rest/WEB-INF/beans.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_soap_rest/WEB-INF/beans.xml?rev=1349307&r1=1349306&r2=1349307&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_soap_rest/WEB-INF/beans.xml (original)
+++ cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_soap_rest/WEB-INF/beans.xml Tue Jun
12 12:49:50 2012
@@ -93,25 +93,46 @@ http://cxf.apache.org/schemas/jaxrs.xsd"
           <entry key="org.apache.cxf.endpoint.private" value="true"/>
       </jaxws:properties>
   </jaxws:endpoint>
-  
   <jaxws:endpoint xmlns:s="http://hello.com"
       serviceName="s:HelloWorld"
       endpointName="s:HelloWorldPort"
       id="hello_soap-databinding"
       implementor="org.apache.cxf.systest.jaxrs.jaxws.HelloWorldImpl"
-      address="/hello-soap-databinding">
+      address="/hello-soap-databinding-jaxb">
       
       <jaxws:dataBinding>
           <ref bean="jaxrs-data-binding"/>
       </jaxws:dataBinding>
       
-  </jaxws:endpoint>        
-
+  </jaxws:endpoint>
+  
+  <jaxws:endpoint xmlns:s="http://hello.com"
+      serviceName="s:HelloWorld"
+      endpointName="s:HelloWorldPort"
+      id="hello_soap-databinding-xslt"
+      implementor="org.apache.cxf.systest.jaxrs.jaxws.HelloWorldImpl"
+      address="/hello-soap-databinding-xslt">
+      
+      <jaxws:dataBinding>
+          <ref bean="jaxrs-data-binding-xslt"/>
+      </jaxws:dataBinding>
+      
+  </jaxws:endpoint>
+          
   <bean id="jaxrs-data-binding" class="org.apache.cxf.jaxrs.provider.JAXRSDataBinding">
       <property name="provider" ref="jaxbProviderSoap"/>
   </bean>
-
+  
   <bean id="jaxbProviderSoap" class="org.apache.cxf.jaxrs.provider.JAXBElementProvider"/>
+  
+  <bean id="jaxrs-data-binding-xslt" class="org.apache.cxf.jaxrs.provider.JAXRSDataBinding">
+      <property name="provider" ref="jaxbProviderXslt"/>
+  </bean>
+  
+  <bean id="jaxbProviderXslt" class="org.apache.cxf.jaxrs.provider.XSLTJaxbProvider">
+      <property name="inTemplate" value="classpath:/WEB-INF/template.xsl"/>
+      <property name="outTemplate" value="classpath:/WEB-INF/template.xsl"/>
+  </bean>
 
   <jaxrs:server id="restservice2"
 		        address="/rest2">

Added: cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_soap_rest/WEB-INF/template.xsl
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_soap_rest/WEB-INF/template.xsl?rev=1349307&view=auto
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_soap_rest/WEB-INF/template.xsl (added)
+++ cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_soap_rest/WEB-INF/template.xsl Tue Jun
12 12:49:50 2012
@@ -0,0 +1,27 @@
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements. See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership. The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License. You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing,
+  software distributed under the License is distributed on an
+  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  KIND, either express or implied. See the License for the
+  specific language governing permissions and limitations
+  under the License.
+-->
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:books="http://www.w3.org/books">
+ 
+ <xsl:template match="@*|node()">
+    <xsl:copy>
+      <xsl:apply-templates select="@*|node()"/>
+    </xsl:copy>
+  </xsl:template>
+ 
+</xsl:stylesheet> 

Propchange: cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_soap_rest/WEB-INF/template.xsl
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_soap_rest/WEB-INF/template.xsl
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_soap_rest/WEB-INF/template.xsl
------------------------------------------------------------------------------
    svn:mime-type = text/xml



Mime
View raw message