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

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


The following commit(s) were added to refs/heads/3.4.x-fixes by this push:
     new d432c40  [CXF-8433]JAXRSServerFactoryBean remove existing path created 
by other sever endpoint from destinations
d432c40 is described below

commit d432c4001e6973f179e81296902c9ccb23efa052
Author: Freeman Fang <[email protected]>
AuthorDate: Fri Mar 5 11:55:30 2021 -0500

    [CXF-8433]JAXRSServerFactoryBean remove existing path created by other 
sever endpoint from destinations
    
    (cherry picked from commit fb493e49fd58b2417d5a9ac6861482f286d1fdf9)
---
 .../java/org/apache/cxf/jaxrs/JAXRSServerFactoryBean.java   |  7 ++++++-
 .../cxf/systest/jaxrs/provider/JsrJsonpProviderTest.java    | 13 +++++++++++++
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git 
a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServerFactoryBean.java
 
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServerFactoryBean.java
index 8548865..f3b47a6 100644
--- 
a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServerFactoryBean.java
+++ 
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServerFactoryBean.java
@@ -208,7 +208,12 @@ public class JAXRSServerFactoryBean extends 
AbstractJAXRSFactoryBean {
                 try {
                     server.start();
                 } catch (RuntimeException re) {
-                    server.destroy(); // prevent resource leak
+                    if (!(re instanceof ServiceConstructionException 
+                        && re.getMessage().startsWith("There is an endpoint 
already running on"))) {
+                        //avoid destroying another server on the same endpoint 
url
+                        server.destroy(); // prevent resource leak if server 
really started by itself
+                        
+                    }
                     throw re;
                 }
             }
diff --git 
a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/provider/JsrJsonpProviderTest.java
 
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/provider/JsrJsonpProviderTest.java
index 2d405ad..85d9244 100644
--- 
a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/provider/JsrJsonpProviderTest.java
+++ 
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/provider/JsrJsonpProviderTest.java
@@ -33,6 +33,7 @@ import org.apache.cxf.jaxrs.client.WebClient;
 import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider;
 import org.apache.cxf.jaxrs.model.AbstractResourceInfo;
 import org.apache.cxf.jaxrs.provider.jsrjsonp.JsrJsonpProvider;
+import org.apache.cxf.service.factory.ServiceConstructionException;
 import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
 import org.apache.cxf.testutil.common.AbstractBusTestServerBase;
 
@@ -61,6 +62,18 @@ public class JsrJsonpProviderTest extends 
AbstractBusClientServerTestBase {
             sf.setProvider(new JsrJsonpProvider());
             sf.setAddress("http://localhost:"; + PORT + "/");
             sf.create();
+            try {
+                sf.create();
+            } catch (Exception ex) {
+                assertTrue(ex.getCause() instanceof 
ServiceConstructionException);
+                assertTrue(ex.getCause().getMessage().startsWith("There is an 
endpoint already running on"));
+            }
+            try {
+                sf.create();
+            } catch (Exception ex) {
+                assertTrue(ex.getCause() instanceof 
ServiceConstructionException);
+                assertTrue(ex.getCause().getMessage().startsWith("There is an 
endpoint already running on"));
+            }
         }
 
         public static void main(String[] args) {

Reply via email to