Repository: tomee
Updated Branches:
  refs/heads/master 734945cbb -> 945ce4aff


TOMEE-2040 don't write EJB JAXWS response before the transaction is over


Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/945ce4af
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/945ce4af
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/945ce4af

Branch: refs/heads/master
Commit: 945ce4aff6c7a42c5a273d37ea3e2dbca39f0416
Parents: 734945c
Author: rmannibucau <[email protected]>
Authored: Wed May 3 22:56:02 2017 +0200
Committer: rmannibucau <[email protected]>
Committed: Wed May 3 22:56:02 2017 +0200

----------------------------------------------------------------------
 .../openejb/server/cxf/ejb/EjbEndpoint.java     |   1 -
 .../openejb/server/cxf/ejb/EjbInterceptor.java  |   4 +-
 .../cxf/DontSerializeBeforeCommitTest.java      | 131 +++++++++++++++++++
 .../server/cxf/handler/PassthroughHandler.java  |  37 ++++++
 .../openejb/server/cxf/passthrough-handler.xml  |  25 ++++
 5 files changed, 195 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/945ce4af/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/ejb/EjbEndpoint.java
----------------------------------------------------------------------
diff --git 
a/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/ejb/EjbEndpoint.java
 
b/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/ejb/EjbEndpoint.java
index 6d5f66a..6747ba9 100644
--- 
a/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/ejb/EjbEndpoint.java
+++ 
b/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/ejb/EjbEndpoint.java
@@ -27,7 +27,6 @@ import 
org.apache.cxf.jaxws.handler.logical.LogicalHandlerInInterceptor;
 import org.apache.cxf.jaxws.handler.soap.SOAPHandlerInterceptor;
 import org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean;
 import org.apache.cxf.transport.DestinationFactory;
-import org.apache.cxf.transport.http.HTTPTransportFactory;
 import org.apache.openejb.BeanContext;
 import org.apache.openejb.assembler.classic.util.ServiceConfiguration;
 import org.apache.openejb.core.webservices.JaxWsUtils;

http://git-wip-us.apache.org/repos/asf/tomee/blob/945ce4af/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/ejb/EjbInterceptor.java
----------------------------------------------------------------------
diff --git 
a/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/ejb/EjbInterceptor.java
 
