You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by aj...@apache.org on 2007/11/26 18:45:21 UTC

svn commit: r598358 - in /incubator/cxf/trunk/rt/frontend/jaxws/src: main/java/org/apache/cxf/jaxws/interceptors/ test/java/org/apache/cxf/jaxws/interceptors/

Author: ajaypaibir
Date: Mon Nov 26 09:45:15 2007
New Revision: 598358

URL: http://svn.apache.org/viewvc?rev=598358&view=rev
Log:
CXF-1238 DispatchInDataBindingInterceptor assumes incoming message to have been read removes out the inputstream from the message.

Added:
    incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/interceptors/
    incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/interceptors/DispatchInDatabindingInterceptorTest.java   (with props)
Modified:
    incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/DispatchInDatabindingInterceptor.java

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/DispatchInDatabindingInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/DispatchInDatabindingInterceptor.java?rev=598358&r1=598357&r2=598358&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/DispatchInDatabindingInterceptor.java (original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/DispatchInDatabindingInterceptor.java Mon Nov 26 09:45:15 2007
@@ -115,6 +115,7 @@
      
         try {
             InputStream is = message.getContent(InputStream.class);
+            boolean msgRead = false;
             Object obj = null;
             ex.put(Service.Mode.class, mode);            
             
@@ -123,7 +124,8 @@
                 PostDispatchSOAPHandlerInterceptor postSoap = new PostDispatchSOAPHandlerInterceptor();
                 message.getInterceptorChain().add(postSoap);
                 
-                message.setContent(SOAPMessage.class, soapMessage);               
+                message.setContent(SOAPMessage.class, soapMessage); 
+                msgRead = true;
             } else if (message instanceof XMLMessage) {
                 if (type.equals(DataSource.class)) {
                     try {
@@ -145,18 +147,22 @@
                     obj = dataReader.read(null, message.getContent(XMLStreamReader.class), readType);
                     message.setContent(Source.class, obj); 
                 }
+                msgRead = true;
             }
-    
-            PostDispatchLogicalHandlerInterceptor postLogical = new PostDispatchLogicalHandlerInterceptor();
-            message.getInterceptorChain().add(postLogical);      
             
-            is.close();
-            message.removeContent(InputStream.class);
+            if (msgRead) {
+                PostDispatchLogicalHandlerInterceptor postLogical = 
+                    new PostDispatchLogicalHandlerInterceptor();
+                message.getInterceptorChain().add(postLogical);      
+                
+                is.close();
+                message.removeContent(InputStream.class);
+            }
         } catch (Exception e) {
             throw new Fault(e);
         }
     }
-
+    
     private SOAPMessage newSOAPMessage(InputStream is, SoapMessage msg) throws Exception {
         SoapVersion version = msg.getVersion();
 

Added: incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/interceptors/DispatchInDatabindingInterceptorTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/interceptors/DispatchInDatabindingInterceptorTest.java?rev=598358&view=auto
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/interceptors/DispatchInDatabindingInterceptorTest.java (added)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/interceptors/DispatchInDatabindingInterceptorTest.java Mon Nov 26 09:45:15 2007
@@ -0,0 +1,93 @@
+/**
+ * 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.
+ */
+
+package org.apache.cxf.jaxws.interceptors;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Iterator;
+
+import org.apache.cxf.endpoint.Endpoint;
+import org.apache.cxf.interceptor.Interceptor;
+import org.apache.cxf.interceptor.InterceptorChain;
+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.phase.PhaseInterceptorChain;
+import org.apache.cxf.phase.PhaseManagerImpl;
+import org.apache.cxf.service.model.BindingInfo;
+import org.apache.cxf.service.model.BindingOperationInfo;
+import org.apache.cxf.service.model.EndpointInfo;
+import org.apache.cxf.service.model.MessageInfo;
+
+import org.easymock.classextension.EasyMock;
+import org.easymock.classextension.IMocksControl;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+public class DispatchInDatabindingInterceptorTest extends Assert {
+    private DispatchInDatabindingInterceptor didi = new DispatchInDatabindingInterceptor(null, null);
+    private Message msg = new MessageImpl();
+    private Exchange ex = new ExchangeImpl();
+    private IMocksControl control = EasyMock.createNiceControl();
+    
+    @Before
+    public void setUp() throws Exception {
+        msg.setExchange(ex);
+        msg.setInterceptorChain(
+               new PhaseInterceptorChain(
+                      new PhaseManagerImpl().getInPhases()));
+        msg.setContent(InputStream.class, new ByteArrayInputStream("abcdf".getBytes()));
+    }
+
+    @After
+    public void tearDown() throws Exception {
+        msg.clear();
+    }
+
+    @Test
+    public void testHandleMessageForNonSoapOrXml() throws Exception {
+        Endpoint ep = control.createMock(Endpoint.class);
+        ex.put(Endpoint.class, ep);
+        MessageInfo mi = control.createMock(MessageInfo.class);
+        msg.put(MessageInfo.class, mi);
+        EndpointInfo ei = control.createMock(EndpointInfo.class);
+        EasyMock.expect(ep.getEndpointInfo()).andReturn(ei).anyTimes();
+        BindingInfo bi = control.createMock(BindingInfo.class);
+        EasyMock.expect(ei.getBinding()).andReturn(bi).anyTimes();
+        EasyMock.expect(bi.getOperations()).andReturn(new ArrayList<BindingOperationInfo>()).anyTimes();
+        control.replay();
+        didi.handleMessage(msg);
+        control.reset();
+        
+        InterceptorChain ic = msg.getInterceptorChain();
+        assertNotNull(ic);
+        //For Non Soap or XML Binding the inputstream could be read by a interceptor before or after
+        //DispatchInDataBindingInterceptor so no assumptions should be made.
+        Iterator<Interceptor <? extends Message>> iter = msg.getInterceptorChain().iterator();
+        assertFalse("No Interceptors should be in the chain",  iter.hasNext());
+        
+        assertNotNull("InputStream should not be removed", 
+                      msg.getContent(InputStream.class));
+    }
+}

Propchange: incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/interceptors/DispatchInDatabindingInterceptorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/interceptors/DispatchInDatabindingInterceptorTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date