cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r902178 - in /cxf/branches/2.2.x-fixes: ./ rt/core/src/main/java/org/apache/cxf/interceptor/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ systests/jaxrs/src/test/ja...
Date Fri, 22 Jan 2010 17:12:53 GMT
Author: sergeyb
Date: Fri Jan 22 17:12:52 2010
New Revision: 902178

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

........
  r902101 | sergeyb | 2010-01-22 14:37:26 +0000 (Fri, 22 Jan 2010) | 1 line
  
  JAXRS : Updating JAXBElementProvider to check for stax factories
........

Modified:
    cxf/branches/2.2.x-fixes/   (props changed)
    cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/FIStaxInInterceptor.java
    cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/FIStaxOutInterceptor.java
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/MessageContextImpl.java
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
    cxf/branches/2.2.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreJaxrsJaxws.java
    cxf/branches/2.2.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSoapRestImpl.java
    cxf/branches/2.2.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java
    cxf/branches/2.2.x-fixes/systests/jaxrs/src/test/resources/jaxrs_soap_rest/WEB-INF/beans.xml

Propchange: cxf/branches/2.2.x-fixes/
------------------------------------------------------------------------------
    svn:mergeinfo = /cxf/trunk:902101

Propchange: cxf/branches/2.2.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/FIStaxInInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/FIStaxInInterceptor.java?rev=902178&r1=902177&r2=902178&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/FIStaxInInterceptor.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/FIStaxInInterceptor.java
Fri Jan 22 17:12:52 2010
@@ -28,6 +28,7 @@
 
 import org.apache.cxf.endpoint.Endpoint;
 import org.apache.cxf.message.Message;
+import org.apache.cxf.message.MessageUtils;
 import org.apache.cxf.phase.AbstractPhaseInterceptor;
 import org.apache.cxf.phase.Phase;
 
@@ -35,21 +36,26 @@
  * Creates an XMLStreamReader from the InputStream on the Message.
  */
 public class FIStaxInInterceptor extends AbstractPhaseInterceptor<Message> {
+    public static final String FI_GET_SUPPORTED = "org.apache.cxf.fastinfoset.get.supported";
+    
     XMLInputFactory factory = new StAXInputFactory();
 
     public FIStaxInInterceptor() {
         this(Phase.POST_STREAM);
     }
+    
     public FIStaxInInterceptor(String phase) {
         super(phase);
         addBefore(StaxInInterceptor.class.getName());
     }
+    
     protected boolean isRequestor(Message message) {
         return Boolean.TRUE.equals(message.containsKey(Message.REQUESTOR_ROLE));
     }
 
     public void handleMessage(Message message) {
-        if (isGET(message) || message.getContentFormats().contains(XMLStreamReader.class))
{
+        if (message.getContentFormats().contains(XMLStreamReader.class)
+            || !isHttpVerbSupported(message)) {
             return;
         }
 
@@ -71,4 +77,16 @@
             }
         }
     }
+    
+    protected boolean isHttpVerbSupported(Message message) {
+        if (isGET(message)) {
+            if (isRequestor(message) 
+                && MessageUtils.isTrue(message.getContextualProperty(FI_GET_SUPPORTED)))
{
+                return true;
+            }
+            return false;
+        } else {
+            return true;
+        }
+    }
 }

Modified: cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/FIStaxOutInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/FIStaxOutInterceptor.java?rev=902178&r1=902177&r2=902178&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/FIStaxOutInterceptor.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/FIStaxOutInterceptor.java
Fri Jan 22 17:12:52 2010
@@ -31,6 +31,7 @@
 
 import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.message.Message;
+import org.apache.cxf.message.MessageUtils;
 import org.apache.cxf.phase.AbstractPhaseInterceptor;
 import org.apache.cxf.phase.Phase;
 
@@ -54,6 +55,8 @@
         force = f;
     }
     
