cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject svn commit: r1476727 - in /cxf/trunk: api/src/main/java/org/apache/cxf/staxutils/ rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/encoded/ rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/logical/ systests/jaxws/src/test/java/o...
Date Sun, 28 Apr 2013 07:53:44 GMT
Author: ningjiang
Date: Sun Apr 28 07:53:43 2013
New Revision: 1476727

URL: http://svn.apache.org/r1476727
Log:
CXF-4990 fixed the namespace issue when thrown the fault from logical handle.

Added:
    cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/handlers/CustomSoapFault.java
    cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/handlers/FaultThrowingHandler.java
    cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/handlers/SoapFaultHandlerTest.java
    cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/handlers/soap_fault_beans.xml
Modified:
    cxf/trunk/api/src/main/java/org/apache/cxf/staxutils/W3CDOMStreamWriter.java
    cxf/trunk/api/src/main/java/org/apache/cxf/staxutils/W3CNamespaceContext.java
    cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/encoded/AbstractEncodedTest.java
    cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/logical/LogicalHandlerFaultOutInterceptor.java

Modified: cxf/trunk/api/src/main/java/org/apache/cxf/staxutils/W3CDOMStreamWriter.java
URL: http://svn.apache.org/viewvc/cxf/trunk/api/src/main/java/org/apache/cxf/staxutils/W3CDOMStreamWriter.java?rev=1476727&r1=1476726&r2=1476727&view=diff
==============================================================================
--- cxf/trunk/api/src/main/java/org/apache/cxf/staxutils/W3CDOMStreamWriter.java (original)
+++ cxf/trunk/api/src/main/java/org/apache/cxf/staxutils/W3CDOMStreamWriter.java Sun Apr 28
07:53:43 2013
@@ -120,7 +120,10 @@ public class W3CDOMStreamWriter implemen
             }
         }
         if (!(context instanceof W3CNamespaceContext)) {
-            context = new W3CNamespaceContext();
+            // set the outside namespace context
+            W3CNamespaceContext childContext = new W3CNamespaceContext();
+            childContext.setOutNamespaceContext(context);
+            context = childContext;
         }
         ((W3CNamespaceContext)context).setElement(element);
         currentNode = element;

