You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by re...@apache.org on 2019/12/29 21:37:23 UTC

[cxf] branch 3.2.x-fixes updated: CXF-8186: On connection refused, XSLTOutInterceptor mangles the error (#618)

This is an automated email from the ASF dual-hosted git repository.

reta pushed a commit to branch 3.2.x-fixes
in repository https://gitbox.apache.org/repos/asf/cxf.git


The following commit(s) were added to refs/heads/3.2.x-fixes by this push:
     new 35b6b52  CXF-8186: On connection refused, XSLTOutInterceptor mangles the error (#618)
35b6b52 is described below

commit 35b6b528cdc2beda53366f0bf5f04be35862e0f8
Author: Réda Housni Alaoui <re...@gmail.com>
AuthorDate: Sun Dec 29 20:11:12 2019 +0100

    CXF-8186: On connection refused, XSLTOutInterceptor mangles the error (#618)
---
 .../cxf/feature/transform/XSLTOutInterceptor.java  |  4 +--
 .../transform/feature/TransformFeatureTest.java    | 31 +++++++++++++++++++++-
 2 files changed, 32 insertions(+), 3 deletions(-)

diff --git a/core/src/main/java/org/apache/cxf/feature/transform/XSLTOutInterceptor.java b/core/src/main/java/org/apache/cxf/feature/transform/XSLTOutInterceptor.java
index 851822f..43b19e3 100644
--- a/core/src/main/java/org/apache/cxf/feature/transform/XSLTOutInterceptor.java
+++ b/core/src/main/java/org/apache/cxf/feature/transform/XSLTOutInterceptor.java
@@ -160,7 +160,7 @@ public class XSLTOutInterceptor extends AbstractXSLTInterceptor {
         @Override
         public void onClose(CachedOutputStream wrapper) {
             InputStream transformedStream;
-            IOException exceptionOnClose = null;
+            Exception exceptionOnClose = null;
             try {
                 transformedStream = XSLTUtils.transform(xsltTemplate, wrapper.getInputStream());
                 IOUtils.copyAndCloseInput(transformedStream, origStream);
@@ -169,7 +169,7 @@ public class XSLTOutInterceptor extends AbstractXSLTInterceptor {
             } finally {
                 try {
                     origStream.close();
-                } catch (IOException e) {
+                } catch (Exception e) {
                     exceptionOnClose = e;
                 }
             }
diff --git a/systests/uncategorized/src/test/java/org/apache/cxf/systest/transform/feature/TransformFeatureTest.java b/systests/uncategorized/src/test/java/org/apache/cxf/systest/transform/feature/TransformFeatureTest.java
index b9c5fcd..cb0420c 100644
--- a/systests/uncategorized/src/test/java/org/apache/cxf/systest/transform/feature/TransformFeatureTest.java
+++ b/systests/uncategorized/src/test/java/org/apache/cxf/systest/transform/feature/TransformFeatureTest.java
@@ -18,9 +18,11 @@
  */
 
 
-
 package org.apache.cxf.systest.transform.feature;
 
+import java.io.IOException;
+import java.net.ServerSocket;
+
 import javax.xml.namespace.QName;
 import javax.xml.ws.Service;
 import javax.xml.ws.soap.SOAPBinding;
@@ -30,6 +32,7 @@ import org.apache.cxf.feature.transform.XSLTInInterceptor;
 import org.apache.cxf.feature.transform.XSLTOutInterceptor;
 import org.apache.cxf.frontend.ClientProxy;
 import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
+import org.apache.cxf.transport.http.HTTPConduit;
 
 import org.junit.Assert;
 import org.junit.BeforeClass;
@@ -83,6 +86,32 @@ public class TransformFeatureTest extends AbstractBusClientServerTestBase {
     }
 
     @Test
+    public void testClientOutTransformationOnConnectionRefused() throws IOException {
+        Service service = Service.create(SERVICE_NAME);
+        ServerSocket socket = new ServerSocket(0);
+        String endpoint = "http://127.0.0.1:" + socket.getLocalPort() + "/";
+        socket.close();
+        service.addPort(PORT_NAME, SOAPBinding.SOAP11HTTP_BINDING, endpoint);
+
+        Echo port = service.getPort(PORT_NAME, Echo.class);
+        Client client = ClientProxy.getClient(port);
+        HTTPConduit httpConduit = (HTTPConduit) client.getConduit();
+        // We need to disable chunking to make the client write directly to the connection OutputStream
+        httpConduit.getClient().setAllowChunking(false);
+
+        XSLTOutInterceptor outInterceptor = new XSLTOutInterceptor(XSLT_REQUEST_PATH);
+        client.getOutInterceptors().add(outInterceptor);
+
+        try {
+            port.echo("test");
+            fail("Connection refused expected");
+        } catch (Exception e) {
+            String exceptionMessage = e.getMessage();
+            assertTrue(exceptionMessage.toLowerCase().contains("connection refused"));
+        }
+    }
+
+    @Test
     public void testClientInTransformation() {
         Service service = Service.create(SERVICE_NAME);
         String endpoint = "http://localhost:" + PORT + "/EchoContext/EchoPort";