Author: dkulp
Date: Fri May 17 16:02:38 2013
New Revision: 1483888
URL: http://svn.apache.org/r1483888
Log:
[CXF-5022] Fix problems with JAX-RS services starting on the same URL
Modified:
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSBindingFactory.java
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/Messages.properties
cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/spring/servers.xml
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/failover/Server.java
Modified:
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSBindingFactory.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSBindingFactory.java?rev=1483888&r1=1483887&r2=1483888&view=diff
==============================================================================
---
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSBindingFactory.java
(original)
+++
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSBindingFactory.java
Fri May 17 16:02:38 2013
@@ -19,6 +19,8 @@
package org.apache.cxf.jaxrs;
+import java.util.logging.Logger;
+
import javax.xml.namespace.QName;
import org.apache.cxf.Bus;
@@ -26,12 +28,17 @@ import org.apache.cxf.binding.AbstractBa
import org.apache.cxf.binding.Binding;
import org.apache.cxf.binding.xml.XMLBinding;
import org.apache.cxf.binding.xml.interceptor.XMLFaultOutInterceptor;
+import org.apache.cxf.common.i18n.Message;
import org.apache.cxf.common.injection.NoJSR250Annotations;
+import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.endpoint.Endpoint;
import org.apache.cxf.interceptor.StaxOutInterceptor;
import org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor;
import org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor;
import org.apache.cxf.service.Service;
+import org.apache.cxf.service.factory.ServiceConstructionException;
import org.apache.cxf.service.model.BindingInfo;
+import org.apache.cxf.transport.Destination;
/**
* The CXF BindingFactory implementation which is used to register
@@ -39,9 +46,11 @@ import org.apache.cxf.service.model.Bind
*/
@NoJSR250Annotations(unlessNull = { "bus" })
public class JAXRSBindingFactory extends AbstractBaseBindingFactory {
-
public static final String JAXRS_BINDING_ID =
"http://apache.org/cxf/binding/jaxrs";
+
+ private static final Logger LOG =
LogUtils.getL7dLogger(JAXRSBindingFactory.class);
+
public JAXRSBindingFactory() {
}
public JAXRSBindingFactory(Bus b) {
@@ -70,6 +79,16 @@ public class JAXRSBindingFactory extends
info.setName(new QName(JAXRSBindingFactory.JAXRS_BINDING_ID,
"binding"));
return info;
}
+
+ public void addListener(Destination d, Endpoint e) {
+ synchronized (d) {
+ if (d.getMessageObserver() != null) {
+ throw new ServiceConstructionException(new
Message("ALREADY_RUNNING", LOG,
+
e.getEndpointInfo().getAddress()));
+ }
+ super.addListener(d, e);
+ }
+ }
}
Modified:
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/Messages.properties
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/Messages.properties?rev=1483888&r1=1483887&r2=1483888&view=diff
==============================================================================
---
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/Messages.properties
(original)
+++
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/Messages.properties
Fri May 17 16:02:38 2013
@@ -22,4 +22,4 @@ NO_RESOURCES_AVAILABLE=No resource class
NO_SUBRESOURCE_FOUND=No subresource locator found for path {0}
NULL_SUBRESOURCE=Null subresource locator is returned for path {0}
PROXY_INVOCATION_FAILURE=Resource method "{0}" available at {1} can not be
called on proxy. Moving resource methods to interface and having {1} implement
it may help.
-
+ALREADY_RUNNING=There is an endpoint already running on {0}.
Modified:
cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/spring/servers.xml
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/spring/servers.xml?rev=1483888&r1=1483887&r2=1483888&view=diff
==============================================================================
---
cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/spring/servers.xml
(original)
+++
cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/spring/servers.xml
Fri May 17 16:02:38 2013
@@ -80,7 +80,7 @@ http://cxf.apache.org/jaxrs http://cxf.a
<jaxrs:server id="moduleServer"
modelRef="classpath:/org/apache/cxf/jaxrs/spring/resources.xml"
- address="http://localhost:9090/simpleWithAddress"
+ address="http://localhost:9090/simpleWithAddress2"
bus="cxf"/>
</beans>
Modified:
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/failover/Server.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/failover/Server.java?rev=1483888&r1=1483887&r2=1483888&view=diff
==============================================================================
---
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/failover/Server.java
(original)
+++
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/failover/Server.java
Fri May 17 16:02:38 2013
@@ -20,6 +20,9 @@
package org.apache.cxf.systest.jaxrs.failover;
+import java.util.ArrayList;
+import java.util.List;
+
import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider;
import org.apache.cxf.systest.jaxrs.BookStore;
@@ -35,17 +38,26 @@ public class Server extends AbstractBusT
public static final String ADDRESS3 = "http://localhost:" + PORT3 +
"/work/rest";
+ List<org.apache.cxf.endpoint.Server> servers = new
ArrayList<org.apache.cxf.endpoint.Server>();
+
protected void run() {
createEndpoint(ADDRESS2);
createEndpoint(ADDRESS3);
}
-
+ public void tearDown() throws Exception {
+ for (org.apache.cxf.endpoint.Server s : servers) {
+ s.stop();
+ s.destroy();
+ }
+ servers.clear();
+ }
+
private void createEndpoint(String address) {
JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
sf.setResourceClasses(BookStore.class);
sf.setResourceProvider(BookStore.class, new
SingletonResourceProvider(new BookStore(), false));
sf.setAddress(address);
- sf.create();
+ servers.add(sf.create());
}
public static void main(String[] args) {