Author: dkulp
Date: Tue Jan  5 22:25:39 2010
New Revision: 896248

URL: http://svn.apache.org/viewvc?rev=896248&view=rev
Log:
[CXF-2601] Fix problems with XmlBeans and non-document fault infos

Modified:
    
cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/CachingXmlEventWriter.java
    
cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java
    
cxf/trunk/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/DataWriterImpl.java
    
cxf/trunk/systests/databinding/src/test/java/org/apache/cxf/systest/xmlbeans/ClientServerXmlBeansTest.java
    
cxf/trunk/systests/databinding/src/test/java/org/apache/cxf/systest/xmlbeans/GreeterImpl.java
    
cxf/trunk/systests/databinding/src/test/resources/wsdl_systest_databinding/xmlbeans/hello_world.wsdl

Modified: 
cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/CachingXmlEventWriter.java
URL: 
http://svn.apache.org/viewvc/cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/CachingXmlEventWriter.java?rev=896248&r1=896247&r2=896248&view=diff
==============================================================================
--- 
cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/CachingXmlEventWriter.java
 (original)
+++ 
cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/CachingXmlEventWriter.java
 Tue Jan  5 22:25:39 2010
@@ -147,7 +147,7 @@
     }
     
     public void setDefaultNamespace(String ns) throws XMLStreamException {
-        writeNamespace("", ns);
+        curContext.addNs("", ns);
     }
 
     

Modified: 
cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java
URL: 
http://svn.apache.org/viewvc/cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java?rev=896248&r1=896247&r2=896248&view=diff
==============================================================================
--- 
cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java 
(original)
+++ 
cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java 
Tue Jan  5 22:25:39 2010
@@ -467,6 +467,19 @@
         
 //        System.out.println("STAXUTILS:writeStartElement : node name : " + 
local +  " namespace URI" + uri);
         boolean writeElementNS = false;
+        
+     // Write out the element name
+        if (uri != null) {
+            if (prefix.length() == 0 && StringUtils.isEmpty(uri)) {
+                writer.writeStartElement(local);
+            } else {
+                writer.writeStartElement(prefix, local, uri);
+            }
+        } else {
+            writer.writeStartElement(local);
+        }
+
+        
         if (uri != null) {
             writeElementNS = true;
             Iterator<String> it = 
CastUtils.cast(writer.getNamespaceContext().getPrefixes(uri));
@@ -481,20 +494,6 @@
             }
         }
 
-        // Write out the element name
-        if (uri != null) {
-            if (prefix.length() == 0 && StringUtils.isEmpty(uri)) {
-                writer.writeStartElement(local);
-                writer.setDefaultNamespace(uri);
-
-            } else {
-                writer.writeStartElement(prefix, local, uri);
-                writer.setPrefix(prefix, uri);
-            }
-        } else {
-            writer.writeStartElement(local);
-        }
-
         // Write out the namespaces
         for (int i = 0; i < reader.getNamespaceCount(); i++) {
             String nsURI = reader.getNamespaceURI(i);

Modified: 
cxf/trunk/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/DataWriterImpl.java
URL: 
http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/DataWriterImpl.java?rev=896248&r1=896247&r2=896248&view=diff
==============================================================================
--- 
cxf/trunk/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/DataWriterImpl.java
 (original)
+++ 
cxf/trunk/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/DataWriterImpl.java
 Tue Jan  5 22:25:39 2010
@@ -144,8 +144,13 @@
                     reader = source.newCursor().newXMLStreamReader(options);   
                 
                 }
                 SchemaType st = 
