cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t..@apache.org
Subject svn commit: r476057 - in /incubator/cxf/trunk: api/src/main/java/org/apache/cxf/interceptor/ api/src/main/java/org/apache/cxf/message/ rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/ rt/core/src/main/java/org/apache/cxf/intercep...
Date Fri, 17 Nov 2006 06:18:38 GMT
Author: tli
Date: Thu Nov 16 22:18:37 2006
New Revision: 476057

URL: http://svn.apache.org/viewvc?view=rev&rev=476057
Log:
add stack trace config & support for soap 11 fault

Added:
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/fault-stack-trace.xml
  (with props)
Modified:
    incubator/cxf/trunk/api/src/main/java/org/apache/cxf/interceptor/Fault.java
    incubator/cxf/trunk/api/src/main/java/org/apache/cxf/message/Message.java
    incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/Soap11FaultOutInterceptor.java
    incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/ClientFaultConverter.java
    incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/EndpointImpl.java
    incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/ServerFactoryBean.java
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ClientServerTest.java

Modified: incubator/cxf/trunk/api/src/main/java/org/apache/cxf/interceptor/Fault.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/api/src/main/java/org/apache/cxf/interceptor/Fault.java?view=diff&rev=476057&r1=476056&r2=476057
==============================================================================
--- incubator/cxf/trunk/api/src/main/java/org/apache/cxf/interceptor/Fault.java (original)
+++ incubator/cxf/trunk/api/src/main/java/org/apache/cxf/interceptor/Fault.java Thu Nov 16
22:18:37 2006
@@ -31,6 +31,7 @@
  */
 public class Fault extends UncheckedException {
 
+    public static final String STACKTRACE = "stackTrace";
     private Element detail;
     private String message;
     

Modified: incubator/cxf/trunk/api/src/main/java/org/apache/cxf/message/Message.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/api/src/main/java/org/apache/cxf/message/Message.java?view=diff&rev=476057&r1=476056&r2=476057
==============================================================================
--- incubator/cxf/trunk/api/src/main/java/org/apache/cxf/message/Message.java (original)
+++ incubator/cxf/trunk/api/src/main/java/org/apache/cxf/message/Message.java Thu Nov 16 22:18:37
2006
@@ -47,7 +47,7 @@
     String QUERY_STRING = Message.class.getName() + ".QUERY_STRING";
     String MTOM_ENABLED = Message.class.getName() + ".isMtomEnabled";
     String SCHEMA_VALIDATION_ENABLED = Message.class.getCanonicalName() + ".schemaValidationEnabled";
-    String FAULT_STACKTRACE_ENABLED = Message.class.getCanonicalName() + ".faultStackTraceEnabled";
+    String FAULT_STACKTRACE_ENABLED = "faultStackTraceEnabled";
     String CONTENT_TYPE = Message.class.getName() + ".ContentType";
     String BASE_PATH = Message.class.getName() + ".BASE_PATH";
     String ENCODING = Message.class.getName() + ".ENCODING";

Modified: incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/Soap11FaultOutInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/Soap11FaultOutInterceptor.java?view=diff&rev=476057&r1=476056&r2=476057
==============================================================================
--- incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/Soap11FaultOutInterceptor.java
(original)
+++ incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/Soap11FaultOutInterceptor.java
Thu Nov 16 22:18:37 2006
@@ -82,23 +82,29 @@
                 writer.writeCharacters("Fault occurred while processing.");
             }
             writer.writeEndElement();
