cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a.@apache.org
Subject svn commit: r1438428 - in /cxf/trunk: api/src/main/java/org/apache/cxf/feature/ api/src/main/java/org/apache/cxf/interceptor/transform/ systests/uncategorized/src/test/java/org/apache/cxf/systest/stax_transform_feature/
Date Fri, 25 Jan 2013 10:33:52 GMT
Author: ay
Date: Fri Jan 25 10:33:52 2013
New Revision: 1438428

URL: http://svn.apache.org/viewvc?rev=1438428&view=rev
Log:
[CXF-4752] TransformOutInterceptor does not transform SoapFaults

Added:
    cxf/trunk/systests/uncategorized/src/test/java/org/apache/cxf/systest/stax_transform_feature/
    cxf/trunk/systests/uncategorized/src/test/java/org/apache/cxf/systest/stax_transform_feature/StaxTransformFeatureTest.java
  (with props)
Modified:
    cxf/trunk/api/src/main/java/org/apache/cxf/feature/StaxTransformFeature.java
    cxf/trunk/api/src/main/java/org/apache/cxf/interceptor/transform/TransformOutInterceptor.java

Modified: cxf/trunk/api/src/main/java/org/apache/cxf/feature/StaxTransformFeature.java
URL: http://svn.apache.org/viewvc/cxf/trunk/api/src/main/java/org/apache/cxf/feature/StaxTransformFeature.java?rev=1438428&r1=1438427&r2=1438428&view=diff
==============================================================================
--- cxf/trunk/api/src/main/java/org/apache/cxf/feature/StaxTransformFeature.java (original)
+++ cxf/trunk/api/src/main/java/org/apache/cxf/feature/StaxTransformFeature.java Fri Jan 25
10:33:52 2013
@@ -63,6 +63,10 @@ public class StaxTransformFeature extend
     public void setAttributesToElements(boolean value) {
         out.setAttributesToElements(value);
     }
+
+    public void setSkipOnFault(boolean value) {
+        out.setAttributesToElements(value);
+    }
     
     public void setOutAppendElements(Map<String, String> map) {
         out.setOutAppendElements(map);

Modified: cxf/trunk/api/src/main/java/org/apache/cxf/interceptor/transform/TransformOutInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/api/src/main/java/org/apache/cxf/interceptor/transform/TransformOutInterceptor.java?rev=1438428&r1=1438427&r2=1438428&view=diff
==============================================================================
--- cxf/trunk/api/src/main/java/org/apache/cxf/interceptor/transform/TransformOutInterceptor.java
(original)
+++ cxf/trunk/api/src/main/java/org/apache/cxf/interceptor/transform/TransformOutInterceptor.java
Fri Jan 25 10:33:52 2013
@@ -50,6 +50,7 @@ public class TransformOutInterceptor ext
     private Map<String, String> outAppendMap;
     private List<String> outDropElements;
     private boolean attributesToElements;
+    private boolean skipOnFault;
     private String contextPropertyName;
     private String defaultNamespace;
     
@@ -84,7 +85,7 @@ public class TransformOutInterceptor ext
             return;
         }
         
-        if (null != message.getContent(Exception.class)) {
+        if (skipOnFault && null != message.getContent(Exception.class)) {
             return;
         }
         
@@ -129,6 +130,10 @@ public class TransformOutInterceptor ext
         this.attributesToElements = value;
     }
     
+    public void setSkipOnFault(boolean value) {
+        this.skipOnFault = value;
+    }
+    
     protected boolean isHttpVerbSupported(Message message) {
         return  isRequestor(message) && isGET(message) ? false : true;
     }

