cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r907887 - in /cxf/trunk/rt: core/src/main/java/org/apache/cxf/interceptor/ frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/ frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/in...
Date Tue, 09 Feb 2010 02:32:20 GMT
Author: dkulp
Date: Tue Feb  9 02:32:19 2010
New Revision: 907887

URL: http://svn.apache.org/viewvc?rev=907887&view=rev
Log:
Use the FI internal stuff directly.  The Stax factories are a LOT
slower and almost defeats the purpose of FI.

Modified:
    cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/FIStaxInInterceptor.java
    cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/FIStaxOutInterceptor.java
    cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/StaxOutInterceptor.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/MessageContextImpl.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java

Modified: cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/FIStaxInInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/FIStaxInInterceptor.java?rev=907887&r1=907886&r2=907887&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/FIStaxInInterceptor.java (original)
+++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/FIStaxInInterceptor.java Tue
Feb  9 02:32:19 2010
@@ -20,11 +20,11 @@
 package org.apache.cxf.interceptor;
 
 
+import java.io.InputStream;
 
-import javax.xml.stream.XMLInputFactory;
 import javax.xml.stream.XMLStreamReader;
 
-import com.sun.xml.fastinfoset.stax.factory.StAXInputFactory;
+import com.sun.xml.fastinfoset.stax.StAXDocumentParser;
 
 import org.apache.cxf.endpoint.Endpoint;
 import org.apache.cxf.message.Message;
@@ -37,8 +37,6 @@
  */
 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);
@@ -53,6 +51,14 @@
         return Boolean.TRUE.equals(message.containsKey(Message.REQUESTOR_ROLE));
     }
 
