cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1349313 - in /cxf/branches/2.6.x-fixes: ./ 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/ja...
Date Tue, 12 Jun 2012 13:03:04 GMT
Author: sergeyb
Date: Tue Jun 12 13:03:03 2012
New Revision: 1349313

URL: http://svn.apache.org/viewvc?rev=1349313&view=rev
Log:
Merged revisions 1349307 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r1349307 | sergeyb | 2012-06-12 13:49:50 +0100 (Tue, 12 Jun 2012) | 1 line
  
  [CXF-4373] Updating JAXB providers to end the xml documents only on JAX-RS paths
........

Added:
    cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/resources/jaxrs_soap_rest/WEB-INF/template.xsl
      - copied unchanged from r1349307, cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_soap_rest/WEB-INF/template.xsl
Modified:
    cxf/branches/2.6.x-fixes/   (props changed)
    cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
    cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/XSLTJaxbProvider.java
    cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JAXBElementProviderTest.java
    cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/XSLTJaxbProviderTest.java
    cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java
    cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/resources/jaxrs_soap_rest/WEB-INF/beans.xml

Propchange: cxf/branches/2.6.x-fixes/
------------------------------------------------------------------------------
    svn:mergeinfo = /cxf/trunk:1349307

Propchange: cxf/branches/2.6.x-fixes/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Tue Jun 12 13:03:03 2012
@@ -1 +1 @@
-/cxf/trunk:1-1348209,1348845,1348862,1348866,1349016,1349264
+/cxf/trunk:1-1348209,1348845,1348862,1348866,1349016,1349264,1349307

Modified: cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java?rev=1349313&r1=1349312&r2=1349313&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
(original)
+++ cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
Tue Jun 12 13:03:03 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/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/XSLTJaxbProvider.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/XSLTJaxbProvider.java?rev=1349313&r1=1349312&r2=1349313&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/XSLTJaxbProvider.java
(original)
+++ cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/XSLTJaxbProvider.java
Tue Jun 12 13:03:03 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/branches/2.6.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JAXBElementProviderTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JAXBElementProviderTest.java?rev=1349313&r1=1349312&r2=1349313&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JAXBElementProviderTest.java
(original)
+++ cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JAXBElementProviderTest.java
Tue Jun 12 13:03:03 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/branches/2.6.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/XSLTJaxbProviderTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/XSLTJaxbProviderTest.java?rev=1349313&r1=1349312&r2=1349313&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/XSLTJaxbProviderTest.java
(original)
+++ cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/XSLTJaxbProviderTest.java
Tue Jun 12 13:03:03 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/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java?rev=1349313&r1=1349312&r2=1349313&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java
(original)
+++ cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java
Tue Jun 12 13:03:03 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/branches/2.6.x-fixes/systests/jaxrs/src/test/resources/jaxrs_soap_rest/WEB-INF/beans.xml
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/resources/jaxrs_soap_rest/WEB-INF/beans.xml?rev=1349313&r1=1349312&r2=1349313&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/resources/jaxrs_soap_rest/WEB-INF/beans.xml
(original)
+++ cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/resources/jaxrs_soap_rest/WEB-INF/beans.xml
Tue Jun 12 13:03:03 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">



Mime
View raw message