Added: cxf/trunk/systests/uncategorized/src/test/java/org/apache/cxf/systest/stax_transform_feature/StaxTransformFeatureTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/uncategorized/src/test/java/org/apache/cxf/systest/stax_transform_feature/StaxTransformFeatureTest.java?rev=1438428&view=auto
==============================================================================
--- cxf/trunk/systests/uncategorized/src/test/java/org/apache/cxf/systest/stax_transform_feature/StaxTransformFeatureTest.java
(added)
+++ cxf/trunk/systests/uncategorized/src/test/java/org/apache/cxf/systest/stax_transform_feature/StaxTransformFeatureTest.java
Fri Jan 25 10:33:52 2013
@@ -0,0 +1,275 @@
+/**
+ * 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.stax_transform_feature;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.xml.ws.Endpoint;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.BusFactory;
+import org.apache.cxf.bus.spring.SpringBusFactory;
+import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.greeter_control.Greeter;
+import org.apache.cxf.greeter_control.GreeterService;
+import org.apache.cxf.interceptor.Fault;
+import org.apache.cxf.interceptor.LoggingInInterceptor;
+import org.apache.cxf.interceptor.LoggingOutInterceptor;
+import org.apache.cxf.interceptor.transform.TransformInInterceptor;
+import org.apache.cxf.interceptor.transform.TransformOutInterceptor;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.systest.interceptor.GreeterImpl;
+import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
+import org.apache.cxf.testutil.common.AbstractBusTestServerBase;
+
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * Tests whether the stax transformer is correctly engaged and it does not interfere with
logging.
+ * This test uses a simple transformation. More complex transformation tests are found in
the api package.
+ *  
+ */
+public class StaxTransformFeatureTest extends AbstractBusClientServerTestBase {
+    public static final String PORT = allocatePort(Server.class);
+    private static final Logger LOG = LogUtils.getLogger(StaxTransformFeatureTest.class);
+    private static final String GREETER_PORT_ADDRESS = "http://localhost:" + PORT + "/SoapContext/GreeterPort";
+    
+    private static TestLoggingInInterceptor serverlogIn = new TestLoggingInInterceptor();
+    private static TestLoggingOutInterceptor serverlogOut = new TestLoggingOutInterceptor();
+    private static TransformInInterceptor servertransIn = new TransformInInterceptor();
+    private static TransformOutInterceptor servertransOut = new TransformOutInterceptor();
+    
+    private Greeter greeter;
+
+    
+    public static class Server extends AbstractBusTestServerBase {
+
+        Endpoint ep;
+        protected void run() {
+            SpringBusFactory factory = new SpringBusFactory();
+            Bus bus = factory.createBus();
+            BusFactory.setDefaultBus(bus);
+            setBus(bus);
+
+            bus.getInInterceptors().add(serverlogIn);
+            bus.getOutInterceptors().add(serverlogOut);
+            bus.getOutFaultInterceptors().add(serverlogOut);
+
+
+            Map<String, String> inElements = new HashMap<String, String>();
+            inElements.put("{http://cxf.apache.org/greeter_control/types}dontPingMe", 
+                           "{http://cxf.apache.org/greeter_control/types}pingMe");
+            servertransIn.setInTransformElements(inElements);
+            bus.getInInterceptors().add(servertransIn);
+            
+
+            Map<String, String> outElements = new HashMap<String, String>();
+            outElements.put("{http://cxf.apache.org/greeter_control/types}faultDetail", 
+                "{http://cxf.apache.org/greeter_control/types}noFaultDetail");
+            servertransOut.setOutTransformElements(outElements);
+            bus.getOutInterceptors().add(servertransOut);
+            bus.getOutFaultInterceptors().add(servertransOut);
+
+            GreeterImpl implementor = new GreeterImpl();
+            ep = Endpoint.publish(GREETER_PORT_ADDRESS, implementor);
+            LOG.fine("Published control endpoint.");
+        }
+        
+        public void tearDown() {
+            ep.stop();
+            ep = null;
+        }
+
+        public static void main(String[] args) {
+            try {
+                Server s = new Server();
+                s.start();
+            } catch (Exception ex) {
+                ex.printStackTrace();
+                System.exit(-1);
+            } finally {
+                System.out.println("done!");
+            }
+        }
+    }
+    
+
+    @BeforeClass
+    public static void startServers() throws Exception {
+        // force the info logging for this test
+        LOG.setLevel(Level.INFO);
+        System.out.println("### logLevel.info = " + LOG.isLoggable(Level.INFO));
+        assertTrue("server did not launch correctly", launchServer(Server.class, true));
+    }
+    
+    @AfterClass
+    public static void reset() {
+        Bus b = BusFactory.getDefaultBus(false);
+        if (b == null) {
+            b = BusFactory.getThreadDefaultBus(false);
+        }
+        if (b == null) {
+            b = BusFactory.getDefaultBus();
+        }
+        b.shutdown(true);
+    }
+    
+    @After
+    public void tearDown() throws Exception {
+        if (null != greeter) {
+            ((java.io.Closeable)greeter).close();
+        }
+    }
+
+    @Test
+    public void testTransformWithLogging() throws Exception {
+        SpringBusFactory bf = new SpringBusFactory();
+        Bus bus = bf.createBus();
+        BusFactory.setDefaultBus(bus);
+
+        TestLoggingInInterceptor logIn = new TestLoggingInInterceptor();
+        bus.getInInterceptors().add(logIn);
+        TestLoggingOutInterceptor logOut = new TestLoggingOutInterceptor();
+        bus.getOutInterceptors().add(logOut);
+        bus.getOutFaultInterceptors().add(logOut);
+
+        TransformInInterceptor transIn = new TransformInInterceptor();
+        Map<String, String> inElements = new HashMap<String, String>();
+        inElements.put("{http://cxf.apache.org/greeter_control/types}noFaultDetail", 
+            "{http://cxf.apache.org/greeter_control/types}faultDetail");
+        bus.getInInterceptors().add(transIn);
+        
+        TransformOutInterceptor transOut = new TransformOutInterceptor();
+        Map<String, String> outElements = new HashMap<String, String>();
+        outElements.put("{http://cxf.apache.org/greeter_control/types}pingMe", 
+            "{http://cxf.apache.org/greeter_control/types}dontPingMe");
+        transOut.setOutTransformElements(outElements);
+
+        bus.getOutInterceptors().add(transOut);
+        bus.getOutFaultInterceptors().add(transOut);
+
+        GreeterService gs = new GreeterService();
+        greeter = gs.getGreeterPort();
+        
+        updateAddressPort(greeter, PORT);
+        LOG.fine("Created greeter client.");
+        
+        // ping 1: request-response transformation
+        greeter.pingMe();
+        verifyPayload(logOut.getMessage(), "dontPingMe");
+        verifyPayload(logIn.getMessage(), "pingMeResponse");
+        verifyPayload(serverlogIn.getMessage(), "dontPingMe");
+        verifyPayload(serverlogOut.getMessage(), "pingMeResponse");
+        
+        serverlogOut.cleaerMessage();
+        serverlogIn.cleaerMessage();
+        logOut.cleaerMessage();
+        logIn.cleaerMessage();
+        
+        // ping 2: request-fault transformation
+        try {
+            greeter.pingMe();
+        } catch (Exception e) {
+            assertEquals("Pings succeed only every other time.", e.getMessage());
+        }
+        verifyPayload(logOut.getMessage(), "dontPingMe");
+        verifyPayload(logIn.getMessage(), "noFaultDetail");
+        verifyPayload(serverlogIn.getMessage(), "dontPingMe");
+        verifyPayload(serverlogOut.getMessage(), "noFaultDetail");
+        
+        // ping 3: idle
+        greeter.pingMe();
+
+        serverlogOut.cleaerMessage();
+        serverlogIn.cleaerMessage();
+        logOut.cleaerMessage();
+        logIn.cleaerMessage();
+
+        // ping 4: request-fault transformation with skipOnFault
+        transOut.setSkipOnFault(true);
+        servertransOut.setSkipOnFault(true);
+        try {
+            greeter.pingMe();
+        } catch (Exception e) {
+            assertEquals("Pings succeed only every other time.", e.getMessage());
+        }
+        verifyPayload(logOut.getMessage(), "dontPingMe");
+        verifyPayload(logIn.getMessage(), "faultDetail");
+        verifyPayload(serverlogIn.getMessage(), "dontPingMe");
+        verifyPayload(serverlogOut.getMessage(), "faultDetail");
+
+        bus.shutdown(true);
+    }
+    
+    private void verifyPayload(String m, String value) {
+        assertNotNull("message not logged", m);
+        // the entire soap envelope is logged
+        assertTrue(m.indexOf("Payload: <soap:Envelope") > 0 && m.indexOf("</soap:Envelope>")
> 0);
+        // the transformed body is logged
+        assertTrue(value + " must be found in payload", m.indexOf(value) > 0);
+    }
+
+    static class TestLoggingInInterceptor extends LoggingInInterceptor {
+        private String logMessage;
+        
+        @Override
+        public void handleMessage(Message msg) throws Fault {
+            msg.getExchange().getEndpoint().getEndpointInfo().setProperty("MessageLogger",
LOG);            
+            super.handleMessage(msg);
+        }
+        @Override
+        protected void log(Logger logger, String msg) {
+            logMessage = msg;
+        }
+        public String getMessage() {
+            return logMessage;
+        }
+        public void cleaerMessage() {
+            logMessage = null;
+        }
+    }
+    
+    static class TestLoggingOutInterceptor extends LoggingOutInterceptor {
+        private String message;
+        
+        @Override
+        public void handleMessage(Message msg) throws Fault {
+            msg.getExchange().getEndpoint().getEndpointInfo().setProperty("MessageLogger",
LOG);            
+            super.handleMessage(msg);
+        }
+        @Override
+        protected void log(Logger logger, String msg) {
+            message = msg;
+        }
+        public String getMessage() {
+            return message;
+        }
+        public void cleaerMessage() {
+            message = null;
+        }
+    }
+
+}

Propchange: cxf/trunk/systests/uncategorized/src/test/java/org/apache/cxf/systest/stax_transform_feature/StaxTransformFeatureTest.java
------------------------------------------------------------------------------
    svn:executable = *



Mime
View raw message