cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amic...@apache.org
Subject [3/3] cxf-dosgi git commit: Extract duplicate handler functionality into BaseDistributionProvider base class
Date Fri, 10 Feb 2017 09:06:23 GMT
Extract duplicate handler functionality into BaseDistributionProvider base class


Project: http://git-wip-us.apache.org/repos/asf/cxf-dosgi/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf-dosgi/commit/bec02202
Tree: http://git-wip-us.apache.org/repos/asf/cxf-dosgi/tree/bec02202
Diff: http://git-wip-us.apache.org/repos/asf/cxf-dosgi/diff/bec02202

Branch: refs/heads/master
Commit: bec02202129f3bcb740c2f9762592f0cc79d7cc3
Parents: 776238e
Author: Amichai Rothman <amichai@apache.org>
Authored: Thu Feb 9 17:03:24 2017 +0200
Committer: Amichai Rothman <amichai@apache.org>
Committed: Fri Feb 10 11:05:00 2017 +0200

----------------------------------------------------------------------
 common/bnd.bnd                                  |  5 +-
 .../handlers/BaseDistributionProvider.java      | 79 ++++++++++++++++++++
 .../cxf/dosgi/dsw/handlers/rest/RsProvider.java | 49 ++----------
 .../cxf/dosgi/dsw/handlers/ws/WsProvider.java   | 50 ++-----------
 4 files changed, 95 insertions(+), 88 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/bec02202/common/bnd.bnd
----------------------------------------------------------------------
diff --git a/common/bnd.bnd b/common/bnd.bnd
index a8b330b..88689ec 100644
--- a/common/bnd.bnd
+++ b/common/bnd.bnd
@@ -1,8 +1,9 @@
 Import-Package: javax.servlet;version='[2,4)', javax.servlet.http;version='[2,4)', *
 Export-Package: \
+	org.apache.cxf.dosgi.common.endpoint,\
+	org.apache.cxf.dosgi.common.handlers,\
 	org.apache.cxf.dosgi.common.httpservice,\
-	org.apache.cxf.dosgi.common.util,\
 	org.apache.cxf.dosgi.common.intent,\
 	org.apache.cxf.dosgi.common.proxy,\
-	org.apache.cxf.dosgi.common.endpoint
+	org.apache.cxf.dosgi.common.util
 

http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/bec02202/common/src/main/java/org/apache/cxf/dosgi/common/handlers/BaseDistributionProvider.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/cxf/dosgi/common/handlers/BaseDistributionProvider.java
b/common/src/main/java/org/apache/cxf/dosgi/common/handlers/BaseDistributionProvider.java
new file mode 100644
index 0000000..0325543
--- /dev/null
+++ b/common/src/main/java/org/apache/cxf/dosgi/common/handlers/BaseDistributionProvider.java
@@ -0,0 +1,79 @@
+/**
+ * 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.common.handlers;
+
+import static org.apache.cxf.dosgi.common.util.PropertyHelper.getMultiValueProperty;
+
+import java.util.Collection;
+import java.util.Map;
+
+import org.apache.aries.rsa.spi.DistributionProvider;
+import org.apache.cxf.Bus;
+import org.apache.cxf.BusFactory;
+import org.apache.cxf.dosgi.common.httpservice.HttpServiceManager;
+import org.apache.cxf.dosgi.common.intent.IntentManager;
+import org.apache.cxf.endpoint.AbstractEndpointFactory;
+import org.osgi.framework.BundleContext;
+import org.osgi.service.remoteserviceadmin.EndpointDescription;
+import org.osgi.service.remoteserviceadmin.RemoteConstants;
+
+public abstract class BaseDistributionProvider implements DistributionProvider {
+
+    protected IntentManager intentManager;
+    protected HttpServiceManager httpServiceManager;
+
+    protected boolean configTypeSupported(Map<String, Object> endpointProps, String
configType) {
+        Collection<String> configs = getMultiValueProperty(endpointProps.get(RemoteConstants.SERVICE_EXPORTED_CONFIGS));
+        return configs == null || configs.isEmpty() || configs.contains(configType);
+    }
+
+    protected EndpointDescription createEndpointDesc(Map<String, Object> props,
+                                                     String[] importedConfigs,
+                                                     String addressPropName,
+                                                     String address,
+                                                     Collection<String> intents) {
+        props.put(RemoteConstants.SERVICE_IMPORTED_CONFIGS, importedConfigs);
+        props.put(addressPropName, address);
+        props.put(RemoteConstants.SERVICE_INTENTS, intents);
+        props.put(RemoteConstants.ENDPOINT_ID, address);
+        return new EndpointDescription(props);
+    }
+
+    protected Bus createBus(Long sid, BundleContext callingContext, String contextRoot,
+                            Map<String, Object> endpointProps) {
+        Bus bus = BusFactory.newInstance().createBus();
+        for (Map.Entry<String, Object> prop : endpointProps.entrySet()) {
+            if (prop.getKey().startsWith("cxf.bus.prop.")) {
+                bus.setProperty(prop.getKey().substring("cxf.bus.prop.".length()), prop.getValue());
+            }
+        }
+        if (contextRoot != null) {
+            httpServiceManager.registerServlet(bus, contextRoot, callingContext, sid);
+        }
+        return bus;
+    }
+
+    protected void addContextProperties(AbstractEndpointFactory factory, Map<String, Object>
sd, String propName) {
+        @SuppressWarnings("unchecked")
+        Map<String, Object> props = (Map<String, Object>)sd.get(propName);
+        if (props != null) {
+            factory.getProperties(true).putAll(props);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/bec02202/provider-rs/src/main/java/org/apache/cxf/dosgi/dsw/handlers/rest/RsProvider.java
----------------------------------------------------------------------
diff --git a/provider-rs/src/main/java/org/apache/cxf/dosgi/dsw/handlers/rest/RsProvider.java
b/provider-rs/src/main/java/org/apache/cxf/dosgi/dsw/handlers/rest/RsProvider.java
index 1c5e2f9..4f32c5a 100644
--- a/provider-rs/src/main/java/org/apache/cxf/dosgi/dsw/handlers/rest/RsProvider.java
+++ b/provider-rs/src/main/java/org/apache/cxf/dosgi/dsw/handlers/rest/RsProvider.java
@@ -18,7 +18,6 @@
  */
 package org.apache.cxf.dosgi.dsw.handlers.rest;
 
