tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject tomee git commit: TOMEE-1463 support WsFeatures in @WebServiceRef
Date Mon, 01 Dec 2014 18:10:46 GMT
Repository: tomee
Updated Branches:
  refs/heads/tomee-1.7.x 00a1d74a3 -> dc1587868


TOMEE-1463 support WsFeatures in @WebServiceRef


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

Branch: refs/heads/tomee-1.7.x
Commit: dc1587868b5a24385d10a4ea646555a27ebecec2
Parents: 00a1d74
Author: Romain Manni-Bucau <rmannibucau@apache.org>
Authored: Mon Dec 1 19:10:06 2014 +0100
Committer: Romain Manni-Bucau <rmannibucau@apache.org>
Committed: Mon Dec 1 19:10:06 2014 +0100

----------------------------------------------------------------------
 .../core/ivm/naming/JaxWsServiceReference.java  | 27 ++++++++++--
 .../client/WebServiceInjectionConfigurator.java | 45 +++++++++++++++++---
 2 files changed, 64 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/dc158786/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/naming/JaxWsServiceReference.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/naming/JaxWsServiceReference.java
b/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/naming/JaxWsServiceReference.java
index 72f9026..b139075 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/naming/JaxWsServiceReference.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/naming/JaxWsServiceReference.java
@@ -32,6 +32,7 @@ import javax.naming.InitialContext;
 import javax.naming.NamingException;
 import javax.xml.namespace.QName;
 import javax.xml.ws.Service;
+import javax.xml.ws.WebServiceFeature;
 import javax.xml.ws.handler.HandlerResolver;
 import java.net.MalformedURLException;
 import java.net.URL;
@@ -144,10 +145,18 @@ public class JaxWsServiceReference extends Reference {
             instance.setHandlerResolver(handlerResolver);
         }
 
+        final WebServiceClientCustomizer customizer = SystemInstance.get().getComponent(WebServiceClientCustomizer.class);
+        final Properties configuration = properties == null ? new Properties() : properties;
+
         final Object port;
         if (referenceClass != null && !Service.class.isAssignableFrom(referenceClass))
{
+            final WebServiceFeature[] features = customizer == null ? null : customizer.features(serviceQName,
configuration);
             // do port lookup
-            port = instance.getPort(referenceClass);
+            if (features == null || features.length == 0) {
+                port = instance.getPort(referenceClass);
+            } else {
+                port = instance.getPort(referenceClass, features);
+            }
         } else {
             // return service
             port = instance;
@@ -163,9 +172,8 @@ public class JaxWsServiceReference extends Reference {
                 portRefs);
         ServiceRefData.putServiceRefData(port, serviceRefData);
 
-        final WebServiceClientCustomizer customizer = SystemInstance.get().getComponent(WebServiceClientCustomizer.class);
         if (customizer != null) {
-            customizer.customize(port, properties == null ? new Properties() : properties);
+            customizer.customize(port, configuration);
         }
 
         return port;
@@ -182,6 +190,19 @@ public class JaxWsServiceReference extends Reference {
     }
 
     public interface WebServiceClientCustomizer {
+        /**
+         * @param qname QName of the webservice
+         * @param properties app configuration
+         * @return ws features associated with this endpoint
+         */
+        WebServiceFeature[] features(QName qname, Properties properties);
+
+        /**
+         * Note: it is recommanded to use same key type as in features() impl (ie qname)
+         *
+         * @param port the client instance
+         * @param properties configuration of the application
+         */
         void customize(Object port, Properties properties);
     }
 }

http://git-wip-us.apache.org/repos/asf/tomee/blob/dc158786/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/client/WebServiceInjectionConfigurator.java
----------------------------------------------------------------------
diff --git a/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/client/WebServiceInjectionConfigurator.java
b/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/client/WebServiceInjectionConfigurator.java
index 609b7c1..e5840ce 100644
--- a/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/client/WebServiceInjectionConfigurator.java
+++ b/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/client/WebServiceInjectionConfigurator.java
@@ -22,6 +22,7 @@ import org.apache.cxf.frontend.ClientProxy;
 import org.apache.openejb.OpenEJBException;
 import org.apache.openejb.assembler.classic.OpenEjbConfiguration;
 import org.apache.openejb.assembler.classic.ServiceInfo;