(SchemaType)part.getProperty(SchemaType.class.getName());
-
-                if (st != null && !st.isDocumentType()) {
+                int i = reader.getEventType();
+                if (i == XMLStreamReader.START_DOCUMENT) {
+                    i = reader.next();
+                }
+                
+                if (st != null && !st.isDocumentType()
+                    || reader.getEventType() == XMLStreamReader.CHARACTERS) {
                     if 
(StringUtils.isEmpty(part.getConcreteName().getNamespaceURI())) {
                         
output.writeStartElement(part.getConcreteName().getLocalPart());
                         

Modified: 
cxf/trunk/systests/databinding/src/test/java/org/apache/cxf/systest/xmlbeans/ClientServerXmlBeansTest.java
URL: 
http://svn.apache.org/viewvc/cxf/trunk/systests/databinding/src/test/java/org/apache/cxf/systest/xmlbeans/ClientServerXmlBeansTest.java?rev=896248&r1=896247&r2=896248&view=diff
==============================================================================
--- 
cxf/trunk/systests/databinding/src/test/java/org/apache/cxf/systest/xmlbeans/ClientServerXmlBeansTest.java
 (original)
+++ 
cxf/trunk/systests/databinding/src/test/java/org/apache/cxf/systest/xmlbeans/ClientServerXmlBeansTest.java
 Tue Jan  5 22:25:39 2010
@@ -35,22 +35,23 @@
 import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
 import org.apache.helloWorldSoapHttp.xmlbeans.types.FaultDetailDocument;
 import 
org.apache.helloWorldSoapHttp.xmlbeans.types.FaultDetailDocument.FaultDetail;
+import org.apache.hello_world_soap_http.xmlbeans.GreetMeFault;
 import org.apache.hello_world_soap_http.xmlbeans.Greeter;
 import org.apache.hello_world_soap_http.xmlbeans.PingMeFault;
 import org.apache.hello_world_soap_http.xmlbeans.SOAPService;
 import org.junit.BeforeClass;
-import org.junit.Ignore;
 import org.junit.Test;
 
 /**
  * 
  */
-...@ignore("randomly fails on Hudson, but dkulp cannot reproduce yet")
+//@org.junit.Ignore("randomly fails on Hudson, but dkulp cannot reproduce yet")
 public class ClientServerXmlBeansTest extends AbstractBusClientServerTestBase {
     
     private static final QName SERVICE_NAME 
         = new QName("http://apache.org/hello_world_soap_http/xmlbeans";, 
"SOAPService");
     
+    
     @BeforeClass
     public static void startServers() throws Exception {
         assertTrue("server did not launch correctly", 
launchServer(Server.class, true));
@@ -71,11 +72,18 @@
         ClientProxy.getClient(port).getInInterceptors().add(new 
LoggingInInterceptor());
         ClientProxy.getClient(port).getOutInterceptors().add(new 
LoggingOutInterceptor());
         resp = port.sayHi();
-        assertEquals("We should get the right response", resp, "Bonjour");     
   
+        assertEquals("We should get the right response", "Bonjour", resp);     
   
         
         resp = port.greetMe("Willem");
-        assertEquals("We should get the right response", resp, "Hello Willem");
-        
+        assertEquals("We should get the right response", "Hello Willem", resp);
+
+        try {
+            port.greetMe("fault");
+            fail("Should have been a fault");
+        } catch (GreetMeFault ex) {
+            assertEquals("Some fault detail", 
ex.getFaultInfo().getStringValue());
+        }
+
         try {
             resp = port.greetMe("Invoking greetMe with invalid length string, 
expecting exception...");
             fail("We expect exception here");
@@ -85,8 +93,6 @@
                        indexOf("string length (67) is greater than maxLength 
facet (30)") >= 0);
         }
         
-        port.greetMeOneWay(System.getProperty("user.name"));
-        
         try {
             port.pingMe();
             fail("We expect exception here");
@@ -95,7 +101,8 @@
             FaultDetail detail = detailDocument.getFaultDetail();
             assertEquals("Wrong faultDetail major", detail.getMajor(), 2);
             assertEquals("Wrong faultDetail minor", detail.getMinor(), 1);     
        
-        }          
+        }
+        
     }
     
     @Test
@@ -128,8 +135,6 @@
                        indexOf("string length (67) is greater than maxLength 
facet (30)") >= 0);
         }
         
-        port.greetMeOneWay(System.getProperty("user.name"));
-        
         try {
             port.pingMe();
             fail("We expect exception here");
@@ -138,7 +143,14 @@
             FaultDetail detail = detailDocument.getFaultDetail();
             assertEquals("Wrong faultDetail major", detail.getMajor(), 2);
             assertEquals("Wrong faultDetail minor", detail.getMinor(), 1);     
        
-        }          
+        }  
+        try {
+            port.greetMe("fault");
+            fail("Should have been a fault");
+        } catch (GreetMeFault ex) {
+            assertEquals("Some fault detail", 
ex.getFaultInfo().getStringValue());
+        }
+
     }
 
 }

Modified: 
cxf/trunk/systests/databinding/src/test/java/org/apache/cxf/systest/xmlbeans/GreeterImpl.java
URL: 
http://svn.apache.org/viewvc/cxf/trunk/systests/databinding/src/test/java/org/apache/cxf/systest/xmlbeans/GreeterImpl.java?rev=896248&r1=896247&r2=896248&view=diff
==============================================================================
--- 
cxf/trunk/systests/databinding/src/test/java/org/apache/cxf/systest/xmlbeans/GreeterImpl.java
 (original)
+++ 
cxf/trunk/systests/databinding/src/test/java/org/apache/cxf/systest/xmlbeans/GreeterImpl.java
 Tue Jan  5 22:25:39 2010
@@ -24,6 +24,7 @@
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.helloWorldSoapHttp.xmlbeans.types.FaultDetailDocument;
 import 
org.apache.helloWorldSoapHttp.xmlbeans.types.FaultDetailDocument.FaultDetail;
+import org.apache.hello_world_soap_http.xmlbeans.GreetMeFault;
 import org.apache.hello_world_soap_http.xmlbeans.Greeter;
 import org.apache.hello_world_soap_http.xmlbeans.PingMeFault;
 
@@ -37,7 +38,12 @@
     /* (non-Javadoc)
      * @see org.apache.hello_world_soap_http.Greeter#greetMe(java.lang.String)
      */
-    public String greetMe(String me) {
+    public String greetMe(String me) throws GreetMeFault {
+        if ("fault".equals(me)) {
+            org.apache.xmlbeans.XmlString st = 
org.apache.xmlbeans.XmlString.Factory.newInstance();
+            st.setStringValue("Some fault detail");
+            throw new GreetMeFault("Fault String", st);
+        }
         LOG.info("Executing operation greetMe");        
         return "Hello " + me;
     }

Modified: 
cxf/trunk/systests/databinding/src/test/resources/wsdl_systest_databinding/xmlbeans/hello_world.wsdl
URL: 
http://svn.apache.org/viewvc/cxf/trunk/systests/databinding/src/test/resources/wsdl_systest_databinding/xmlbeans/hello_world.wsdl?rev=896248&r1=896247&r2=896248&view=diff
==============================================================================
--- 
cxf/trunk/systests/databinding/src/test/resources/wsdl_systest_databinding/xmlbeans/hello_world.wsdl
 (original)
+++ 
cxf/trunk/systests/databinding/src/test/resources/wsdl_systest_databinding/xmlbeans/hello_world.wsdl
 Tue Jan  5 22:25:39 2010
@@ -17,23 +17,23 @@
   specific language governing permissions and limitations
   under the License.
 -->
-<wsdl:definitions name="HelloWorld" 
targetNamespace="http://apache.org/hello_world_soap_http/xmlbeans"; 
-    xmlns="http://schemas.xmlsoap.org/wsdl/"; 
-    xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"; 
+<wsdl:definitions name="HelloWorld" 
targetNamespace="http://apache.org/hello_world_soap_http/xmlbeans";
+    xmlns="http://schemas.xmlsoap.org/wsdl/";
+    xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/";
     xmlns:tns="http://apache.org/hello_world_soap_http/xmlbeans";
     xmlns:x1="http://apache.org/hello_world_soap_http/xmlbeans/types";
-    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"; 
+    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/";
     xmlns:xsd="http://www.w3.org/2001/XMLSchema";>
     <wsdl:types>
-        <schema 
targetNamespace="http://apache.org/hello_world_soap_http/xmlbeans/types"; 
+        <schema 
targetNamespace="http://apache.org/hello_world_soap_http/xmlbeans/types";
             xmlns="http://www.w3.org/2001/XMLSchema";
-           xmlns:tns="http://apache.org/hello_world_soap_http/xmlbeans/types";
+        xmlns:tns="http://apache.org/hello_world_soap_http/xmlbeans/types";
             elementFormDefault="qualified">
-           <simpleType name="MyStringType">
-               <restriction base="string">
-                   <maxLength value="30" />
-               </restriction>
-           </simpleType>
+            <simpleType name="MyStringType">
+                <restriction base="string">
+                    <maxLength value="30" />
+                </restriction>
+            </simpleType>
 
             <element name="sayHi">
                 <complexType/>
@@ -80,6 +80,7 @@
                     </sequence>
                 </complexType>
             </element>
+            <element name="greetMeFaultDetail" type="string"/>
         </schema>
     </wsdl:types>
     <wsdl:message name="sayHiRequest">
@@ -102,22 +103,29 @@
     </wsdl:message>
     <wsdl:message name="pingMeResponse">
         <wsdl:part name="out" element="x1:pingMeResponse"/>
-    </wsdl:message>            
+    </wsdl:message>
     <wsdl:message name="pingMeFault">
         <wsdl:part name="faultDetail" element="x1:faultDetail"/>
     </wsdl:message>
-    
+    <wsdl:message name="greetMeFault">
+        <wsdl:part name="greetMeFault" element="x1:greetMeFaultDetail"/>
+    </wsdl:message>
+
+
     <wsdl:portType name="Greeter">
         <wsdl:operation name="sayHi">
             <wsdl:input message="tns:sayHiRequest" name="sayHiRequest"/>
             <wsdl:output message="tns:sayHiResponse" name="sayHiResponse"/>
         </wsdl:operation>
         
+
         <wsdl:operation name="greetMe">
             <wsdl:input message="tns:greetMeRequest" name="greetMeRequest"/>
             <wsdl:output message="tns:greetMeResponse" name="greetMeResponse"/>
+            <wsdl:fault name="greetMeFault" message="tns:greetMeFault"/>
         </wsdl:operation>
         
+
         <wsdl:operation name="greetMeOneWay">
             <wsdl:input message="tns:greetMeOneWayRequest" 
name="greetMeOneWayRequest"/>
         </wsdl:operation>
@@ -126,11 +134,12 @@
             <wsdl:input name="pingMeRequest" message="tns:pingMeRequest"/>
             <wsdl:output name="pingMeResponse" message="tns:pingMeResponse"/>
             <wsdl:fault name="pingMeFault" message="tns:pingMeFault"/>
-        </wsdl:operation> 
+        </wsdl:operation>
     </wsdl:portType>
     <wsdl:binding name="Greeter_SOAPBinding" type="tns:Greeter">
         <soap:binding style="document" 
transport="http://schemas.xmlsoap.org/soap/http"/>
         
+
         <wsdl:operation name="sayHi">
             <soap:operation soapAction="" style="document"/>
             <wsdl:input name="sayHiRequest">
@@ -141,6 +150,7 @@
             </wsdl:output>
         </wsdl:operation>
         
+
         <wsdl:operation name="greetMe">
             <soap:operation soapAction="" style="document"/>
             <wsdl:input name="greetMeRequest">
@@ -149,8 +159,12 @@
             <wsdl:output name="greetMeResponse">
                 <soap:body use="literal"/>
             </wsdl:output>
+            <wsdl:fault name="greetMeFault">
+                <soap:fault name="greetMeFault" use="literal"/>
+            </wsdl:fault>
         </wsdl:operation>
         
+
         <wsdl:operation name="greetMeOneWay">
             <soap:operation soapAction="" style="document"/>
             <wsdl:input name="greetMeOneWayRequest">
@@ -171,6 +185,7 @@
             </wsdl:fault>
         </wsdl:operation>
         
+
     </wsdl:binding>
     <wsdl:service name="SOAPService">
         <wsdl:port binding="tns:Greeter_SOAPBinding" name="SoapPort">


Reply via email to