This is an automated email from the ASF dual-hosted git repository.
ffang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cxf.git
The following commit(s) were added to refs/heads/master by this push:
new fb493e4 [CXF-8433]JAXRSServerFactoryBean remove existing path created
by other sever endpoint from destinations
fb493e4 is described below
commit fb493e49fd58b2417d5a9ac6861482f286d1fdf9
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
---
.../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) {