+    
+    
     public void handleMessage(Message message) {
         XMLStreamWriter writer = message.getContent(XMLStreamWriter.class);
         if (writer != null) {
@@ -87,7 +90,7 @@
         }
             
         if (force 
-            || Boolean.TRUE.equals(o)) {
+            || MessageUtils.isTrue(o)) {
             
             message.put(XMLOutputFactory.class.getName(),
                         factory);

Modified: cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/MessageContextImpl.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/MessageContextImpl.java?rev=902178&r1=902177&r2=902178&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/MessageContextImpl.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/MessageContextImpl.java
Fri Jan 22 17:12:52 2010
@@ -68,7 +68,18 @@
             || (MultipartBody.INBOUND_MESSAGE_ATTACHMENTS + ".embedded").equals(keyValue))
{
             return createAttachments(key.toString());
         }
-        return m.get(key);
+        Object value = m.get(key);
+        if (value == null && isRequestor()) {
+            Message inMessage = m.getExchange().getInMessage();
+            if (inMessage != null) {
+                value = inMessage.get(key);
+            }
+        } 
+        return value;
+    }
+    
+    private boolean isRequestor() {
+        return Boolean.TRUE.equals(m.containsKey(Message.REQUESTOR_ROLE));
     }
     
     public <T> T getContent(Class<T> format) {

Modified: cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java?rev=902178&r1=902177&r2=902178&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
Fri Jan 22 17:12:52 2010
@@ -45,6 +45,9 @@
 import javax.xml.bind.Unmarshaller;
 import javax.xml.bind.ValidationEventHandler;
 import javax.xml.namespace.QName;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
 import javax.xml.stream.XMLStreamWriter;
 import javax.xml.transform.stream.StreamSource;
@@ -186,6 +189,19 @@
     protected XMLStreamReader getStreamReader(InputStream is, Class<?> type, MediaType
mt) {
         MessageContext mc = getContext();
         XMLStreamReader reader = mc != null ? mc.getContent(XMLStreamReader.class) : null;
+        
+        if (reader == null && mc != null) {
+            XMLInputFactory factory = (XMLInputFactory)mc.get(XMLInputFactory.class.getName());
+            if (factory != null) {
+                try {
+                    reader = factory.createXMLStreamReader(is);
+                } catch (XMLStreamException e) {
+                    throw new WebApplicationException(
+                        new RuntimeException("Cant' create XMLStreamReader", e));
+                }
+            }
+        }
+        
         reader = createTransformReaderIfNeeded(reader, is);
         if (InjectionUtils.isSupportedCollectionOrArray(type)) {
             return new JAXBCollectionWrapperReader(createNewReaderIfNeeded(reader, is));
@@ -332,6 +348,17 @@
         MessageContext mc = getContext();
         if (mc != null) {
             writer = mc.getContent(XMLStreamWriter.class);
+            if (writer == null) {
+                XMLOutputFactory factory = (XMLOutputFactory)mc.get(XMLOutputFactory.class.getName());
+                if (factory != null) {
+                    try {
+                        writer = factory.createXMLStreamWriter(os);
+                    } catch (XMLStreamException e) {
+                        throw new WebApplicationException(
+                            new RuntimeException("Cant' create XMLStreamWriter", e));
+                    }
+                }
+            }
             if (writer == null && enableStreaming) {
                 writer = StaxUtils.createXMLStreamWriter(os);
             }

Modified: cxf/branches/2.2.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreJaxrsJaxws.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreJaxrsJaxws.java?rev=902178&r1=902177&r2=902178&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreJaxrsJaxws.java
(original)
+++ cxf/branches/2.2.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreJaxrsJaxws.java
Fri Jan 22 17:12:52 2010
@@ -53,4 +53,17 @@
     @Path("/thestore/{id}")
     @WebMethod(exclude = true)
     BookStoreJaxrsJaxws getBookStore(@PathParam("id") String id);
+    
+    @POST
+    @Path("/fastinfoset")
+    @Consumes({"text/xml" })
+    @Produces({"application/fastinfoset", "text/xml", "application/xml" })
+    @WebMethod(exclude = true)
+    Book addFastinfoBook(Book book);
+    
+    @GET
+    @Path("/fastinfoset2")
+    @Produces({"application/fastinfoset", "text/xml", "application/xml" })
+    @WebMethod(exclude = true)
+    Book getFastinfoBook();
 }

Modified: cxf/branches/2.2.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSoapRestImpl.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSoapRestImpl.java?rev=902178&r1=902177&r2=902178&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSoapRestImpl.java
(original)
+++ cxf/branches/2.2.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSoapRestImpl.java
Fri Jan 22 17:12:52 2010
@@ -142,5 +142,13 @@
         }
         return this;
     }
+
+    public Book addFastinfoBook(Book book) {
+        return book;
+    }
+    
+    public Book getFastinfoBook() {
+        return new Book("CXF2", 2L);
+    }
     
 }

Modified: cxf/branches/2.2.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java?rev=902178&r1=902177&r2=902178&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java
(original)
+++ cxf/branches/2.2.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java
Fri Jan 22 17:12:52 2010
@@ -45,6 +45,8 @@
 import org.apache.cxf.Bus;
 import org.apache.cxf.feature.AbstractFeature;
 import org.apache.cxf.helpers.IOUtils;
+import org.apache.cxf.interceptor.FIStaxInInterceptor;
+import org.apache.cxf.interceptor.FIStaxOutInterceptor;
 import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.interceptor.InterceptorProvider;
 import org.apache.cxf.io.CachedOutputStream;
@@ -55,6 +57,7 @@
 import org.apache.cxf.jaxrs.ext.form.Form;
 import org.apache.cxf.jaxrs.ext.xml.XMLSource;
 import org.apache.cxf.jaxrs.impl.MetadataMap;
+import org.apache.cxf.jaxrs.provider.JAXBElementProvider;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.phase.AbstractPhaseInterceptor;
 import org.apache.cxf.phase.Phase;
@@ -82,6 +85,50 @@
     }
     
     @Test