-import static org.apache.cxf.dosgi.common.util.PropertyHelper.getMultiValueProperty;
 import static org.osgi.service.remoteserviceadmin.RemoteConstants.REMOTE_CONFIGS_SUPPORTED;
 import static org.osgi.service.remoteserviceadmin.RemoteConstants.REMOTE_INTENTS_SUPPORTED;
 
@@ -38,15 +37,14 @@ import org.apache.aries.rsa.spi.DistributionProvider;
 import org.apache.aries.rsa.spi.Endpoint;
 import org.apache.aries.rsa.spi.IntentUnsatisfiedException;
 import org.apache.cxf.Bus;
-import org.apache.cxf.BusFactory;
 import org.apache.cxf.binding.BindingConfiguration;
 import org.apache.cxf.databinding.DataBinding;
 import org.apache.cxf.dosgi.common.endpoint.ServerEndpoint;
+import org.apache.cxf.dosgi.common.handlers.BaseDistributionProvider;
 import org.apache.cxf.dosgi.common.httpservice.HttpServiceManager;
 import org.apache.cxf.dosgi.common.intent.IntentManager;
 import org.apache.cxf.dosgi.common.proxy.ProxyFactory;
 import org.apache.cxf.dosgi.common.util.PropertyHelper;
-import org.apache.cxf.endpoint.AbstractEndpointFactory;
 import org.apache.cxf.endpoint.Server;
 import org.apache.cxf.feature.Feature;
 import org.apache.cxf.jaxrs.AbstractJAXRSFactoryBean;
@@ -66,12 +64,10 @@ import org.slf4j.LoggerFactory;
  REMOTE_CONFIGS_SUPPORTED + "=" + RsConstants.RS_CONFIG_TYPE,
  REMOTE_INTENTS_SUPPORTED + "="
 })