+    private synchronized StAXDocumentParser getParser(InputStream in) {
+        StAXDocumentParser parser = new StAXDocumentParser(in);
+        parser.setStringInterning(true);
+        parser.setForceStreamClose(true);
+        parser.setInputStream(in);
+        return parser;
+    }
+    
     public void handleMessage(Message message) {
         if (message.getContentFormats().contains(XMLStreamReader.class)
             || !isHttpVerbSupported(message)) {
@@ -60,8 +66,11 @@
         }
 
         String ct = (String)message.get(Message.CONTENT_TYPE);
-        if (ct != null && ct.indexOf("fastinfoset") != -1) {
-            message.put(XMLInputFactory.class.getName(), factory);
+        if (ct != null && ct.indexOf("fastinfoset") != -1 
+            && message.getContent(InputStream.class) != null
+            && message.getContent(XMLStreamReader.class) == null) {
+            message.setContent(XMLStreamReader.class, getParser(message.getContent(InputStream.class)));
+            
             ct = ct.replace("fastinfoset", "xml");
             if (ct.contains("application/xml")) {
                 ct = ct.replace("application/xml", "text/xml"); 

Modified: cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/FIStaxOutInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/FIStaxOutInterceptor.java?rev=907887&r1=907886&r2=907887&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/FIStaxOutInterceptor.java (original)
+++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/FIStaxOutInterceptor.java Tue
Feb  9 02:32:19 2010
@@ -20,15 +20,18 @@
 package org.apache.cxf.interceptor;
 
 
+import java.io.OutputStream;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
+import java.util.ResourceBundle;
 
-import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamWriter;
 
-import com.sun.xml.fastinfoset.stax.factory.StAXOutputFactory;
+import com.sun.xml.fastinfoset.stax.StAXDocumentSerializer;
 
+import org.apache.cxf.common.i18n.BundleUtils;
 import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.message.MessageUtils;
@@ -41,9 +44,11 @@
  */
 public class FIStaxOutInterceptor extends AbstractPhaseInterceptor<Message> {
     public static final String FI_ENABLED = "org.apache.cxf.fastinfoset.enabled";
-    
+    private static final String OUTPUT_STREAM_HOLDER = FIStaxOutInterceptor.class.getName()
+ ".outputstream";
+    private static final FIStaxOutEndingInterceptor ENDING = new FIStaxOutEndingInterceptor();
+    private static final ResourceBundle BUNDLE = BundleUtils.getBundle(FIStaxOutInterceptor.class);
+
     boolean force;
-    XMLOutputFactory factory = new StAXOutputFactory();
     
     public FIStaxOutInterceptor() {
         super(Phase.PRE_STREAM);
@@ -55,13 +60,22 @@
         force = f;
     }
     
-    
+    @Override
+    public void handleFault(Message message) {
+        super.handleFault(message);
+        OutputStream os = (OutputStream)message.get(OUTPUT_STREAM_HOLDER);
+        if (os != null) {
+            message.setContent(OutputStream.class, os);
+        }
+    }
     
     public void handleMessage(Message message) {
+        OutputStream out = message.getContent(OutputStream.class);
         XMLStreamWriter writer = message.getContent(XMLStreamWriter.class);
-        if (writer != null) {
+        if (out == null || writer != null) {
             return;
-        }
+        } 
+        
         boolean req = isRequestor(message);
         Object o = message.getContextualProperty(FI_ENABLED);
         if (!req) {
@@ -91,9 +105,14 @@
             
         if (force 
             || MessageUtils.isTrue(o)) {
+            StAXDocumentSerializer serializer = getOutput(message, out);
+            message.setContent(XMLStreamWriter.class, serializer);
             
-            message.put(XMLOutputFactory.class.getName(),
-                        factory);
+            message.removeContent(OutputStream.class);
+            message.put(OUTPUT_STREAM_HOLDER, out);
+            message.put(AbstractOutDatabindingInterceptor.DISABLE_OUTPUTSTREAM_OPTIMIZATION,
+                  Boolean.TRUE);
+
             String s = (String)message.get(Message.CONTENT_TYPE);
             if (s.contains("application/soap+xml")) {
                 s = s.replace("application/soap+xml", "application/soap+fastinfoset");
@@ -101,7 +120,61 @@
             } else {
                 message.put(Message.CONTENT_TYPE, "application/fastinfoset");
             }
+            
+            try {
+                serializer.writeStartDocument();
+            } catch (XMLStreamException e) {
+                throw new Fault(e);
+            }
+            message.getInterceptorChain().add(ENDING);
+        }
+    }
+    
+    private StAXDocumentSerializer getOutput(Message m, OutputStream out) {
+        /*
+        StAXDocumentSerializer serializer = (StAXDocumentSerializer)m.getExchange().get(Endpoint.class)
+            .remove(StAXDocumentSerializer.class.getName());
+        if (serializer != null) {
+            serializer.setOutputStream(out);
+        } else {
+            serializer = new StAXDocumentSerializer(out);
         }
+        return serializer;
+        */
+        return new StAXDocumentSerializer(out);
     }
+    public static class FIStaxOutEndingInterceptor extends AbstractPhaseInterceptor<Message>
{
+        public FIStaxOutEndingInterceptor() {
+            super(Phase.PRE_STREAM_ENDING);
+            getAfter().add(AttachmentOutInterceptor.AttachmentOutEndingInterceptor.class.getName());
+        }
+
+        public void handleMessage(Message message) throws Fault {
+            try {
+                XMLStreamWriter xtw = message.getContent(XMLStreamWriter.class);
+                if (xtw != null) {
+                    xtw.writeEndDocument();
+                    xtw.flush();
+                    xtw.close();
+                }
+                /*
+                if (xtw instanceof StAXDocumentSerializer) {
+                    ((StAXDocumentSerializer)xtw).setOutputStream(null);
+                    message.getExchange().get(Endpoint.class)
+                        .put(StAXDocumentSerializer.class.getName(), xtw);
+                }
+                */
+
+                OutputStream os = (OutputStream)message.get(OUTPUT_STREAM_HOLDER);
+                if (os != null) {
+                    message.setContent(OutputStream.class, os);
+                }
+                message.removeContent(XMLStreamWriter.class);
+            } catch (XMLStreamException e) {
+                throw new Fault(new org.apache.cxf.common.i18n.Message("STAX_WRITE_EXC",
BUNDLE), e);
+            }
+        }
+
+    }    
 
 }

Modified: cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/StaxOutInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/StaxOutInterceptor.java?rev=907887&r1=907886&r2=907887&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/StaxOutInterceptor.java (original)
+++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/StaxOutInterceptor.java Tue
Feb  9 02:32:19 2010
@@ -161,6 +161,7 @@
                 XMLStreamWriter xtw = message.getContent(XMLStreamWriter.class);
                 if (xtw != null) {
                     xtw.writeEndDocument();
+                    xtw.flush();
                     xtw.close();
                 }
 

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java?rev=907887&r1=907886&r2=907887&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
Tue Feb  9 02:32:19 2010
@@ -355,7 +355,9 @@
         if (mbw != null) {
             try {
                 mbw.writeTo(o, cls, type, anns, contentType, headers, os);
-                os.flush();
+                if (os != null) {
+                    os.flush();
+                }
             } catch (Exception ex) {
                 throw new WebApplicationException(ex);
             }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java?rev=907887&r1=907886&r2=907887&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java Tue
Feb  9 02:32:19 2010
@@ -39,6 +39,7 @@
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.Response.ResponseBuilder;
 import javax.ws.rs.core.UriBuilder;
+import javax.xml.stream.XMLStreamWriter;
 
 
 import org.apache.cxf.Bus;
@@ -620,7 +621,8 @@
         public void handleMessage(Message outMessage) throws Fault {
             
             OutputStream os = outMessage.getContent(OutputStream.class);
-            if (os == null) {
+            XMLStreamWriter writer = outMessage.getContent(XMLStreamWriter.class);
+            if (os == null && writer == null) {
                 return;
             }
             MessageContentsList objs = MessageContentsList.getContentsList(outMessage);
@@ -633,7 +635,9 @@
             try {
                 writeBody(body, outMessage, body.getClass(), body.getClass(), new Annotation[]{},

                           headers, os);
-                os.flush();
+                if (os != null) {
+                    os.flush();
+                }
             } catch (Exception ex) {
                 throw new Fault(ex);
             }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/MessageContextImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/MessageContextImpl.java?rev=907887&r1=907886&r2=907887&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/MessageContextImpl.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/MessageContextImpl.java
Tue Feb  9 02:32:19 2010
@@ -83,6 +83,10 @@
     }
     
     public <T> T getContent(Class<T> format) {
+        if (isRequestor() && m.getExchange().getInMessage() != null) {
+            Message inMessage = m.getExchange().getInMessage();
+            return inMessage.getContent(format);
+        } 
         return m.getContent(format);
     }
     

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java?rev=907887&r1=907886&r2=907887&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
Tue Feb  9 02:32:19 2010
@@ -47,6 +47,7 @@
 import org.apache.cxf.interceptor.AbstractOutDatabindingInterceptor;
 import org.apache.cxf.io.CachedOutputStream;
 import org.apache.cxf.jaxrs.ext.ResponseHandler;
+import org.apache.cxf.jaxrs.impl.MetadataMap;
 import org.apache.cxf.jaxrs.lifecycle.ResourceProvider;
 import org.apache.cxf.jaxrs.model.ClassResourceInfo;
 import org.apache.cxf.jaxrs.model.OperationResourceInfo;
@@ -169,9 +170,15 @@
         } else {
             message.put(Message.PROTOCOL_HEADERS, response.getMetadata());
         }
-        MultivaluedMap<String, Object> responseHeaders = 
-            (MultivaluedMap)message.get(Message.PROTOCOL_HEADERS);
-        setResponseDate(responseHeaders, firstTry);
+        Map<String, List<Object>> rh = 
+            (Map<String, List<Object>>)message.get(Message.PROTOCOL_HEADERS);
+        MultivaluedMap<String, Object> responseHeaders;
+        if (!(rh instanceof MultivaluedMap)) {
+            responseHeaders = new MetadataMap<String, Object>(rh);
+        } else {
+            responseHeaders = (MultivaluedMap)rh;
+        }
+        setResponseDate((MultivaluedMap)responseHeaders, firstTry);
         if (isResponseNull(responseObj)) {
             return;
         }

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=907887&r1=907886&r2=907887&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 Feb  9 02:32:19 2010
@@ -189,7 +189,6 @@
     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) {
@@ -335,9 +334,17 @@
         XMLStreamWriter writer = getStreamWriter(obj, os, mt);
         if (writer != null) {
             if (mc != null) {
+                if (mc.getContent(XMLStreamWriter.class) != null) {
+                    ms.setProperty(Marshaller.JAXB_FRAGMENT, true);
+                }
                 mc.put(XMLStreamWriter.class.getName(), writer);
-            }
+            }    
             marshalToWriter(ms, obj, writer, mt);
+            if (mc != null && mc.getContent(XMLStreamWriter.class) != null) {
+                writer.writeEndDocument();
+                writer.flush();
+                writer.close();
+            }
         } else {
             marshalToOutputStream(ms, obj, os, mt);
         }



Mime
View raw message