+    public void testGetBookFastinfoset() throws Exception {
+        
+        JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
+        bean.setAddress("http://localhost:9092/test/services/rest3/bookstore/fastinfoset2");
+        bean.getInInterceptors().add(new FIStaxInInterceptor());
+        JAXBElementProvider p = new JAXBElementProvider();
+        p.setConsumeMediaTypes(Collections.singletonList("application/fastinfoset"));
+        bean.setProvider(p);
+        
+        Map<String, Object> props = new HashMap<String, Object>();
+        props.put(FIStaxInInterceptor.FI_GET_SUPPORTED, Boolean.TRUE);
+        bean.setProperties(props);
+        
+        WebClient client = bean.createWebClient();
+        Book b = client.accept("application/fastinfoset").get(Book.class);
+        assertEquals("CXF2", b.getName());
+        assertEquals(2L, b.getId());
+    }
+    
+    @Test
+    public void testPostGetBookFastinfoset() throws Exception {
+        
+        JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
+        bean.setAddress("http://localhost:9092/test/services/rest3/bookstore/fastinfoset");
+        bean.getOutInterceptors().add(new FIStaxOutInterceptor());
+        bean.getInInterceptors().add(new FIStaxInInterceptor());
+        JAXBElementProvider p = new JAXBElementProvider();
+        p.setConsumeMediaTypes(Collections.singletonList("application/fastinfoset"));
+        p.setProduceMediaTypes(Collections.singletonList("application/fastinfoset"));
+        bean.setProvider(p);
+        
+        Map<String, Object> props = new HashMap<String, Object>();
+        props.put(FIStaxOutInterceptor.FI_ENABLED, Boolean.TRUE);
+        bean.setProperties(props);
+        
+        WebClient client = bean.createWebClient();
+        Book b = new Book("CXF", 1L);
+        Book b2 = client.type("application/fastinfoset").accept("application/fastinfoset")
+            .post(b, Book.class);
+        assertEquals(b2.getName(), b.getName());
+        assertEquals(b2.getId(), b.getId());
+    }
+    
+    @Test
     public void testGetBook123ServletResponse() throws Exception {
         
         InputStream in = getHttpInputStream("http://localhost:9092/test/services/rest/bookstore/0");

Modified: cxf/branches/2.2.x-fixes/systests/jaxrs/src/test/resources/jaxrs_soap_rest/WEB-INF/beans.xml
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/systests/jaxrs/src/test/resources/jaxrs_soap_rest/WEB-INF/beans.xml?rev=902178&r1=902177&r2=902178&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/systests/jaxrs/src/test/resources/jaxrs_soap_rest/WEB-INF/beans.xml
(original)
+++ cxf/branches/2.2.x-fixes/systests/jaxrs/src/test/resources/jaxrs_soap_rest/WEB-INF/beans.xml
Fri Jan 22 17:12:52 2010
@@ -22,8 +22,11 @@
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:jaxrs="http://cxf.apache.org/jaxrs"
   xmlns:jaxws="http://cxf.apache.org/jaxws"
+  xmlns:util="http://www.springframework.org/schema/util"
   xsi:schemaLocation="http://www.springframework.org/schema/beans 
 http://www.springframework.org/schema/beans/spring-beans.xsd
+http://www.springframework.org/schema/util 
+http://www.springframework.org/schema/util/spring-util-2.0.xsd
 http://cxf.apache.org/jaxws
 http://cxf.apache.org/schemas/jaxws.xsd
 http://cxf.apache.org/jaxrs
@@ -75,5 +78,39 @@
   </jaxrs:server>
   <bean id="bookstore2" class="org.apache.cxf.systest.jaxrs.BookStoreSoapRestImpl2"/>
 
+  <util:list id="fastinfosetType">
+    <value>application/fastinfoset</value>
+  </util:list> 
+
+
+  <jaxrs:server id="restservice3"
+		        address="/rest3">
+    <jaxrs:serviceBeans>
+      <ref bean="bookstore"/>
+    </jaxrs:serviceBeans>
+    
+    <jaxrs:providers>
+       <ref bean="jaxbProvider" />
+    </jaxrs:providers>
+        
+    <jaxrs:outInterceptors>
+      <ref bean="fastInfosetOutInterceptor" />
+    </jaxrs:outInterceptors>
+    <jaxrs:inInterceptors>
+      <ref bean="fastInfosetInInterceptor" />
+    </jaxrs:inInterceptors>
+    		   
+  </jaxrs:server> 
+
+  <bean id="jaxbProvider" class="org.apache.cxf.jaxrs.provider.JAXBElementProvider">
+      <property name="produceMediaTypes" ref="fastinfosetType"/>
+      <property name="consumeMediaTypes" ref="fastinfosetType"/>
+  </bean>
+
+   <bean id="fastInfosetOutInterceptor"
+         class="org.apache.cxf.interceptor.FIStaxOutInterceptor" />
+   <bean id="fastInfosetInInterceptor"
+         class="org.apache.cxf.interceptor.FIStaxInInterceptor" />
+
 </beans>
 <!-- END SNIPPET: beans -->



Mime
View raw message