-public class RsProvider implements DistributionProvider {
+public class RsProvider extends BaseDistributionProvider implements DistributionProvider
{
 
     private static final Logger LOG = LoggerFactory.getLogger(RsProvider.class);
-    private IntentManager intentManager;
-    private HttpServiceManager httpServiceManager;
-    
+
     @Reference
     public void setHttpServiceManager(HttpServiceManager httpServiceManager) {
         this.httpServiceManager = httpServiceManager;
@@ -152,20 +148,6 @@ public class RsProvider implements DistributionProvider {
         return createServerFromFactory(factory, epd);
     }
 
-    protected Bus createBus(Long sid, BundleContext callingContext, String contextRoot,
-                            Map<String, Object> endpointProps) {
-        Bus bus = BusFactory.newInstance().createBus();
-        for (Map.Entry<String, Object> prop : endpointProps.entrySet()) {
-            if (prop.getKey().startsWith("cxf.bus.prop.")) {
-                bus.setProperty(prop.getKey().substring("cxf.bus.prop.".length()), prop.getValue());
-            }
-        }
-        if (contextRoot != null) {
-            httpServiceManager.registerServlet(bus, contextRoot, callingContext, sid);
-        }
-        return bus;
-    }
-
     private void applyIntents(List<Object> intents, AbstractJAXRSFactoryBean factory)
{
         List<Feature> features = intentManager.getIntents(Feature.class, intents);
         factory.setFeatures(features);
@@ -194,11 +176,6 @@ public class RsProvider implements DistributionProvider {
             || (intent instanceof ContextResolver);
     }
 
-    private boolean configTypeSupported(Map<String, Object> endpointProps, String configType)
{
-        Collection<String> configs = getMultiValueProperty(endpointProps.get(RemoteConstants.SERVICE_EXPORTED_CONFIGS));
-        return configs == null || configs.isEmpty() || configs.contains(configType);
-    }
-
     private Endpoint createServerFromFactory(JAXRSServerFactoryBean factory,
                                              EndpointDescription epd) {
         ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
@@ -238,22 +215,8 @@ public class RsProvider implements DistributionProvider {
         }
     }
 
-    private EndpointDescription createEndpointDesc(Map<String, Object> props, 
-                                                     String[] importedConfigs,
-                                                     String address,
-                                                     Set<String> intents) {
-        props.put(RemoteConstants.SERVICE_IMPORTED_CONFIGS, importedConfigs);
-        props.put(RsConstants.RS_ADDRESS_PROPERTY, address);
-        props.put(RemoteConstants.SERVICE_INTENTS, intents);
-        props.put(RemoteConstants.ENDPOINT_ID, address);
-        return new EndpointDescription(props);
-    }
-    
-    private static void addContextProperties(AbstractEndpointFactory factory, Map<String,
Object> sd, String propName) {
-        @SuppressWarnings("unchecked")
-        Map<String, Object> props = (Map<String, Object>)sd.get(propName);
-        if (props != null) {
-            factory.getProperties(true).putAll(props);
-        }
+    protected EndpointDescription createEndpointDesc(Map<String, Object> props, String[]
importedConfigs,
+                                                     String address, Collection<String>
intents) {
+        return super.createEndpointDesc(props, importedConfigs, RsConstants.RS_ADDRESS_PROPERTY,
address, intents);
     }
 }

http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/bec02202/provider-ws/src/main/java/org/apache/cxf/dosgi/dsw/handlers/ws/WsProvider.java
----------------------------------------------------------------------
diff --git a/provider-ws/src/main/java/org/apache/cxf/dosgi/dsw/handlers/ws/WsProvider.java
b/provider-ws/src/main/java/org/apache/cxf/dosgi/dsw/handlers/ws/WsProvider.java
index c13c93d..99e64d4 100644
--- a/provider-ws/src/main/java/org/apache/cxf/dosgi/dsw/handlers/ws/WsProvider.java
+++ b/provider-ws/src/main/java/org/apache/cxf/dosgi/dsw/handlers/ws/WsProvider.java
@@ -18,7 +18,6 @@
  */
 package org.apache.cxf.dosgi.dsw.handlers.ws;
 
-import static org.apache.cxf.dosgi.common.util.PropertyHelper.getMultiValueProperty;
 import static org.osgi.service.remoteserviceadmin.RemoteConstants.REMOTE_CONFIGS_SUPPORTED;
 import static org.osgi.service.remoteserviceadmin.RemoteConstants.REMOTE_INTENTS_SUPPORTED;
 
@@ -33,12 +32,12 @@ import org.apache.aries.rsa.spi.DistributionProvider;
 import org.apache.aries.rsa.spi.Endpoint;
 import org.apache.aries.rsa.spi.IntentUnsatisfiedException;
 import org.apache.cxf.Bus;
-import org.apache.cxf.BusFactory;
 import org.apache.cxf.aegis.databinding.AegisDatabinding;
 import org.apache.cxf.binding.BindingConfiguration;
 import org.apache.cxf.binding.soap.SoapBindingConfiguration;
 import org.apache.cxf.databinding.DataBinding;
 import org.apache.cxf.dosgi.common.endpoint.ServerEndpoint;
+import org.apache.cxf.dosgi.common.handlers.BaseDistributionProvider;
 import org.apache.cxf.dosgi.common.httpservice.HttpServiceManager;
 import org.apache.cxf.dosgi.common.intent.IntentManager;
 import org.apache.cxf.dosgi.common.proxy.ProxyFactory;
@@ -65,12 +64,11 @@ import org.slf4j.LoggerFactory;
  REMOTE_CONFIGS_SUPPORTED + "=" + WsConstants.WS_CONFIG_TYPE,
  REMOTE_INTENTS_SUPPORTED + "=" 
 })
-public class WsProvider implements DistributionProvider {
+public class WsProvider extends BaseDistributionProvider implements DistributionProvider
{
+
     private static final Logger LOG = LoggerFactory.getLogger(WsProvider.class);
     protected BundleContext bundleContext;
-    protected IntentManager intentManager;
-    protected HttpServiceManager httpServiceManager;
-    
+
     @Reference
     public void setHttpServiceManager(HttpServiceManager httpServiceManager) {
         this.httpServiceManager = httpServiceManager;
@@ -203,21 +201,10 @@ public class WsProvider implements DistributionProvider {
             factory.setBindingConfig(binding);
         }
     }
-
-    private boolean configTypeSupported(Map<String, Object> endpointProps, String configType)
{
-        Collection<String> configs = getMultiValueProperty(endpointProps.get(RemoteConstants.SERVICE_EXPORTED_CONFIGS));
-        return configs == null || configs.isEmpty() || configs.contains(configType);
-    }
     
-    protected EndpointDescription createEndpointDesc(Map<String, Object> props, 
-                                                     String[] importedConfigs,
-                                                     String address, 
-                                                     Collection<String> intents) {
-        props.put(RemoteConstants.SERVICE_IMPORTED_CONFIGS, importedConfigs);
-        props.put(WsConstants.WS_ADDRESS_PROPERTY, address);
-        props.put(RemoteConstants.SERVICE_INTENTS, intents);
-        props.put(RemoteConstants.ENDPOINT_ID, address);
-        return new EndpointDescription(props);
+    protected EndpointDescription createEndpointDesc(Map<String, Object> props, String[]
importedConfigs,
+                                                     String address, Collection<String>
intents) {
+        return super.createEndpointDesc(props, importedConfigs, WsConstants.WS_ADDRESS_PROPERTY,
address, intents);
     }
 
     private String getPojoAddress(Map<String, Object> sd, Class<?> iClass) {
@@ -248,34 +235,11 @@ public class WsProvider implements DistributionProvider {
         return address == null ? httpServiceManager.getDefaultAddress(iClass) : address;
     }
 
-    protected Bus createBus(Long sid, BundleContext callingContext, String contextRoot,
-                            Map<String, Object> endpointProps) {
-        Bus bus = BusFactory.newInstance().createBus();
-        for (Map.Entry<String, Object> prop : endpointProps.entrySet()) {
-            if (prop.getKey().startsWith("cxf.bus.prop.")) {
-                bus.setProperty(prop.getKey().substring("cxf.bus.prop.".length()), prop.getValue());
-            }
-        }
-        if (contextRoot != null) {
-            httpServiceManager.registerServlet(bus, contextRoot, callingContext, sid);
-        }
-        return bus;
-    }
-
     protected Endpoint createServerFromFactory(ServerFactoryBean factory, EndpointDescription
epd) {
         Server server = factory.create();
         return new ServerEndpoint(epd, server);
     }
 
-    protected static void addContextProperties(AbstractEndpointFactory factory, 
-                                               Map<String, Object> sd, String propName)
{
-        @SuppressWarnings("unchecked")
-        Map<String, Object> props = (Map<String, Object>)sd.get(propName);
-        if (props != null) {
-            factory.getProperties(true).putAll(props);
-        }
-    }
-    
     private DataBinding getDataBinding(Map<String, Object> sd, Class<?> iClass)
{
         return isJAXWS(sd, iClass) ? new JAXBDataBinding() : new AegisDatabinding();
     }


Mime
View raw message