Modified: cxf/trunk/api/src/main/java/org/apache/cxf/staxutils/W3CNamespaceContext.java
URL: http://svn.apache.org/viewvc/cxf/trunk/api/src/main/java/org/apache/cxf/staxutils/W3CNamespaceContext.java?rev=1476727&r1=1476726&r2=1476727&view=diff
==============================================================================
--- cxf/trunk/api/src/main/java/org/apache/cxf/staxutils/W3CNamespaceContext.java (original)
+++ cxf/trunk/api/src/main/java/org/apache/cxf/staxutils/W3CNamespaceContext.java Sun Apr
28 07:53:43 2013
@@ -32,12 +32,18 @@ import org.w3c.dom.Node;
 
 public class W3CNamespaceContext implements NamespaceContext {
     private Element currentNode;
+    private NamespaceContext outNamespaceContext;
     
     public W3CNamespaceContext() {
     }
     public W3CNamespaceContext(Element el) {
         currentNode = el;
     }
+    
+    public void setOutNamespaceContext(NamespaceContext context) {
+        outNamespaceContext = context;
+    }
+    
     public String getNamespaceURI(String prefix) {
         String name = prefix;
         if (name.length() == 0) {
@@ -53,7 +59,14 @@ public class W3CNamespaceContext impleme
         if (e == null) {
             return null;
         }
-
+        // check the outside namespace URI
+        if (outNamespaceContext != null) {
+            String result = outNamespaceContext.getNamespaceURI(name);
+            if (result != null) {
+                return result;
+            }
+        }
+        
         Attr attr = e.getAttributeNode(name);
         if (attr == null) {
             Node n = e.getParentNode();
@@ -75,6 +88,14 @@ public class W3CNamespaceContext impleme
         if (e == null) {
             return null;
         }
+        // check the outside namespace URI
+        if (outNamespaceContext != null) {
+            String result = outNamespaceContext.getPrefix(uri);
+            if (result != null) {
+                return result;
+            }
+        }
+        
         NamedNodeMap attributes = e.getAttributes();
         if (attributes != null) {
             for (int i = 0; i < attributes.getLength(); i++) {

Modified: cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/encoded/AbstractEncodedTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/encoded/AbstractEncodedTest.java?rev=1476727&r1=1476726&r2=1476727&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/encoded/AbstractEncodedTest.java
(original)
+++ cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/encoded/AbstractEncodedTest.java
Sun Apr 28 07:53:43 2013
@@ -21,7 +21,6 @@ package org.apache.cxf.aegis.type.encode
 import java.io.ByteArrayInputStream;
 import java.io.UnsupportedEncodingException;
 import java.util.List;
-import java.util.Map;
 
 import javax.xml.stream.XMLStreamException;
 
@@ -89,7 +88,7 @@ public abstract class AbstractEncodedTes
 
         // write value to element
         Element element = writeRef(value);
-
+        
         // reread value from element
         value = typeClass.cast(readRef(element));
 
@@ -143,9 +142,10 @@ public abstract class AbstractEncodedTes
         // create the document
         Element element = createElement("urn:Bean", "root", "b");
         MapNamespaceContext namespaces = new MapNamespaceContext();
-        for (Map.Entry<String, String> entry : getNamespaces().entrySet()) {
+        // we should not add the out namespace here, as it is not a part of root element

+        /*for (Map.Entry<String, String> entry : getNamespaces().entrySet()) {
             namespaces.addNamespace(entry.getKey(), entry.getValue());
-        }
+        }*/
         ElementWriter rootWriter = getElementWriter(element, namespaces);
         Context context = getContext();
 

Modified: cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/logical/LogicalHandlerFaultOutInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/logical/LogicalHandlerFaultOutInterceptor.java?rev=1476727&r1=1476726&r2=1476727&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/logical/LogicalHandlerFaultOutInterceptor.java
(original)
+++ cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/logical/LogicalHandlerFaultOutInterceptor.java
Sun Apr 28 07:53:43 2013
@@ -73,7 +73,12 @@ public class LogicalHandlerFaultOutInter
             Document doc = XMLUtils.newDocument();
             message.setContent(Node.class, doc);
             W3CDOMStreamWriter writer = new W3CDOMStreamWriter(doc);
-        
+            // set up the namespace context
+            try {
+                writer.setNamespaceContext(origWriter.getNamespaceContext());
+            } catch (XMLStreamException ex) {
+                // don't set the namespaceContext
+            }
             // Replace stax writer with DomStreamWriter
             message.setContent(XMLStreamWriter.class, writer);
             message.put(ORIGINAL_WRITER, origWriter);
@@ -81,7 +86,7 @@ public class LogicalHandlerFaultOutInter
             message.getInterceptorChain().add(ending);
         } catch (ParserConfigurationException e) {
             throw new Fault(e);
-        }
+        } 
     }
     
     

Added: cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/handlers/CustomSoapFault.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/handlers/CustomSoapFault.java?rev=1476727&view=auto
==============================================================================
--- cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/handlers/CustomSoapFault.java
(added)
+++ cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/handlers/CustomSoapFault.java
Sun Apr 28 07:53:43 2013
@@ -0,0 +1,31 @@
+/**
+ * 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.systest.handlers;
+
+import javax.xml.namespace.QName;
+
+import org.apache.cxf.binding.soap.SoapFault;
+
+public class CustomSoapFault extends SoapFault {
+    private static final long serialVersionUID = 1L;
+
+    public CustomSoapFault() {
+        super("faultstring", new QName("http://cxf.apache.org/handler_test/types", "Provider",
"cxf"));
+    }
+}

Added: cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/handlers/FaultThrowingHandler.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/handlers/FaultThrowingHandler.java?rev=1476727&view=auto
==============================================================================
--- cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/handlers/FaultThrowingHandler.java
(added)
+++ cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/handlers/FaultThrowingHandler.java
Sun Apr 28 07:53:43 2013
@@ -0,0 +1,42 @@
+/**
+ * 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.systest.handlers;
+
+import javax.xml.ws.handler.LogicalHandler;
+import javax.xml.ws.handler.LogicalMessageContext;
+import javax.xml.ws.handler.MessageContext;
+
+public class FaultThrowingHandler implements LogicalHandler<LogicalMessageContext>
{
+
+    @Override
+    public boolean handleMessage(LogicalMessageContext context) {
+        throw new CustomSoapFault();
+    }
+
+    @Override
+    public boolean handleFault(LogicalMessageContext context) {
+        return false;
+    }
+
+    @Override
+    public void close(MessageContext context) {
+
+    }
+
+}

Added: cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/handlers/SoapFaultHandlerTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/handlers/SoapFaultHandlerTest.java?rev=1476727&view=auto
==============================================================================
--- cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/handlers/SoapFaultHandlerTest.java
(added)
+++ cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/handlers/SoapFaultHandlerTest.java
Sun Apr 28 07:53:43 2013
@@ -0,0 +1,88 @@
+/**
+ * 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.systest.handlers;
+
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.HttpURLConnection;
+import java.net.URL;
+
+import org.apache.cxf.helpers.IOUtils;
+import org.apache.cxf.test.AbstractCXFSpringTest;
+import org.apache.cxf.testutil.common.TestUtil;
+
+import org.junit.Test;
+
+public class SoapFaultHandlerTest extends AbstractCXFSpringTest {
+
+    static String port = TestUtil.getPortNumber("SoapFaultHandler");
+    static String addNumbersAddress = "http://localhost:" + port + "/SpringEndpoint";
+   
+    @Override
+    protected String[] getConfigLocations() {
+        return new String[] {"classpath:/org/apache/cxf/systest/handlers/soap_fault_beans.xml"
};
+    }
+    
+    @Test
+    public void testFaultThrowingHandler() throws Exception {
+        // set the post request using url connection
+        URL postUrl = new URL(addNumbersAddress);
+        HttpURLConnection connection = (HttpURLConnection) postUrl.openConnection();
+        connection.setRequestMethod("POST");
+        connection.setDoOutput(true);
+        connection.setDoInput(true);
+        connection.setRequestProperty("Content-Type",
+            "text/xml; charset=UTF-8");
+        connection.connect();
+        DataOutputStream out = new DataOutputStream(connection.getOutputStream());
+        InputStream is = this.getClass().getResourceAsStream("resources/GreetMeDocLiteralReq.xml");
+        
+        IOUtils.copyAndCloseInput(is, out);
+        out.flush();
+        out.close();
+        InputStream response = getInputStream(connection);
+        // get the response fault message
+        String result = IOUtils.toString(response, "UTF-8");
+        // just make sure the custom namespace is working
+        assertTrue("The custom namespace is not working.", result.indexOf("cxf:Provider")
> 0);
+        
+    }
+    
+    protected InputStream getInputStream(HttpURLConnection connection) throws IOException
{
+        InputStream in = null;
+        if (connection.getResponseCode() >= HttpURLConnection.HTTP_BAD_REQUEST) {
+            in = connection.getErrorStream();
+            if (in == null) {
+                try {
+                    // just in case - but this will most likely cause an exception
+                    in = connection.getInputStream();
+                } catch (IOException ex) {
+                    // ignore
+                }
+            }
+        } else {
+            in = connection.getInputStream();
+        }
+        return in;
+    }
+    
+    
+
+}

Added: cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/handlers/soap_fault_beans.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/handlers/soap_fault_beans.xml?rev=1476727&view=auto
==============================================================================
--- cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/handlers/soap_fault_beans.xml
(added)
+++ cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/handlers/soap_fault_beans.xml
Sun Apr 28 07:53:43 2013
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="UTF-8"?> 
+<!--
+  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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans" 
+xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
+xmlns:jaxws="http://cxf.apache.org/jaxws" 
+xmlns:cxf="http://cxf.apache.org/core" 
+xsi:schemaLocation=" 
+http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd

+http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd 
+http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd"> 
+ 
+	<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/>
+	
+	<jaxws:endpoint id="cxfHandlerTestEndpoint"
+		implementor="org.apache.cxf.systest.handlers.AddNumbersNoHandlers"
+		address="http://localhost:${testutil.ports.SoapFaultHandler}/SpringEndpoint">
+    	<jaxws:properties>
+    	     <entry key="soap.env.ns.map">
+				<map>
+					<entry key="cxf" value="http://cxf.apache.org/handler_test/types" />
+				</map>
+			</entry>
+    	</jaxws:properties>
+    	<jaxws:handlers>
+    		<bean class="org.apache.cxf.systest.handlers.FaultThrowingHandler"/>
+    	</jaxws:handlers>
+    	
+    </jaxws:endpoint> 
+	
+    <jaxws:client id="cxfHandlerTestClientEndpoint"
+    	serviceClass="org.apache.handlers.AddNumbers"
+    	address="http://localhost:${testutil.ports.SoapFaultHandler}/SpringEndpoint">
+    </jaxws:client> 
+    
+    
+</beans> 



Mime
View raw message