b/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/ejb/EjbInterceptor.java
index 53a7dd3..a192e00 100644
--- 
a/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/ejb/EjbInterceptor.java
+++ 
b/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/ejb/EjbInterceptor.java
@@ -119,7 +119,7 @@ public class EjbInterceptor {
 
             // install default interceptors
             chain.add(new ServiceInvokerInterceptor());
-            chain.add(new OutgoingChainInterceptor());
+            //chain.add(new OutgoingChainInterceptor()); // it is already in 
the enclosing chain, if we add it there we are in the tx so we write the 
message in the tx!
 
             // See http://cwiki.apache.org/CXF20DOC/interceptors.html
             // install Holder and Wrapper interceptors
@@ -131,7 +131,7 @@ public class EjbInterceptor {
             chain.add(new LogicalHandlerInInterceptor(binding));
             chain.add(new SOAPHandlerInterceptor(binding));
 
-            // install data binding interceptors
+            // install data binding interceptors - todo: check we need it
             copyDataBindingInterceptors(chain, 
inMessage.getInterceptorChain());
 
             InterceptorChain oldChain = inMessage.getInterceptorChain();

http://git-wip-us.apache.org/repos/asf/tomee/blob/945ce4af/server/openejb-cxf/src/test/java/org/apache/openejb/server/cxf/DontSerializeBeforeCommitTest.java
----------------------------------------------------------------------
diff --git 
a/server/openejb-cxf/src/test/java/org/apache/openejb/server/cxf/DontSerializeBeforeCommitTest.java
 
b/server/openejb-cxf/src/test/java/org/apache/openejb/server/cxf/DontSerializeBeforeCommitTest.java
new file mode 100644
index 0000000..682751c
--- /dev/null
+++ 
b/server/openejb-cxf/src/test/java/org/apache/openejb/server/cxf/DontSerializeBeforeCommitTest.java
@@ -0,0 +1,131 @@
+/**
+ *
+ * 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.openejb.server.cxf;
+
+import org.apache.openejb.junit.ApplicationComposer;
+import org.apache.openejb.testing.Classes;
+import org.apache.openejb.testing.EnableServices;
+import org.apache.openejb.testing.RandomPort;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import javax.annotation.Resource;
+import javax.ejb.EJB;
+import javax.ejb.LocalBean;
+import javax.ejb.Singleton;
+import javax.jws.HandlerChain;
+import javax.jws.WebService;
+import javax.transaction.Synchronization;
+import javax.transaction.TransactionSynchronizationRegistry;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.namespace.QName;
+import javax.xml.ws.Service;
+import javax.xml.ws.soap.SOAPFaultException;
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+@EnableServices("jaxws")
+@RunWith(ApplicationComposer.class)
+@Classes(innerClassesAsBean = true)
+public class DontSerializeBeforeCommitTest {
+    @RandomPort("http")
+    private int port;
+
+    @EJB
+    private TheTxImpl bean;
+
+    @Test
+    public void test() throws MalformedURLException {
+        bean.setCounter(0);
+        final TheTx client = Service.create(new URL("http://localhost:"; + port 
+ "/openejb/TheTxImpl?wsdl"),
+                new QName("http://cxf.server.openejb.apache.org/";, 
"TheTxImplService"))
+                .getPort(TheTx.class);
+        try {
+            client.compute(false);
+            fail();
+        } catch (final SOAPFaultException fault) {
+            assertTrue(fault.getMessage().contains("Transaction was rolled 
back"));
+        }
+        assertEquals(2, client.compute(true).getValue());
+    }
+
+    @WebService
+    public interface TheTx {
+        TheResult compute(boolean passing);
+    }
+
+    @WebService
+    @Singleton
+    @LocalBean
+    @HandlerChain(file = "passthrough-handler.xml")
+    public static class TheTxImpl implements TheTx {
+        @Resource
+        private TransactionSynchronizationRegistry registry;
+
+        private int counter = 0;
+
+        public int getCounter() {
+            return counter;
+        }
+
+        public void setCounter(final int counter) {
+            this.counter = counter;
+        }
+
+        @Override
+        public TheResult compute(final boolean passing) {
+            final TheResult theResult = new TheResult();
+            counter++; // ensure we are not called N times
+            theResult.setValue(counter);
+            if (!passing) {
+                registry.registerInterposedSynchronization(new 
Synchronization() {
+                    @Override
+                    public void beforeCompletion() {
+                        registry.setRollbackOnly();
+                    }
+
+                    @Override
+                    public void afterCompletion(final int status) {
+                        // no-op
+                    }
+                });
+            }
+            return theResult;
+        }
+    }
+
+    @XmlRootElement
+    @XmlAccessorType(XmlAccessType.FIELD)
+    public static class TheResult {
+        private int value;
+
+        public int getValue() {
+            return value;
+        }
+
+        public void setValue(final int value) {
+            this.value = value;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/tomee/blob/945ce4af/server/openejb-cxf/src/test/java/org/apache/openejb/server/cxf/handler/PassthroughHandler.java
----------------------------------------------------------------------
diff --git 
a/server/openejb-cxf/src/test/java/org/apache/openejb/server/cxf/handler/PassthroughHandler.java
 
b/server/openejb-cxf/src/test/java/org/apache/openejb/server/cxf/handler/PassthroughHandler.java
new file mode 100644
index 0000000..eb4cea0
--- /dev/null
+++ 
b/server/openejb-cxf/src/test/java/org/apache/openejb/server/cxf/handler/PassthroughHandler.java
@@ -0,0 +1,37 @@
+/*
+ * 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.openejb.server.cxf.handler;
+
+import javax.xml.ws.handler.Handler;
+import javax.xml.ws.handler.MessageContext;
+
+public class PassthroughHandler implements Handler {
+    @Override
+    public void close(final MessageContext messageContext) {
+        // no-op
+    }
+
+    @Override
+    public boolean handleFault(final MessageContext messageContext) {
+        return false;
+    }
+
+    @Override
+    public boolean handleMessage(final MessageContext messageContext) {
+        return true;
+    }
+}

http://git-wip-us.apache.org/repos/asf/tomee/blob/945ce4af/server/openejb-cxf/src/test/resources/org/apache/openejb/server/cxf/passthrough-handler.xml
----------------------------------------------------------------------
diff --git 
a/server/openejb-cxf/src/test/resources/org/apache/openejb/server/cxf/passthrough-handler.xml
 
b/server/openejb-cxf/src/test/resources/org/apache/openejb/server/cxf/passthrough-handler.xml
new file mode 100644
index 0000000..3d8f653
--- /dev/null
+++ 
b/server/openejb-cxf/src/test/resources/org/apache/openejb/server/cxf/passthrough-handler.xml
@@ -0,0 +1,25 @@
+<?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.
+-->
+<handler-chains xmlns="http://java.sun.com/xml/ns/javaee";>
+  <handler-chain>
+    <handler>
+      <handler-name>PassthroughHandler</handler-name>
+      
<handler-class>org.apache.openejb.server.cxf.handler.PassthroughHandler</handler-class>
+    </handler>
+  </handler-chain>
+</handler-chains>

Reply via email to