-            Object config = message.getContextualProperty(
+            String config = (String)message.getContextualProperty(
                     org.apache.cxf.message.Message.FAULT_STACKTRACE_ENABLED);
-            if (config != null && Boolean.TRUE.equals(config) && fault.getCause()
!= null) {                
+            if (config != null && Boolean.valueOf(config).booleanValue() &&
fault.getCause() != null) {
                 StringBuffer sb = new StringBuffer();
-                for (StackTraceElement stk : fault.getCause().getStackTrace()) {
-                    sb.append(stk.toString());
+                for (StackTraceElement ste : fault.getCause().getStackTrace()) {        
           
+                    sb.append(ste.getClassName() + "!" + ste.getMethodName() + "!" + ste.getFileName()
 
+                            + "!" + ste.getLineNumber() + "\n");
                 }
                 try {
-                    if (fault.getDetail() == null) {
+                    Element detail = fault.getDetail(); 
+                    if (detail == null) {
                         Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder()
-                                .newDocument();
-                        Element detail = doc.createElementNS(Soap11.SOAP_NAMESPACE, "detail");
-                        Element stackTrace = doc.createElementNS(Soap11.SOAP_NAMESPACE, "stackTrace");
+                            .newDocument();
+                        Element stackTrace = doc.createElementNS(Soap11.SOAP_NAMESPACE, Fault.STACKTRACE);
                         stackTrace.setTextContent(sb.toString());
-                        detail.appendChild(stackTrace);
+                        detail = doc.createElementNS(Soap11.SOAP_NAMESPACE, "detail");
                         fault.setDetail(detail);
-                    }
+                        detail.appendChild(stackTrace);
+                    } else {
+                        Element stackTrace = detail.getOwnerDocument().createElementNS(
+                                Soap11.SOAP_NAMESPACE, Fault.STACKTRACE);
+                        detail.appendChild(stackTrace);
+                    }                    
                 } catch (ParserConfigurationException pe) {
                     // move on...
                 }

Modified: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/ClientFaultConverter.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/ClientFaultConverter.java?view=diff&rev=476057&r1=476056&r2=476057
==============================================================================
--- incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/ClientFaultConverter.java
(original)
+++ incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/ClientFaultConverter.java
Thu Nov 16 22:18:37 2006
@@ -19,6 +19,9 @@
 package org.apache.cxf.interceptor;
 
 import java.lang.reflect.Constructor;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.StringTokenizer;
 
 import javax.xml.namespace.QName;
 
@@ -53,13 +56,14 @@
 
         if (fault.getDetail() != null) {
             processFaultDetail(fault, msg);
+            setStackTrace(fault, msg);
         }
     }
 
     protected void processFaultDetail(Fault fault, Message msg) {
         Element exDetail = (Element) DOMUtils.getChild(fault.getDetail(), Node.ELEMENT_NODE);
         QName qname = new QName(exDetail.getNamespaceURI(), exDetail.getLocalName());
-        FaultInfo faultWanted = null;    
+        FaultInfo faultWanted = null;
         MessagePartInfo part = null;
         BindingOperationInfo boi = msg.getExchange().get(BindingOperationInfo.class);
         if (boi.isUnwrapped()) {
@@ -76,22 +80,18 @@
             if (faultWanted != null) {
                 break;
             }
-        }
-
+        }        
         if (faultWanted == null) {
             return;
         }
-
         Service s = msg.getExchange().get(Service.class);
         DataBinding dataBinding = s.getDataBinding();
 
         DataReader<Node> reader = dataBinding.getDataReaderFactory().createReader(Node.class);
         Object e = reader.read(part, exDetail);
-
         if (!(e instanceof Exception)) {
             Class exClass = faultWanted.getProperty(Class.class.getName(), Class.class);
             Class beanClass = e.getClass();
-
             try {
                 Constructor constructor = exClass.getConstructor(new Class[]{String.class,
beanClass});
                 e = constructor.newInstance(new Object[]{fault.getMessage(), e});
@@ -99,8 +99,43 @@
                 throw new Fault(e1);
             }
         }
-
         msg.setContent(Exception.class, e);
     }
 
+    private void setStackTrace(Fault fault, Message msg) {
+        Element exDetail = (Element) DOMUtils.getChild(fault.getDetail(), Node.ELEMENT_NODE);
+        List<StackTraceElement> stackTraceList = new ArrayList<StackTraceElement>();
+        while (exDetail != null) {
+            if (((Element) exDetail).getLocalName().equals(Fault.STACKTRACE)) {
+                String content = exDetail.getTextContent();
+                if (content != null) {
+                    StringTokenizer st = new StringTokenizer(content, "\n");
+                    while (st.hasMoreTokens()) {
+                        String oneLine = st.nextToken();
+                        StringTokenizer stInner = new StringTokenizer(oneLine, "!");
+                        StackTraceElement ste = new StackTraceElement(stInner.nextToken(),
stInner
+                                .nextToken(), stInner.nextToken(), Integer.parseInt(stInner.nextToken()));
+                        stackTraceList.add(ste);
+                    }
+                }
+                if (stackTraceList.size() > 0) {
+                    StackTraceElement[] stackTraceElement = new StackTraceElement[stackTraceList.size()];
+                    Exception e = msg.getContent(Exception.class);
+                    e.setStackTrace(stackTraceList.toArray(stackTraceElement));
+                }
+            }
+            Node next = exDetail.getNextSibling();
+            while (!(next instanceof Element)) {
+                next = exDetail.getNextSibling();
+                if (next == null) {
+                    break;
+                }
+            }
+            if (next instanceof Element) {
+                exDetail = (Element) next;
+            } else {
+                exDetail = null;
+            }
+        }
+    }
 }

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/EndpointImpl.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/EndpointImpl.java?view=diff&rev=476057&r1=476056&r2=476057
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/EndpointImpl.java
(original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/EndpointImpl.java
Thu Nov 16 22:18:37 2006
@@ -205,6 +205,7 @@
         svrFactory.setAddress(address);
         svrFactory.setServiceFactory(serviceFactory);
         svrFactory.setStart(false);
+        configureObject(svrFactory);
         
         // TODO: Replace with discovery mechanism!!
         AbstractBindingInfoFactoryBean bindingFactory = null;

Modified: incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/ServerFactoryBean.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/ServerFactoryBean.java?view=diff&rev=476057&r1=476056&r2=476057
==============================================================================
--- incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/ServerFactoryBean.java
(original)
+++ incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/ServerFactoryBean.java
Thu Nov 16 22:18:37 2006
@@ -68,6 +68,10 @@
         setServiceFactory(new ReflectionServiceFactoryBean());
     }
     
+    public String getBeanName() {
+        return this.getClass().getName();
+    }
+
     public Server create() {
         try {
             Endpoint ep = createEndpoint();

Modified: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ClientServerTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ClientServerTest.java?view=diff&rev=476057&r1=476056&r2=476057
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ClientServerTest.java
(original)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ClientServerTest.java
Thu Nov 16 22:18:37 2006
@@ -81,7 +81,11 @@
     public static class Server extends TestServerBase {
         
 
-        protected void run()  {
+        protected void run()  {            
+            URL url = getClass().getResource("fault-stack-trace.xml");
+            if (url != null) {
+                System.setProperty("cxf.config.file.url", url.toString());
+            }
             Object implementor = new GreeterImpl();
             String address = "http://localhost:9000/SoapContext/SoapPort";
             Endpoint.publish(address, implementor);
@@ -107,14 +111,19 @@
     public static Test suite() throws Exception {
         TestSuite suite = new TestSuite(ClientServerTest.class);
         return new ClientServerSetupBase(suite) {
-                public void startServers() throws Exception {
+                public void startServers() throws Exception {                    
                     assertTrue("server did not launch correctly", launchServer(Server.class));
                 }
+                public void setUp() throws Exception {
+                    // set up configuration to enable schema validation
+                    URL url = getClass().getResource("fault-stack-trace.xml");
+                    assertNotNull("cannot find test resource", url);
+                    configFileName = url.toString();
+                    super.setUp();
+                }
             };
-        
-
-         
     }
+
     
     public void testBasicConnection() throws Exception {
 
@@ -476,13 +485,25 @@
                         
         }
 
+    }
+    public void testFaultStackTrace() throws Exception {
+        System.setProperty("cxf.config.file.url", 
+                getClass().getResource("fault-stack-trace.xml").toString());
+        URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
+        assertNotNull(wsdl);
+        SOAPService service = new SOAPService(wsdl, serviceName);
+        ExecutorService ex = Executors.newFixedThreadPool(1);
+        service.setExecutor(ex);
+        assertNotNull(service);        
+        Greeter greeter = service.getPort(portName, Greeter.class);
         try {
             // trigger runtime exception throw of implementor method
             greeter.testDocLitFault("");
             fail("Should have thrown Runtime exception");
         } catch (Exception e) {
-            assertEquals("can't get back original message",  "Unknown source", e.getMessage());
-        } 
+            assertEquals("can't get back original message", "Unknown source", e.getMessage());
+            assertTrue(e.getStackTrace().length > 0);            
+        }
     }
     
     public void testGetSayHi() throws Exception {

Added: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/fault-stack-trace.xml
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/fault-stack-trace.xml?view=auto&rev=476057
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/fault-stack-trace.xml
(added)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/fault-stack-trace.xml
Thu Nov 16 22:18:37 2006
@@ -0,0 +1,33 @@
+<?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:foo="http://cxf.apache.org/configuration/foo"
+    xsi:schemaLocation="
+http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
+
+    <bean class="org.apache.cxf.service.factory.ServerFactoryBean" id="org.apache.cxf.service.factory.ServerFactoryBean">
+        <property name="properties">
+            <map>
+                <entry key="faultStackTraceEnabled" value="true" />
+            </map>
+        </property>
+    </bean>
+
+</beans>
\ No newline at end of file

Propchange: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/fault-stack-trace.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/fault-stack-trace.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/fault-stack-trace.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml



Mime
View raw message