+import org.apache.openejb.assembler.classic.util.ServiceInfos;
 import org.apache.openejb.config.ConfigurationFactory;
 import org.apache.openejb.config.sys.Openejb;
 import org.apache.openejb.config.sys.Service;
@@ -30,9 +31,12 @@ import org.apache.openejb.loader.SystemInstance;
 import org.apache.openejb.util.LogCategory;
 import org.apache.openejb.util.Logger;
 
+import javax.xml.namespace.QName;
+import javax.xml.ws.WebServiceFeature;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.LinkedList;
 import java.util.List;
 import java.util.Properties;
 
@@ -54,11 +58,37 @@ import static org.apache.openejb.server.cxf.transport.util.CxfUtil.configureInte
  * Note: resources.xml are ignored for now (to be enhanced)
  */
 public class WebServiceInjectionConfigurator implements JaxWsServiceReference.WebServiceClientCustomizer
{
+    private static final String CXF_JAXWS_CLIENT_PREFIX = "cxf.jaxws.client.";
+
+    @Override
+    public WebServiceFeature[] features(final QName qname, final Properties properties) {
+        Collection<WebServiceFeature> list = null;
+        for (final String suffix : asList("", (qname == null ? "_" : qname.toString()) +
".")) {
+            final String wsFeatures = properties.getProperty(CXF_JAXWS_CLIENT_PREFIX + suffix
+ "wsFeatures");
+            if (wsFeatures != null) {
+                final Collection<Object> instances = ServiceInfos.resolve(createServiceInfos(properties),
wsFeatures.split(" *, *"));
+                if (instances != null && !instances.isEmpty()) {
+                    for (final Object i : instances) {
+                        if (!WebServiceFeature.class.isInstance(i)) {
+                            throw new IllegalArgumentException("Not a WebServiceFeature:
" + i);
+                        }
+                        if (list == null) { // lazy to avoid useless allocation in most of
cases
+                            list = new LinkedList<WebServiceFeature>();
+                        }
+                        list.add(WebServiceFeature.class.cast(i));
+                    }
+                }
+            }
+        }
+        return list != null ? list.toArray(new WebServiceFeature[list.size()]) : null;
+    }
+
     @Override
     public void customize(final Object o, final Properties properties) {
         try {
             if (!javax.xml.ws.Service.class.isInstance(o)) {
-                configure(ClientProxy.getClient(o), properties);
+                final Client client = ClientProxy.getClient(o);
+                configure(client, properties);
             }
         } catch (final Exception e) {
             Logger.getInstance(LogCategory.CXF, WebServiceInjectionConfigurator.class.getName())
@@ -74,13 +104,18 @@ public class WebServiceInjectionConfigurator implements JaxWsServiceReference.We
         for (final String suffix : asList("", client.getEndpoint().getEndpointInfo().getName().toString()
+ ".")) {
             // here (ie at runtime) we have no idea which services were linked to the app
             // so using tomee.xml ones for now (not that shocking since we externalize the
config with this class)
-            final OpenEjbConfiguration config = SystemInstance.get().getComponent(OpenEjbConfiguration.class);
-            final List<ServiceInfo> services = new ArrayList<ServiceInfo>(config.facilities
!= null && config.facilities.services != null ? config.facilities.services : Collections.<ServiceInfo>emptyList());
-            services.addAll(getServices(properties));
-            configureInterceptors(client, "cxf.jaxws.client." + suffix, services, properties);
+            final List<ServiceInfo> services = createServiceInfos(properties);
+            configureInterceptors(client, CXF_JAXWS_CLIENT_PREFIX + suffix, services, properties);
         }
     }
 
+    private List<ServiceInfo> createServiceInfos(final Properties properties) {
+        final OpenEjbConfiguration config = SystemInstance.get().getComponent(OpenEjbConfiguration.class);
+        final List<ServiceInfo> services = new ArrayList<ServiceInfo>(config.facilities
!= null && config.facilities.services != null ? config.facilities.services : Collections.<ServiceInfo>emptyList());
+        services.addAll(getServices(properties));
+        return services;
+    }
+
     private Collection<ServiceInfo> getServices(final Properties properties) {
         final ConfigurationFactory cf = SystemInstance.get().getComponent(ConfigurationFactory.class);
         if (cf == null || !ConfigurationFactory.class.isInstance(cf)) {


Mime
View raw message