You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by cs...@apache.org on 2012/11/05 14:29:55 UTC
svn commit: r1405786 - in /cxf/dosgi/trunk/dsw/cxf-dsw/src:
main/java/org/apache/cxf/dosgi/dsw/handlers/
main/java/org/apache/cxf/dosgi/dsw/service/
test/java/org/apache/cxf/dosgi/dsw/handlers/
Author: cschneider
Date: Mon Nov 5 13:29:54 2012
New Revision: 1405786
URL: http://svn.apache.org/viewvc?rev=1405786&view=rev
Log:
DOSGI-139 Better refactoring for DSW-CXF
Added:
cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/ExportResult.java (with props)
Removed:
cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/CXFExportRegistration.java
Modified:
cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/ConfigurationTypeHandler.java
cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/HttpServiceConfigurationTypeHandler.java
cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/JaxRSHttpServiceConfigurationTypeHandler.java
cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/JaxRSPojoConfigurationTypeHandler.java
cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandler.java
cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/WsdlConfigurationTypeHandler.java
cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/EventAdminHelper.java
cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/EventProducer.java
cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ExportReferenceImpl.java
cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ExportRegistrationImpl.java
cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminCore.java
cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/HttpServiceConfigurationTypeHandlerTest.java
cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandlerTest.java
Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/ConfigurationTypeHandler.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/ConfigurationTypeHandler.java?rev=1405786&r1=1405785&r2=1405786&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/ConfigurationTypeHandler.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/ConfigurationTypeHandler.java Mon Nov 5 13:29:54 2012
@@ -27,7 +27,7 @@ import org.osgi.service.remoteserviceadm
public interface ConfigurationTypeHandler {
String getType();
- void createServer(CXFExportRegistration serviceReference,
+ ExportResult createServer(ServiceReference serviceReference,
BundleContext dswContext,
BundleContext callingContext,
Map sd,
Added: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/ExportResult.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/ExportResult.java?rev=1405786&view=auto
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/ExportResult.java (added)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/ExportResult.java Mon Nov 5 13:29:54 2012
@@ -0,0 +1,43 @@
+/**
+ * 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.cxf.dosgi.dsw.handlers;
+
+import java.util.Map;
+
+import org.apache.cxf.endpoint.Server;
+
+public class ExportResult {
+ private final Map<String, Object> endpointProps;
+ private final Server server;
+
+ public ExportResult(Map<String, Object> endpointProps, Server server) {
+ super();
+ this.endpointProps = endpointProps;
+ this.server = server;
+ }
+
+ public Map<String, Object> getEndpointProps() {
+ return endpointProps;
+ }
+
+ public Server getServer() {
+ return server;
+ }
+
+}
Propchange: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/ExportResult.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/HttpServiceConfigurationTypeHandler.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/HttpServiceConfigurationTypeHandler.java?rev=1405786&r1=1405785&r2=1405786&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/HttpServiceConfigurationTypeHandler.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/HttpServiceConfigurationTypeHandler.java Mon Nov 5 13:29:54 2012
@@ -124,27 +124,23 @@ public class HttpServiceConfigurationTyp
return null;
}
- public void createServer(CXFExportRegistration exportRegistration, BundleContext dswContext,
+ public ExportResult createServer(ServiceReference sref, BundleContext dswContext,
BundleContext callingContext, Map sd, Class<?> iClass, Object serviceBean) {
final String contextRoot = getServletContextRoot(sd, iClass);
if (contextRoot == null) {
- LOG.warning("Remote address is unavailable");
- return;
+ throw new RuntimeException("Remote address is unavailable");
}
- Bus bus = registerServletAndGetBus(contextRoot, dswContext, exportRegistration);
- final ServiceReference sref = exportRegistration.getExportedService();
+ Bus bus = registerServletAndGetBus(contextRoot, dswContext, sref);
DataBinding databinding;
- String dataBindingImpl = (String)exportRegistration.getExportedService()
- .getProperty(Constants.WS_DATABINDING_PROP_KEY);
+ String dataBindingImpl = (String)sref.getProperty(Constants.WS_DATABINDING_PROP_KEY);
String dataBindingImpl2 = (String) sref.getProperty(Constants.WS_DATABINDING_PROP_KEY);
if ("jaxb".equals(dataBindingImpl) || "jaxb".equals(dataBindingImpl2)) {
databinding = new JAXBDataBinding();
} else {
databinding = new AegisDatabinding();
}
- String frontEndImpl = (String)exportRegistration.getExportedService()
- .getProperty(Constants.WS_FRONTEND_PROP_KEY);
+ String frontEndImpl = (String)sref.getProperty(Constants.WS_FRONTEND_PROP_KEY);
String frontEndImpl2 = (String) sref.getProperty(Constants.WS_FRONTEND_PROP_KEY);
ServerFactoryBean factory =
@@ -173,33 +169,24 @@ public class HttpServiceConfigurationTyp
Map<String, Object> endpointProps = createEndpointProps(sd, iClass, new String[] {
Constants.WS_CONFIG_TYPE
}, completeEndpointAddress, intents);
- EndpointDescription endpdDesc = null;
-
+
Thread.currentThread().setContextClassLoader(ServerFactoryBean.class.getClassLoader());
Server server = factory.create();
-
- endpdDesc = new EndpointDescription(endpointProps);
- exportRegistration.setServer(server);
-
- // add the information on the new Endpoint to the export registration
- exportRegistration.setEndpointdescription(endpdDesc);
- } catch (IntentUnsatifiedException iue) {
- exportRegistration.setException(iue);
+
+ return new ExportResult(endpointProps, server);
} finally {
Thread.currentThread().setContextClassLoader(oldClassLoader);
}
-
-
}
protected Bus registerServletAndGetBus(String contextRoot, BundleContext dswContext,
- CXFExportRegistration exportRegistration) {
+ ServiceReference sref) {
CXFNonSpringServlet cxf = new CXFNonSpringServlet();
HttpService httpService = getHttpService();
try {
httpService.registerServlet(contextRoot, cxf, new Hashtable<String, String>(),
getHttpContext(dswContext, httpService));
- registerUnexportHook(exportRegistration, contextRoot);
+ registerUnexportHook(sref, contextRoot);
LOG.info("Successfully registered CXF DOSGi servlet at " + contextRoot);
} catch (Exception e) {
@@ -311,8 +298,7 @@ public class HttpServiceConfigurationTyp
* @param reference The service reference to track
* @param alias The HTTP servlet context alias
*/
- protected void registerUnexportHook(CXFExportRegistration export, String alias) {
- final ServiceReference sref = export.getExportedService();
+ protected void registerUnexportHook(ServiceReference sref, String alias) {
final Long sid = (Long) sref.getProperty(org.osgi.framework.Constants.SERVICE_ID);
LOG.log(Level.FINE, "Registering service listener for service with ID {0}", sid);
Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/JaxRSHttpServiceConfigurationTypeHandler.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/JaxRSHttpServiceConfigurationTypeHandler.java?rev=1405786&r1=1405785&r2=1405786&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/JaxRSHttpServiceConfigurationTypeHandler.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/JaxRSHttpServiceConfigurationTypeHandler.java Mon Nov 5 13:29:54 2012
@@ -32,6 +32,7 @@ import org.apache.cxf.jaxrs.JAXRSServerF
import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider;
import org.apache.cxf.jaxrs.model.UserResource;
import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
import org.osgi.service.remoteserviceadmin.EndpointDescription;
public class JaxRSHttpServiceConfigurationTypeHandler extends HttpServiceConfigurationTypeHandler {
@@ -43,16 +44,15 @@ public class JaxRSHttpServiceConfigurati
}
@Override
- public void createServer(CXFExportRegistration exportRegistration, BundleContext dswContext,
+ public ExportResult createServer(ServiceReference sref, BundleContext dswContext,
BundleContext callingContext, Map sd, Class<?> iClass, Object serviceBean) {
String contextRoot = getServletContextRoot(sd, iClass);
if (contextRoot == null) {
- LOG.warning("Remote address is unavailable");
- return;
+ throw new RuntimeException("Remote address is unavailable");
}
- Bus bus = registerServletAndGetBus(contextRoot, dswContext, exportRegistration);
+ Bus bus = registerServletAndGetBus(contextRoot, dswContext, sref);
JAXRSServerFactoryBean factory = new JAXRSServerFactoryBean();
factory.setBus(bus);
@@ -95,24 +95,12 @@ public class JaxRSHttpServiceConfigurati
Map<String, Object> endpointProps = createEndpointProps(sd, iClass, new String[] {
Constants.RS_CONFIG_TYPE
}, completeEndpointAddress, intents);
- EndpointDescription endpdDesc = null;
-
-
Thread.currentThread().setContextClassLoader(JAXRSServerFactoryBean.class.getClassLoader());
Server server = factory.create();
-
- endpdDesc = new EndpointDescription(endpointProps);
- exportRegistration.setServer(server);
-
- // add the information on the new Endpoint to the export registration
- exportRegistration.setEndpointdescription(endpdDesc);
- } catch (IntentUnsatifiedException iue) {
- exportRegistration.setException(iue);
+ return new ExportResult(endpointProps, server);
} finally {
Thread.currentThread().setContextClassLoader(oldClassLoader);
}
-
-
}
@Override
Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/JaxRSPojoConfigurationTypeHandler.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/JaxRSPojoConfigurationTypeHandler.java?rev=1405786&r1=1405785&r2=1405786&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/JaxRSPojoConfigurationTypeHandler.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/JaxRSPojoConfigurationTypeHandler.java Mon Nov 5 13:29:54 2012
@@ -112,15 +112,13 @@ public class JaxRSPojoConfigurationTypeH
}
@Override
- public void createServer(CXFExportRegistration exportRegistration, BundleContext dswContext,
+ public ExportResult createServer(ServiceReference sref, BundleContext dswContext,
BundleContext callingContext, Map sd, Class<?> iClass, Object serviceBean)
throws IntentUnsatifiedException {
String address = getPojoAddress(sd, iClass);
if (address == null) {
- LOG.warning("Remote address is unavailable");
- exportRegistration.setException(new Throwable("Remote address is unavailable"));
- return;
+ throw new RuntimeException("Remote address is unavailable");
}
LOG.info("Creating a " + iClass.getName()
@@ -167,13 +165,9 @@ public class JaxRSPojoConfigurationTypeH
Thread.currentThread().setContextClassLoader(JAXRSServerFactoryBean.class.getClassLoader());
Server server = factory.create();
- exportRegistration.setServer(server);
- endpdDesc = new EndpointDescription(endpointProps);
// add the information on the new Endpoint to the export registration
- exportRegistration.setEndpointdescription(endpdDesc);
- } catch (IntentUnsatifiedException iue) {
- exportRegistration.setException(iue);
+ return new ExportResult(endpointProps, server);
} finally {
Thread.currentThread().setContextClassLoader(oldClassLoader);
}
Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandler.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandler.java?rev=1405786&r1=1405785&r2=1405786&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandler.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandler.java Mon Nov 5 13:29:54 2012
@@ -88,28 +88,24 @@ public class PojoConfigurationTypeHandle
return null;
}
- public void createServer(CXFExportRegistration exportRegistration, BundleContext dswContext,
+ public ExportResult createServer(ServiceReference sref, BundleContext dswContext,
BundleContext callingContext, Map sd, Class<?> iClass, Object serviceBean)
throws IntentUnsatifiedException {
String address = getPojoAddress(sd, iClass);
if (address == null) {
- LOG.warning("Remote address is unavailable");
- exportRegistration.setException(new Throwable("Remote address is unavailable"));
- return;
+ throw new RuntimeException("Remote address is unavailable");
}
LOG.info("Creating a " + iClass.getName() + " endpoint from CXF PublishHook, address is " + address);
DataBinding databinding;
- String dataBindingImpl = (String)exportRegistration.getExportedService()
- .getProperty(Constants.WS_DATABINDING_PROP_KEY);
+ String dataBindingImpl = (String)sref.getProperty(Constants.WS_DATABINDING_PROP_KEY);
if ("jaxb".equals(dataBindingImpl)) {
databinding = new JAXBDataBinding();
} else {
databinding = new AegisDatabinding();
}
- String frontEndImpl = (String)exportRegistration.getExportedService()
- .getProperty(Constants.WS_FRONTEND_PROP_KEY);
+ String frontEndImpl = (String)sref.getProperty(Constants.WS_FRONTEND_PROP_KEY);
ServerFactoryBean factory = createServerFactoryBean(frontEndImpl);
factory.setServiceClass(iClass);
@@ -129,24 +125,12 @@ public class PojoConfigurationTypeHandle
Thread.currentThread().setContextClassLoader(ServerFactoryBean.class.getClassLoader());
Server server = factory.create();
- exportRegistration.setServer(server);
-
- // add the information on the new Endpoint to the export registration
- EndpointDescription ed = new EndpointDescription(endpointProps);
- exportRegistration.setEndpointdescription(ed);
-
- } catch (IntentUnsatifiedException iue) {
- exportRegistration.setException(iue);
+ return new ExportResult(endpointProps, server);
} finally {
Thread.currentThread().setContextClassLoader(oldClassLoader);
}
-
-
}
-
-
-
protected String getPojoAddress(Map sd, Class<?> iClass) {
String address = OsgiUtils.getProperty(sd, RemoteConstants.ENDPOINT_ID);
if(address == null && sd.get(RemoteConstants.ENDPOINT_ID)!=null ){
Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/WsdlConfigurationTypeHandler.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/WsdlConfigurationTypeHandler.java?rev=1405786&r1=1405785&r2=1405786&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/WsdlConfigurationTypeHandler.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/WsdlConfigurationTypeHandler.java Mon Nov 5 13:29:54 2012
@@ -103,7 +103,8 @@ public class WsdlConfigurationTypeHandle
return Service.create(wsdlAddress, serviceQname);
}
- public void createServer(CXFExportRegistration exportRegistration,
+ @Override
+ public ExportResult createServer(ServiceReference sref,
BundleContext dswContext,
BundleContext callingContext,
Map sd,
@@ -112,33 +113,27 @@ public class WsdlConfigurationTypeHandle
String location = OsgiUtils.getProperty(sd, Constants.WSDL_LOCATION);
if (location == null) {
- LOG.warning("WSDL location is unavailable");
- exportRegistration.setException(new Throwable("WSDL location is unavailable"));
- return;
+ throw new RuntimeException("WSDL location property is unavailable");
}
URL wsdlURL = dswContext.getBundle().getResource(location);
if (wsdlURL == null) {
- LOG.warning("WSDL resource is unavailable");
- exportRegistration.setException(new Throwable("WSDL resource is unavailable"));
- return;
+ throw new RuntimeException("WSDL resource at " + location + " is unavailable");
}
String address = getPojoAddress(sd, iClass);
String contextRoot = null;
if (address == null) {
contextRoot = getServletContextRoot(sd, iClass);
- if (contextRoot == null) {
- LOG.warning("Remote address is unavailable");
- }
- exportRegistration.setException(new Throwable("Remote address is unavailable"));
- return;
+ if (contextRoot == null) {
+ throw new RuntimeException("Remote address is unavailable");
+ }
}
LOG.info("Creating a " + iClass.getName() + " endpoint from CXF PublishHook, address is " + address);
Bus bus = null;
if (contextRoot != null) {
- bus = registerServletAndGetBus(contextRoot, dswContext, exportRegistration);
+ bus = registerServletAndGetBus(contextRoot, dswContext, sref);
}
DataBinding databinding = new JAXBDataBinding();
@@ -166,14 +161,7 @@ public class WsdlConfigurationTypeHandle
Thread.currentThread().setContextClassLoader(ServerFactoryBean.class.getClassLoader());
Server server = factory.create();
- exportRegistration.setServer(server);
-
- // add the information on the new Endpoint to the export registration
- EndpointDescription ed = new EndpointDescription(endpointProps);
- exportRegistration.setEndpointdescription(ed);
-
- } catch (IntentUnsatifiedException iue) {
- exportRegistration.setException(iue);
+ return new ExportResult(endpointProps, server);
} finally {
Thread.currentThread().setContextClassLoader(oldClassLoader);
}
Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/EventAdminHelper.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/EventAdminHelper.java?rev=1405786&r1=1405785&r2=1405786&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/EventAdminHelper.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/EventAdminHelper.java Mon Nov 5 13:29:54 2012
@@ -78,7 +78,7 @@ public class EventAdminHelper {
epd = ((ImportReferenceImpl)rsae.getImportReference()).getImportedEndpointAlways();
setIfNotNull(props, "import.registration", epd);
} else if (rsae.getExportReference() != null) {
- epd = ((ExportReferenceImpl)rsae.getExportReference()).getExportedEndpointAlways();
+ epd = ((ExportReferenceImpl)rsae.getExportReference()).getExportedEndpoint();
setIfNotNull(props, "export.registration", epd);
}
Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/EventProducer.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/EventProducer.java?rev=1405786&r1=1405785&r2=1405786&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/EventProducer.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/EventProducer.java Mon Nov 5 13:29:54 2012
@@ -95,7 +95,7 @@ public class EventProducer {
eaHelper.notifyEventAdmin(rsae);
}
- public void notifyRemoval(ExportRegistrationImpl eri) {
+ public void notifyRemoval(ExportRegistration eri) {
RemoteServiceAdminEvent rsae = null;
rsae = new RemoteServiceAdminEvent(RemoteServiceAdminEvent.EXPORT_UNREGISTRATION, bctx.getBundle(), eri.getExportReference(), eri.getException());
Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ExportReferenceImpl.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ExportReferenceImpl.java?rev=1405786&r1=1405785&r2=1405786&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ExportReferenceImpl.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ExportReferenceImpl.java Mon Nov 5 13:29:54 2012
@@ -21,33 +21,31 @@ package org.apache.cxf.dosgi.dsw.service
import org.osgi.framework.ServiceReference;
import org.osgi.service.remoteserviceadmin.EndpointDescription;
import org.osgi.service.remoteserviceadmin.ExportReference;
-import org.osgi.service.remoteserviceadmin.ExportRegistration;
public class ExportReferenceImpl implements ExportReference {
- private final ExportRegistrationImpl exportRegistration;
+ private final ServiceReference serviceReference;
+ private final EndpointDescription endpointDescription;
- public ExportReferenceImpl(ExportRegistration exportRegistration) {
- if (!(exportRegistration instanceof ExportRegistrationImpl)) {
- throw new IllegalArgumentException("Can only create a reference from ExportRegistrationImpl");
- }
- this.exportRegistration = (ExportRegistrationImpl) exportRegistration;
+ public ExportReferenceImpl(ServiceReference serviceReference, EndpointDescription endpointDescription) {
+ this.serviceReference = serviceReference;
+ this.endpointDescription = endpointDescription;
}
public EndpointDescription getExportedEndpoint() {
- return exportRegistration.getEndpointDescription();
+ return endpointDescription;
}
public ServiceReference getExportedService() {
- return exportRegistration.getExportedService();
- }
-
- protected EndpointDescription getExportedEndpointAlways() {
- return exportRegistration.getEndpointDescriptionAlways();
+ return serviceReference;
}
@Override
public int hashCode() {
- return 31 * 1 + ((exportRegistration == null) ? 0 : exportRegistration.hashCode());
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((endpointDescription == null) ? 0 : endpointDescription.hashCode());
+ result = prime * result + ((serviceReference == null) ? 0 : serviceReference.hashCode());
+ return result;
}
@Override
@@ -59,12 +57,18 @@ public class ExportReferenceImpl impleme
if (getClass() != obj.getClass())
return false;
ExportReferenceImpl other = (ExportReferenceImpl) obj;
- if (exportRegistration == null) {
- if (other.exportRegistration != null)
+ if (endpointDescription == null) {
+ if (other.endpointDescription != null)
return false;
- } else if (!exportRegistration.equals(other.exportRegistration))
+ } else if (!endpointDescription.equals(other.endpointDescription))
+ return false;
+ if (serviceReference == null) {
+ if (other.serviceReference != null)
+ return false;
+ } else if (!serviceReference.equals(other.serviceReference))
return false;
return true;
}
+
}
Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ExportRegistrationImpl.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ExportRegistrationImpl.java?rev=1405786&r1=1405785&r2=1405786&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ExportRegistrationImpl.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ExportRegistrationImpl.java Mon Nov 5 13:29:54 2012
@@ -25,7 +25,6 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.cxf.common.logging.LogUtils;
-import org.apache.cxf.dosgi.dsw.handlers.CXFExportRegistration;
import org.apache.cxf.endpoint.Server;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
@@ -38,18 +37,16 @@ import org.osgi.service.remoteserviceadm
import org.osgi.util.tracker.ServiceTracker;
import org.osgi.util.tracker.ServiceTrackerCustomizer;
-public class ExportRegistrationImpl implements ExportRegistration, CXFExportRegistration {
+public class ExportRegistrationImpl implements ExportRegistration {
private static final Logger LOG = LogUtils.getL7dLogger(ExportRegistrationImpl.class);
private Server server;
private boolean closed = false;
- private ServiceReference serviceReference = null;
- private EndpointDescription endpointDescription;
+
private Throwable exception = null;
private ExportRegistrationImpl parent = null;
- private volatile int instanceCount = 1;
private RemoteServiceAdminCore rsaCore;
@@ -57,105 +54,42 @@ public class ExportRegistrationImpl impl
private ServiceTracker serviceTracker;
- // provide a clone of the provided exp.Reg that is linked to this instance
- public ExportRegistrationImpl(ExportRegistrationImpl exportRegistration) {
-
- parent = exportRegistration;
- serviceReference = parent.getExportedService();
- endpointDescription = parent.getEndpointDescription();
- exception = parent.getException();
- rsaCore = parent.getRsaCore();
- parent.instanceAdded();
- }
-
- private void instanceAdded() {
- ++instanceCount;
- }
-
- public ExportRegistrationImpl(ServiceReference sref, EndpointDescription endpoint, RemoteServiceAdminCore remoteServiceAdminCore) {
- serviceReference = sref;
- endpointDescription = endpoint;
+ public ExportRegistrationImpl(ExportReference exportReference, RemoteServiceAdminCore remoteServiceAdminCore) {
+ this.exportReference = exportReference;
parent = this;
rsaCore = remoteServiceAdminCore;
}
public synchronized void close() {
- if (closed)
+ if (closed) {
return;
+ }
closed = true;
rsaCore.removeExportRegistration(this);
- parent.instanceClosed();
if (server != null) {
server.stop();
server = null;
}
- }
-
- private void instanceClosed() {
- --instanceCount;
- if (instanceCount <= 0) {
- // really close the ExReg
- // TODO close it and remove from management structure .... !
-
- LOG.fine("really closing ExportRegistartion now! ");
-
- synchronized (this) {
- if (server != null) {
- // FIXME: is this done like this ?
- server.stop();
- server = null;
- }
- }
- }
- }
-
- public EndpointDescription getEndpointDescription() {
- if (!closed)
- return endpointDescription;
- else
- return null;
+ exportReference = null;
+ exception = null;
}
public Throwable getException() {
- if (!closed)
- return exception;
- else
- return null;
- }
-
- protected ServiceReference getServiceReference() {
- return serviceReference;
- }
-
- /* (non-Javadoc)
- * @see org.apache.cxf.dosgi.dsw.service.CXFExportRegistration#getExportedService()
- */
- public ServiceReference getExportedService() throws IllegalStateException {
- if (!closed)
- return serviceReference;
- else
- return null;
- }
-
- /* (non-Javadoc)
- * @see org.apache.cxf.dosgi.dsw.service.CXFExportRegistration#setEndpointdescription(org.osgi.service.remoteserviceadmin.EndpointDescription)
- */
- public void setEndpointdescription(EndpointDescription epd) {
- endpointDescription = epd;
+ return exception;
}
@Override
public String toString() {
- String r = "Endpoint Desctiption for ServiceReference " + serviceReference;
+ String r = "Endpoint Desctiption for ServiceReference " + getExportReference().getExportedService();
r += "\n";
r += "*** EndpointDescription: **** \n";
- if (endpointDescription == null) {
+ if (getExportReference().getExportedService() == null) {
r += "---> NULL <---- \n";
} else {
- Set<Map.Entry<String,Object>> props = endpointDescription.getProperties().entrySet();
+ Set<Map.Entry<String,Object>> props = getExportReference().getExportedEndpoint().getProperties().entrySet();
for (Map.Entry<String,Object> entry : props) {
Object value = entry.getValue();
r += entry.getKey() + " => " +
@@ -165,38 +99,20 @@ public class ExportRegistrationImpl impl
return r;
}
- /* (non-Javadoc)
- * @see org.apache.cxf.dosgi.dsw.service.CXFExportRegistration#setServer(org.apache.cxf.endpoint.Server)
- */
public void setServer(Server server) {
this.server = server;
}
- /* (non-Javadoc)
- * @see org.apache.cxf.dosgi.dsw.service.CXFExportRegistration#getServer()
- */
- public Server getServer() {
- return server;
- }
-
- /* (non-Javadoc)
- * @see org.apache.cxf.dosgi.dsw.service.CXFExportRegistration#setException(java.lang.Throwable)
- */
public void setException(Throwable ex) {
exception = ex;
}
public ExportReference getExportReference() {
- synchronized (this) {
- if(exportReference==null){
- exportReference = new ExportReferenceImpl(this);
- }
- return exportReference;
- }
+ return exportReference;
}
protected EndpointDescription getEndpointDescriptionAlways() {
- return endpointDescription;
+ return getExportReference().getExportedEndpoint();
}
/**
@@ -217,7 +133,7 @@ public class ExportRegistrationImpl impl
}
Filter f;
- final Long sid = (Long)serviceReference.getProperty(Constants.SERVICE_ID);
+ final Long sid = (Long)getExportReference().getExportedService().getProperty(Constants.SERVICE_ID);
try {
f = bctx.createFilter("("+Constants.SERVICE_ID+"="+sid+")");
} catch (InvalidSyntaxException e) {
@@ -248,7 +164,4 @@ public class ExportRegistrationImpl impl
this.rsaCore = rsaCore;
}
- public RemoteServiceAdminCore getRsaCore() {
- return rsaCore;
- }
}
Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminCore.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminCore.java?rev=1405786&r1=1405785&r2=1405786&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminCore.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminCore.java Mon Nov 5 13:29:54 2012
@@ -30,12 +30,14 @@ import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
+import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.cxf.common.logging.LogUtils;
import org.apache.cxf.dosgi.dsw.Constants;
import org.apache.cxf.dosgi.dsw.handlers.ConfigTypeHandlerFactory;
import org.apache.cxf.dosgi.dsw.handlers.ConfigurationTypeHandler;
+import org.apache.cxf.dosgi.dsw.handlers.ExportResult;
import org.apache.cxf.dosgi.dsw.qos.IntentMap;
import org.apache.cxf.dosgi.dsw.qos.IntentUtils;
import org.apache.cxf.dosgi.dsw.util.ClassUtils;
@@ -105,10 +107,11 @@ public class RemoteServiceAdminCore impl
for (ExportRegistration exportRegistration : regs) {
if (exportRegistration instanceof ExportRegistrationImpl) {
ExportRegistrationImpl exportRegistrationImpl = (ExportRegistrationImpl) exportRegistration;
+ EndpointDescription epd = exportRegistration.getExportReference().getExportedEndpoint();
// create one copy for each distinct endpoint description
- if (!copiedEndpoints.contains(exportRegistrationImpl.getEndpointDescription())) {
- copiedEndpoints.add(exportRegistrationImpl.getEndpointDescription());
- copy.add(new ExportRegistrationImpl(exportRegistrationImpl));
+ if (!copiedEndpoints.contains(epd)) {
+ copiedEndpoints.add(epd);
+ copy.add(exportRegistration);
}
}
}
@@ -212,25 +215,12 @@ public class RemoteServiceAdminCore impl
return Collections.emptyList();
}
- LinkedHashMap<String, ExportRegistrationImpl> exportRegs = new LinkedHashMap<String, ExportRegistrationImpl>(
- 1);
-
- for (String iface : interfaces) {
- LOG.info("creating initial ExportDescription for interface " + iface
- + " with configuration types " + configurationTypes);
-
- // create initial ExportRegistartion
- ExportRegistrationImpl expReg = new ExportRegistrationImpl(serviceReference, null, this);
-
- exportRegs.put(iface, expReg);
-
- }
+ LinkedHashMap<String, ExportRegistrationImpl> exportRegs = new LinkedHashMap<String, ExportRegistrationImpl>();
// FIXME: move out of synchronized ... -> blocks until publication is finished
for (String iface : interfaces) {
LOG.info("creating server for interface " + iface);
- ExportRegistrationImpl exportRegistration = exportRegs.get(iface);
ConfigurationTypeHandler handler = getHandler(configurationTypes, serviceProperties,
getHandlerProperties());
Object serviceObject = bctx.getService(serviceReference);
@@ -248,20 +238,25 @@ public class RemoteServiceAdminCore impl
Class<?> interfaceClass = ClassUtils.getInterfaceClass(serviceObject, interfaceName);
if (interfaceClass != null) {
-
- handler.createServer(exportRegistration, bctx, callingContext, serviceProperties,
- interfaceClass, serviceObject);
-
- if(exportRegistration.getException()==null){
+ ExportRegistrationImpl exportRegistration = null;
+ try {
+ ExportResult exportResult = handler.createServer(serviceReference, bctx,
+ callingContext, serviceProperties, interfaceClass, serviceObject);
+ EndpointDescription epd = new EndpointDescription(exportResult.getEndpointProps());
+ ExportReference exportRef = new ExportReferenceImpl(serviceReference, epd);
+ exportRegistration = new ExportRegistrationImpl(exportRef , this);
+ exportRegistration.setServer(exportResult.getServer());
LOG.info("created server for interface " + iface);
-
exportRegistration.startServiceTracker(bctx);
- }else{
- LOG.warning("server creation for interface " + iface + " failed!");
+ } catch (Exception e) {
+ EndpointDescription epd = new EndpointDescription(null);
+ ExportReference exportRef = new ExportReferenceImpl(serviceReference, epd);
+ exportRegistration = new ExportRegistrationImpl(exportRef , this);
+ exportRegistration.setException(e);
+ LOG.log(Level.WARNING, "Server creation for interface " + iface + " failed!", e);
// Fire event happens at the end
}
-
-
+ exportRegs.put(iface, exportRegistration);
}
}
@@ -306,13 +301,16 @@ public class RemoteServiceAdminCore impl
public Collection<ExportReference> getExportedServices() {
synchronized (exportedServices) {
- List<ExportReference> ers = new ArrayList<ExportReference>();
+ List<ExportReference> eRefs = new ArrayList<ExportReference>();
for (Collection<ExportRegistration> exportRegistrations : exportedServices.values()) {
for (ExportRegistration er : exportRegistrations) {
- ers.add(new ExportReferenceImpl(er));
+ ExportReference eRef = er.getExportReference();
+ if (eRef != null) {
+ eRefs.add(eRef);
+ }
}
}
- return Collections.unmodifiableCollection(ers);
+ return Collections.unmodifiableCollection(eRefs);
}
}
@@ -472,17 +470,16 @@ public class RemoteServiceAdminCore impl
* Removes the provided Export Registration from the internal management structures -> intended to be used
* when the export Registration is closed
*/
- protected void removeExportRegistration(ExportRegistrationImpl eri) {
+ protected void removeExportRegistration(ExportRegistration eri) {
synchronized (exportedServices) {
- Collection<ExportRegistration> exRegs = exportedServices.get(eri.getServiceReference());
+ Collection<ExportRegistration> exRegs = exportedServices.get(eri.getExportReference().getExportedService());
if (exRegs != null && exRegs.contains(eri)) {
exRegs.remove(eri);
} else {
- LOG
- .severe("An exportRegistartion was intended to be removed form internal management structure but couldn't be found in it !! ");
+ LOG.severe("An exportRegistartion was intended to be removed form internal management structure but couldn't be found in it !! ");
}
if (exRegs == null || exRegs.size() == 0) {
- exportedServices.remove(eri.getServiceReference());
+ exportedServices.remove(eri.getExportReference().getExportedService());
}
eventProducer.notifyRemoval(eri);
Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/HttpServiceConfigurationTypeHandlerTest.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/HttpServiceConfigurationTypeHandlerTest.java?rev=1405786&r1=1405785&r2=1405786&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/HttpServiceConfigurationTypeHandlerTest.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/HttpServiceConfigurationTypeHandlerTest.java Mon Nov 5 13:29:54 2012
@@ -97,11 +97,9 @@ public class HttpServiceConfigurationTyp
props.put(Constants.WS_HTTP_SERVICE_CONTEXT, "/myRunnable");
//ServiceEndpointDescription sd = new ServiceEndpointDescriptionImpl(Runnable.class.getName(), props);
- ExportRegistrationImpl exReg = new ExportRegistrationImpl(sr,null,null);
-
// assertEquals("Precondition failed", 0, dp.getExposedServices().size());
assertEquals("Precondition failed", "", sfb.getAddress());
- h.createServer(exReg, dswContext, callingContext, props, Runnable.class, myService);
+ ExportResult exportResult = h.createServer(sr, dswContext, callingContext, props, Runnable.class, myService);
assertEquals("The address should be set to '/'. The Servlet context dictates the actual location.", "/", sfb.getAddress());
//assertEquals(1, dp.getExposedServices().size());
//assertSame(sr, dp.getExposedServices().iterator().next());
@@ -113,7 +111,7 @@ public class HttpServiceConfigurationTyp
hostName = "localhost";
}
- Map edProps = exReg.getEndpointDescription().getProperties();
+ Map edProps = exportResult.getEndpointProps();
assertNotNull(edProps.get(RemoteConstants.SERVICE_IMPORTED_CONFIGS));
assertEquals(1, ((String[])edProps.get(RemoteConstants.SERVICE_IMPORTED_CONFIGS)).length);
@@ -177,10 +175,8 @@ public class HttpServiceConfigurationTyp
Map<String, Object> props = new HashMap<String, Object>();
//ServiceEndpointDescription sd = new ServiceEndpointDescriptionImpl(Runnable.class.getName(), props);
- ExportRegistrationImpl exReg = new ExportRegistrationImpl(sr,null,null);
-
//assertEquals("Precondition failed", 0, dp.getExposedServices().size());
- h.createServer(exReg, dswContext, callingContext, props, Runnable.class, myService);
+ ExportResult exportResult = h.createServer(sr, dswContext, callingContext, props, Runnable.class, myService);
//assertEquals(1, dp.getExposedServices().size());
//assertSame(sr, dp.getExposedServices().iterator().next());
@@ -191,7 +187,7 @@ public class HttpServiceConfigurationTyp
hostname = "localhost";
}
- Map edProps = exReg.getEndpointDescription().getProperties();
+ Map edProps = exportResult.getEndpointProps();
assertNotNull(edProps.get(RemoteConstants.SERVICE_IMPORTED_CONFIGS));
assertEquals(1, ((String[])edProps.get(RemoteConstants.SERVICE_IMPORTED_CONFIGS)).length);
@@ -253,10 +249,8 @@ public class HttpServiceConfigurationTyp
props.put(Constants.WS_HTTP_SERVICE_CONTEXT, "/myRunnable");
//ServiceEndpointDescription sd = new ServiceEndpointDescriptionImpl(Runnable.class.getName(), props);
- ExportRegistrationImpl exReg = new ExportRegistrationImpl(sr,null,null);
-
//assertEquals("Precondition failed", 0, dp.getExposedServices().size());
- h.createServer(exReg, dswContext, callingContext, props, Runnable.class, myService);
+ ExportResult exportResult = h.createServer(sr, dswContext, callingContext, props, Runnable.class, myService);
//assertEquals(1, dp.getExposedServices().size());
//assertSame(sr, dp.getExposedServices().iterator().next());
@@ -266,7 +260,7 @@ public class HttpServiceConfigurationTyp
} catch (Exception e) {
hostName = "localhost";
}
- Map edProps = exReg.getEndpointDescription().getProperties();
+ Map edProps = exportResult.getEndpointProps();
assertNotNull(edProps.get(RemoteConstants.SERVICE_IMPORTED_CONFIGS));
assertEquals(1, ((String[])edProps.get(RemoteConstants.SERVICE_IMPORTED_CONFIGS)).length);
Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandlerTest.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandlerTest.java?rev=1405786&r1=1405785&r2=1405786&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandlerTest.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandlerTest.java Mon Nov 5 13:29:54 2012
@@ -287,13 +287,11 @@ public class PojoConfigurationTypeHandle
Map<String, Object> props = new HashMap<String, Object>();
props.put(Constants.WS_ADDRESS_PROPERTY, "http://alternate_host:80/myString");
-
- ExportRegistrationImpl exReg = new ExportRegistrationImpl(sr,null,null);
-
- p.createServer(exReg, dswContext, callingContext, props, String.class, myService);
+
+ ExportResult exportResult = p.createServer(sr, dswContext, callingContext, props, String.class, myService);
- Map edProps = exReg.getEndpointDescription().getProperties();
+ Map edProps = exportResult.getEndpointProps();
assertNotNull(edProps.get(RemoteConstants.SERVICE_IMPORTED_CONFIGS));
assertEquals(1, ((String[])edProps.get(RemoteConstants.SERVICE_IMPORTED_CONFIGS)).length);