Repository: tomee Updated Branches: refs/heads/tomee-1.7.x 6687dec8d -> fc6160f17
TOMEE-1458 @WebServiceRef cxf config support Project: http://git-wip-us.apache.org/repos/asf/tomee/repo Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/fc6160f1 Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/fc6160f1 Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/fc6160f1 Branch: refs/heads/tomee-1.7.x Commit: fc6160f17bbc8643b26eb6f766fc94d12e6a628a Parents: 6687dec Author: Romain Manni-Bucau <[email protected]> Authored: Wed Nov 26 19:53:46 2014 +0100 Committer: Romain Manni-Bucau <[email protected]> Committed: Wed Nov 26 19:58:31 2014 +0100 ---------------------------------------------------------------------- .../apache/openejb/assembler/DeployerEjb.java | 3 +- .../openejb/assembler/classic/Assembler.java | 6 +- .../assembler/classic/EjbJarBuilder.java | 2 +- .../classic/EnterpriseBeanBuilder.java | 4 +- .../assembler/classic/JndiEncBuilder.java | 14 ++- .../openejb/config/ConfigurationFactory.java | 10 +- .../core/ivm/naming/JaxWsServiceReference.java | 30 +++-- .../openejb/testing/ApplicationComposers.java | 10 ++ .../testing/ApplicationConfiguration.java | 28 +++++ .../openejb/web/LightweightWebAppBuilder.java | 4 +- .../server/cxf/transport/util/CxfUtil.java | 4 +- .../server/cxf/ConfigureCxfSecurity.java | 3 +- .../apache/openejb/server/cxf/CxfService.java | 7 ++ .../client/WebServiceInjectionConfigurator.java | 115 +++++++++++++++++++ .../server/cxf/WebServiceInjectionTest.java | 88 ++++++++++++++ .../tomee/catalina/TomcatWebAppBuilder.java | 7 +- .../java/org/apache/tomee/common/WsFactory.java | 6 +- 17 files changed, 312 insertions(+), 29 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tomee/blob/fc6160f1/container/openejb-core/src/main/java/org/apache/openejb/assembler/DeployerEjb.java ---------------------------------------------------------------------- diff --git a/container/openejb-core/src/main/java/org/apache/openejb/assembler/DeployerEjb.java b/container/openejb-core/src/main/java/org/apache/openejb/assembler/DeployerEjb.java index 0e97ff8..162b5b2 100644 --- a/container/openejb-core/src/main/java/org/apache/openejb/assembler/DeployerEjb.java +++ b/container/openejb-core/src/main/java/org/apache/openejb/assembler/DeployerEjb.java @@ -120,7 +120,8 @@ public class DeployerEjb implements Deployer { public DeployerEjb() { deploymentLoader = new DeploymentLoader(); - configurationFactory = new ConfigurationFactory(); + final ConfigurationFactory component = SystemInstance.get().getComponent(ConfigurationFactory.class); + configurationFactory = component == null ? new ConfigurationFactory() : component; assembler = (Assembler) SystemInstance.get().getComponent(org.apache.openejb.spi.Assembler.class); } http://git-wip-us.apache.org/repos/asf/tomee/blob/fc6160f1/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java ---------------------------------------------------------------------- diff --git a/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java b/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java index d5c11b6..29c7588 100644 --- a/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java +++ b/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java @@ -662,11 +662,11 @@ public class Assembler extends AssemblerTool implements org.apache.openejb.spi.A injections.addAll(injectionBuilder.buildInjections(appInfo.globalJndiEnc)); injections.addAll(injectionBuilder.buildInjections(appInfo.appJndiEnc)); - final JndiEncBuilder globalBuilder = new JndiEncBuilder(appInfo.globalJndiEnc, injections, appInfo.appId, null, GLOBAL_UNIQUE_ID, classLoader); + final JndiEncBuilder globalBuilder = new JndiEncBuilder(appInfo.globalJndiEnc, injections, appInfo.appId, null, GLOBAL_UNIQUE_ID, classLoader, appInfo.properties); final Map<String, Object> globalBindings = globalBuilder.buildBindings(JndiEncBuilder.JndiScope.global); final Context globalJndiContext = globalBuilder.build(globalBindings); - final JndiEncBuilder appBuilder = new JndiEncBuilder(appInfo.appJndiEnc, injections, appInfo.appId, null, appInfo.appId, classLoader); + final JndiEncBuilder appBuilder = new JndiEncBuilder(appInfo.appJndiEnc, injections, appInfo.appId, null, appInfo.appId, classLoader, appInfo.properties); final Map<String, Object> appBindings = appBuilder.buildBindings(JndiEncBuilder.JndiScope.app); final Context appJndiContext = appBuilder.build(appBindings); @@ -849,7 +849,7 @@ public class Assembler extends AssemblerTool implements org.apache.openejb.spi.A final List<Injection> clientInjections = injectionBuilder.buildInjections(clientInfo.jndiEnc); // build the enc - final JndiEncBuilder jndiEncBuilder = new JndiEncBuilder(clientInfo.jndiEnc, clientInjections, "Bean", clientInfo.moduleId, null, clientInfo.uniqueId, classLoader); + final JndiEncBuilder jndiEncBuilder = new JndiEncBuilder(clientInfo.jndiEnc, clientInjections, "Bean", clientInfo.moduleId, null, clientInfo.uniqueId, classLoader, new Properties()); // if there is at least a remote client classes // or if there is no local client classes // then, we can set the client flag http://git-wip-us.apache.org/repos/asf/tomee/blob/fc6160f1/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/EjbJarBuilder.java ---------------------------------------------------------------------- diff --git a/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/EjbJarBuilder.java b/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/EjbJarBuilder.java index bcfb645..6f7e32f 100644 --- a/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/EjbJarBuilder.java +++ b/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/EjbJarBuilder.java @@ -49,7 +49,7 @@ public class EjbJarBuilder { final InjectionBuilder injectionBuilder = new InjectionBuilder(classLoader); final List<Injection> moduleInjections = injectionBuilder.buildInjections(ejbJar.moduleJndiEnc); moduleInjections.addAll(appInjections); - final Context moduleJndiContext = new JndiEncBuilder(ejbJar.moduleJndiEnc, moduleInjections, null, ejbJar.moduleName, ejbJar.moduleUri, ejbJar.uniqueId, classLoader) + final Context moduleJndiContext = new JndiEncBuilder(ejbJar.moduleJndiEnc, moduleInjections, null, ejbJar.moduleName, ejbJar.moduleUri, ejbJar.uniqueId, classLoader, context.getProperties()) .build(JndiEncBuilder.JndiScope.module); final HashMap<String, BeanContext> deployments = new HashMap<String, BeanContext>(); http://git-wip-us.apache.org/repos/asf/tomee/blob/fc6160f1/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/EnterpriseBeanBuilder.java ---------------------------------------------------------------------- diff --git a/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/EnterpriseBeanBuilder.java b/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/EnterpriseBeanBuilder.java index 30a5662..ef60bb8 100644 --- a/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/EnterpriseBeanBuilder.java +++ b/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/EnterpriseBeanBuilder.java @@ -145,7 +145,9 @@ class EnterpriseBeanBuilder { } // build the enc - final JndiEncBuilder jndiEncBuilder = new JndiEncBuilder(bean.jndiEnc, injections, transactionType, moduleContext.getId(), null, moduleContext.getUniqueId(), moduleContext.getClassLoader()); + final JndiEncBuilder jndiEncBuilder = new JndiEncBuilder( + bean.jndiEnc, injections, transactionType, moduleContext.getId(), null, moduleContext.getUniqueId(), moduleContext.getClassLoader(), + moduleContext.getAppContext() == null ? moduleContext.getProperties() : moduleContext.getAppContext().getProperties()); final Context compJndiContext = jndiEncBuilder.build(JndiEncBuilder.JndiScope.comp); bind(compJndiContext, "module", moduleContext.getModuleJndiContext()); bind(compJndiContext, "app", moduleContext.getAppContext().getAppJndiContext()); http://git-wip-us.apache.org/repos/asf/tomee/blob/fc6160f1/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/JndiEncBuilder.java ---------------------------------------------------------------------- diff --git a/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/JndiEncBuilder.java b/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/JndiEncBuilder.java index 91ce25d..bf0eb60 100644 --- a/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/JndiEncBuilder.java +++ b/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/JndiEncBuilder.java @@ -88,6 +88,7 @@ import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Properties; import java.util.TreeMap; import java.util.concurrent.Callable; @@ -112,15 +113,17 @@ public class JndiEncBuilder { private final String uniqueId; private final Collection<Injection> injections; private final ClassLoader classLoader; + private final Properties properties; private boolean useCrossClassLoaderRef = true; private boolean client; - public JndiEncBuilder(final JndiEncInfo jndiEnc, final Collection<Injection> injections, final String moduleId, final URI moduleUri, final String uniqueId, final ClassLoader classLoader) throws OpenEJBException { - this(jndiEnc, injections, null, moduleId, moduleUri, uniqueId, classLoader); + public JndiEncBuilder(final JndiEncInfo jndiEnc, final Collection<Injection> injections, final String moduleId, final URI moduleUri, final String uniqueId, final ClassLoader classLoader, final Properties appProperties) throws OpenEJBException { + this(jndiEnc, injections, null, moduleId, moduleUri, uniqueId, classLoader, appProperties); } - public JndiEncBuilder(final JndiEncInfo jndiEnc, final Collection<Injection> injections, final String transactionType, final String moduleId, final URI moduleUri, final String uniqueId, final ClassLoader classLoader) throws OpenEJBException { + public JndiEncBuilder(final JndiEncInfo jndiEnc, final Collection<Injection> injections, final String transactionType, final String moduleId, + final URI moduleUri, final String uniqueId, final ClassLoader classLoader, final Properties appProperties) throws OpenEJBException { this.jndiEnc = jndiEnc; this.injections = injections; beanManagedTransactions = transactionType != null && transactionType.equalsIgnoreCase("Bean"); @@ -130,6 +133,8 @@ public class JndiEncBuilder { this.uniqueId = uniqueId; this.classLoader = classLoader; + + this.properties = appProperties; } public boolean isUseCrossClassLoaderRef() { @@ -492,7 +497,8 @@ public class JndiEncBuilder { wsdlUrl, portRefs, handlerChains, - injections); + injections, + properties); bindings.put(normalize(referenceInfo.referenceName), reference); } else { final ServiceRefData serviceRefData = new ServiceRefData(referenceInfo.id, http://git-wip-us.apache.org/repos/asf/tomee/blob/fc6160f1/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java ---------------------------------------------------------------------- diff --git a/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java b/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java index f2a7cb8..b23f9d0 100644 --- a/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java +++ b/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java @@ -197,6 +197,7 @@ public class ConfigurationFactory implements OpenEjbConfigurationFactory { if (SystemInstance.get().getComponent(ClassLoaderEnricher.class) == null) { SystemInstance.get().setComponent(ClassLoaderEnricher.class, new ClassLoaderEnricher()); } + SystemInstance.get().setComponent(ConfigurationFactory.class, this); // annotation deployer encapsulate some logic, to be able to push to it some config // we give the ability here to get the internal deployer to push the config values @@ -684,11 +685,14 @@ public class ConfigurationFactory implements OpenEjbConfigurationFactory { return configureService(container, infoClass); } - private void loadPropertiesDeclaredConfiguration(final Openejb openejb) { + public static void loadPropertiesDeclaredConfiguration(final Openejb openejb) { final Properties sysProps = new Properties(System.getProperties()); sysProps.putAll(SystemInstance.get().getProperties()); + fillOpenEjb(openejb, sysProps); + } + public static void fillOpenEjb(final Openejb openejb, final Properties sysProps) { for (final Map.Entry<Object, Object> entry : sysProps.entrySet()) { final Object o = entry.getValue(); @@ -714,7 +718,7 @@ public class ConfigurationFactory implements OpenEjbConfigurationFactory { } } - protected Object toConfigDeclaration(final String name, String value) throws URISyntaxException, OpenEJBException { + protected static Object toConfigDeclaration(final String name, String value) throws URISyntaxException, OpenEJBException { // value = value.replaceFirst("(.)#", "$1%23"); value = value.replaceFirst("(provider=[^#=&]+)#", "$1%23"); @@ -723,7 +727,7 @@ public class ConfigurationFactory implements OpenEjbConfigurationFactory { return toConfigDeclaration(name, uri); } - public Object toConfigDeclaration(final String id, final URI uri) throws OpenEJBException { + public static Object toConfigDeclaration(final String id, final URI uri) throws OpenEJBException { final String serviceType; try { serviceType = uri.getHost(); http://git-wip-us.apache.org/repos/asf/tomee/blob/fc6160f1/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 a4a6b0f..72f9026 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 @@ -40,6 +40,7 @@ import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Properties; import java.util.Set; public class JaxWsServiceReference extends Reference { @@ -51,11 +52,17 @@ public class JaxWsServiceReference extends Reference { private final URL wsdlUrl; private final List<HandlerChainData> handlerChains = new ArrayList<HandlerChainData>(); private final Collection<Injection> injections; + private final Properties properties; private PortAddressRegistry portAddressRegistry; private final List<PortRefData> portRefs = new ArrayList<PortRefData>(); - public JaxWsServiceReference(final String id, final QName serviceQName, final Class<? extends Service> serviceClass, final QName portQName, final Class<?> referenceClass, final URL wsdlUrl, final List<PortRefData> portRefs, final List<HandlerChainData> handlerChains, final Collection<Injection> injections) { + public JaxWsServiceReference(final String id, final QName serviceQName, final Class<? extends Service> serviceClass, + final QName portQName, final Class<?> referenceClass, final URL wsdlUrl, + final List<PortRefData> portRefs, final List<HandlerChainData> handlerChains, + final Collection<Injection> injections, + final Properties properties) { this.id = id; + this.properties = properties; this.serviceQName = serviceQName; this.serviceClass = serviceClass; this.portQName = portQName; @@ -148,14 +155,19 @@ public class JaxWsServiceReference extends Reference { // register the service data so it can be fetched when the service is passed over the EJBd protocol final ServiceRefData serviceRefData = new ServiceRefData(id, - serviceQName, - serviceClass, portQName, - referenceClass, - wsdlUrl, - handlerChains, - portRefs); + serviceQName, + serviceClass, portQName, + referenceClass, + wsdlUrl, + handlerChains, + portRefs); ServiceRefData.putServiceRefData(port, serviceRefData); + final WebServiceClientCustomizer customizer = SystemInstance.get().getComponent(WebServiceClientCustomizer.class); + if (customizer != null) { + customizer.customize(port, properties == null ? new Properties() : properties); + } + return port; } @@ -168,4 +180,8 @@ public class JaxWsServiceReference extends Reference { } return portAddressRegistry; } + + public interface WebServiceClientCustomizer { + void customize(Object port, Properties properties); + } } http://git-wip-us.apache.org/repos/asf/tomee/blob/fc6160f1/container/openejb-core/src/main/java/org/apache/openejb/testing/ApplicationComposers.java ---------------------------------------------------------------------- diff --git a/container/openejb-core/src/main/java/org/apache/openejb/testing/ApplicationComposers.java b/container/openejb-core/src/main/java/org/apache/openejb/testing/ApplicationComposers.java index 5b0df66..af8ee36 100644 --- a/container/openejb-core/src/main/java/org/apache/openejb/testing/ApplicationComposers.java +++ b/container/openejb-core/src/main/java/org/apache/openejb/testing/ApplicationComposers.java @@ -700,6 +700,16 @@ public final class ApplicationComposers { appModule = newModule; } + // config for the app + for (final Map.Entry<Object, List<Method>> method : findAnnotatedMethods(configs, ApplicationConfiguration.class).entrySet()) { + for (final Method m : method.getValue()) { + final Object o = m.invoke(method.getKey()); + if (Properties.class.isInstance(o)) { + appModule.getProperties().putAll(Properties.class.cast(o)); + } + } + } + // copy ejb into beans if cdi is activated and init finder for (final EjbModule ejb : appModule.getEjbModules()) { final EnterpriseBean[] enterpriseBeans = ejb.getEjbJar().getEnterpriseBeans(); http://git-wip-us.apache.org/repos/asf/tomee/blob/fc6160f1/container/openejb-core/src/main/java/org/apache/openejb/testing/ApplicationConfiguration.java ---------------------------------------------------------------------- diff --git a/container/openejb-core/src/main/java/org/apache/openejb/testing/ApplicationConfiguration.java b/container/openejb-core/src/main/java/org/apache/openejb/testing/ApplicationConfiguration.java new file mode 100644 index 0000000..09819b2 --- /dev/null +++ b/container/openejb-core/src/main/java/org/apache/openejb/testing/ApplicationConfiguration.java @@ -0,0 +1,28 @@ +/* + * 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.openejb.testing; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target(ElementType.METHOD) +@Retention(RetentionPolicy.RUNTIME) +public @interface ApplicationConfiguration { +} http://git-wip-us.apache.org/repos/asf/tomee/blob/fc6160f1/container/openejb-core/src/main/java/org/apache/openejb/web/LightweightWebAppBuilder.java ---------------------------------------------------------------------- diff --git a/container/openejb-core/src/main/java/org/apache/openejb/web/LightweightWebAppBuilder.java b/container/openejb-core/src/main/java/org/apache/openejb/web/LightweightWebAppBuilder.java index e604658..315449c 100644 --- a/container/openejb-core/src/main/java/org/apache/openejb/web/LightweightWebAppBuilder.java +++ b/container/openejb-core/src/main/java/org/apache/openejb/web/LightweightWebAppBuilder.java @@ -112,11 +112,11 @@ public class LightweightWebAppBuilder implements WebAppBuilder { final Map<String, Object> bindings = new HashMap<String, Object>(); bindings.putAll(appContext.getBindings()); - bindings.putAll(new JndiEncBuilder(webAppInfo.jndiEnc, injections, webAppInfo.moduleId, "Bean", null, webAppInfo.uniqueId, classLoader).buildBindings(JndiEncBuilder.JndiScope.comp)); + bindings.putAll(new JndiEncBuilder(webAppInfo.jndiEnc, injections, webAppInfo.moduleId, "Bean", null, webAppInfo.uniqueId, classLoader, appInfo.properties).buildBindings(JndiEncBuilder.JndiScope.comp)); final WebContext webContext = new WebContext(appContext); webContext.setBindings(bindings); - webContext.getBindings().putAll(new JndiEncBuilder(webAppInfo.jndiEnc, injections, webAppInfo.moduleId, "Bean", null, webAppInfo.uniqueId, classLoader).buildBindings(JndiEncBuilder.JndiScope.comp)); + webContext.getBindings().putAll(new JndiEncBuilder(webAppInfo.jndiEnc, injections, webAppInfo.moduleId, "Bean", null, webAppInfo.uniqueId, classLoader, appInfo.properties).buildBindings(JndiEncBuilder.JndiScope.comp)); webContext.setJndiEnc(WebInitialContext.create(bindings, appContext.getGlobalJndiContext())); webContext.setClassLoader(classLoader); webContext.setId(webAppInfo.moduleId); http://git-wip-us.apache.org/repos/asf/tomee/blob/fc6160f1/server/openejb-cxf-transport/src/main/java/org/apache/openejb/server/cxf/transport/util/CxfUtil.java ---------------------------------------------------------------------- diff --git a/server/openejb-cxf-transport/src/main/java/org/apache/openejb/server/cxf/transport/util/CxfUtil.java b/server/openejb-cxf-transport/src/main/java/org/apache/openejb/server/cxf/transport/util/CxfUtil.java index 6d8001c..8747fe2 100644 --- a/server/openejb-cxf-transport/src/main/java/org/apache/openejb/server/cxf/transport/util/CxfUtil.java +++ b/server/openejb-cxf-transport/src/main/java/org/apache/openejb/server/cxf/transport/util/CxfUtil.java @@ -28,8 +28,8 @@ import org.apache.cxf.configuration.spring.MapProvider; import org.apache.cxf.databinding.DataBinding; import org.apache.cxf.endpoint.AbstractEndpointFactory; import org.apache.cxf.feature.AbstractFeature; -import org.apache.cxf.interceptor.AbstractBasicInterceptorProvider; import org.apache.cxf.interceptor.Interceptor; +import org.apache.cxf.interceptor.InterceptorProvider; import org.apache.cxf.management.InstrumentationManager; import org.apache.cxf.management.jmx.InstrumentationManagerImpl; import org.apache.cxf.message.Message; @@ -188,7 +188,7 @@ public final class CxfUtil { } } - public static void configureInterceptors(final AbstractBasicInterceptorProvider abip, final String prefix, final Collection<ServiceInfo> availableServices, final Properties beanConfig) { + public static void configureInterceptors(final InterceptorProvider abip, final String prefix, final Collection<ServiceInfo> availableServices, final Properties beanConfig) { // interceptors final String inInterceptorsIds = beanConfig.getProperty(prefix + IN_INTERCEPTORS); if (inInterceptorsIds != null && !inInterceptorsIds.trim().isEmpty()) { http://git-wip-us.apache.org/repos/asf/tomee/blob/fc6160f1/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/ConfigureCxfSecurity.java ---------------------------------------------------------------------- diff --git a/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/ConfigureCxfSecurity.java b/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/ConfigureCxfSecurity.java index 0d73cda..e969bc5 100644 --- a/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/ConfigureCxfSecurity.java +++ b/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/ConfigureCxfSecurity.java @@ -19,6 +19,7 @@ package org.apache.openejb.server.cxf; import org.apache.cxf.binding.soap.saaj.SAAJInInterceptor; import org.apache.cxf.binding.soap.saaj.SAAJOutInterceptor; import org.apache.cxf.endpoint.Endpoint; +import org.apache.cxf.interceptor.InterceptorProvider; import org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor; import org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor; import org.apache.openejb.core.webservices.PortData; @@ -99,7 +100,7 @@ public class ConfigureCxfSecurity { return cl.loadClass(validator).newInstance(); } - public static final void setupWSS4JChain(final Endpoint endpoint, final Map<String, Object> inProps, final Map<String, Object> outProps) { + public static final void setupWSS4JChain(final InterceptorProvider endpoint, final Map<String, Object> inProps, final Map<String, Object> outProps) { if (null != inProps && !inProps.isEmpty()) { endpoint.getInInterceptors().add(new SAAJInInterceptor()); http://git-wip-us.apache.org/repos/asf/tomee/blob/fc6160f1/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/CxfService.java ---------------------------------------------------------------------- diff --git a/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/CxfService.java b/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/CxfService.java index aedbd7f..78833b1 100644 --- a/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/CxfService.java +++ b/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/CxfService.java @@ -20,8 +20,11 @@ package org.apache.openejb.server.cxf; import org.apache.cxf.Bus; import org.apache.openejb.BeanContext; import org.apache.openejb.assembler.classic.util.ServiceConfiguration; +import org.apache.openejb.core.ivm.naming.JaxWsServiceReference; import org.apache.openejb.core.webservices.PortData; +import org.apache.openejb.loader.SystemInstance; import org.apache.openejb.server.cxf.client.SaajInterceptor; +import org.apache.openejb.server.cxf.client.WebServiceInjectionConfigurator; import org.apache.openejb.server.cxf.ejb.EjbWsContainer; import org.apache.openejb.server.cxf.pojo.PojoWsContainer; import org.apache.openejb.server.cxf.transport.HttpTransportFactory; @@ -54,6 +57,10 @@ public class CxfService extends WsService { SaajInterceptor.registerInterceptors(); initBusTransport(CxfUtil.getBus()); + + if (SystemInstance.get().getComponent(JaxWsServiceReference.WebServiceClientCustomizer.class) == null) { + SystemInstance.get().setComponent(JaxWsServiceReference.WebServiceClientCustomizer.class, new WebServiceInjectionConfigurator()); + } } private void initBusTransport(final Bus bus) { http://git-wip-us.apache.org/repos/asf/tomee/blob/fc6160f1/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 new file mode 100644 index 0000000..5feceea --- /dev/null +++ b/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/client/WebServiceInjectionConfigurator.java @@ -0,0 +1,115 @@ +/** + * + * 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.openejb.server.cxf.client; + +import org.apache.cxf.endpoint.Client; +import org.apache.cxf.frontend.ClientProxy; +import org.apache.openejb.OpenEJBException; +import org.apache.openejb.assembler.classic.Assembler; +import org.apache.openejb.assembler.classic.OpenEjbConfiguration; +import org.apache.openejb.assembler.classic.OpenEjbConfigurationFactory; +import org.apache.openejb.assembler.classic.ServiceInfo; +import org.apache.openejb.config.ConfigurationFactory; +import org.apache.openejb.config.sys.Openejb; +import org.apache.openejb.config.sys.Service; +import org.apache.openejb.core.ivm.naming.JaxWsServiceReference; +import org.apache.openejb.loader.SystemInstance; +import org.apache.openejb.util.LogCategory; +import org.apache.openejb.util.Logger; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Properties; + +import static java.util.Arrays.asList; +import static org.apache.openejb.server.cxf.ConfigureCxfSecurity.getPropsFromProperties; +import static org.apache.openejb.server.cxf.ConfigureCxfSecurity.setupWSS4JChain; +import static org.apache.openejb.server.cxf.transport.util.CxfUtil.configureInterceptors; + +/** + * Used to configure a @WebServiceRef. + * Config uses application.properties. + * Format is: + * + * # global for all clients + * cxf.jaxws.client.out-interceptors = com.foo.MyInInterceptor + * # specific + * cxf.jaxws.client.{ns}MyPort.out-interceptors = com.foo.MyInInterceptor + * + * Services can be defines in tomee.xml or application.properties. + * + * Note: resources.xml are ignored for now (to be enhanced) + */ +public class WebServiceInjectionConfigurator implements JaxWsServiceReference.WebServiceClientCustomizer { + @Override + public void customize(final Object o, final Properties properties) { + try { + configure(ClientProxy.getClient(o), properties); + } catch (final Exception e) { + Logger.getInstance(LogCategory.CXF, WebServiceInjectionConfigurator.class.getName()) + .error(e.getMessage(), e); + } + } + + private void configure(final Client client, final Properties properties) { + if (properties == null) { + return; + } + + for (final String suffix : asList("", client.getEndpoint().getEndpointInfo().getName().toString() + ".")) { + // wss4j which is historically quite particular + setupWSS4JChain(client, + getPropsFromProperties(properties, "cxf.jaxws.client.wss4j.in." + suffix), + getPropsFromProperties(properties, "cxf.jaxws.client.wss4j.out." + suffix)); + + // 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); + } + } + + private Collection<ServiceInfo> getServices(final Properties properties) { + final ConfigurationFactory cf = SystemInstance.get().getComponent(ConfigurationFactory.class); + if (cf == null || !ConfigurationFactory.class.isInstance(cf)) { + return Collections.emptyList(); + } + + final Openejb openejb = new Openejb(); + ConfigurationFactory.fillOpenEjb(openejb, properties); + + final List<Service> services = openejb.getServices(); + if (services.isEmpty()) { + return Collections.emptyList(); + } + + final Collection<ServiceInfo> info = new ArrayList<ServiceInfo>(services.size()); + for (final Service s : services) { + try { + info.add(cf.configureService(s, ServiceInfo.class)); + } catch (final OpenEJBException e) { + throw new IllegalArgumentException(e); + } + } + return info; + } +} http://git-wip-us.apache.org/repos/asf/tomee/blob/fc6160f1/server/openejb-cxf/src/test/java/org/apache/openejb/server/cxf/WebServiceInjectionTest.java ---------------------------------------------------------------------- diff --git a/server/openejb-cxf/src/test/java/org/apache/openejb/server/cxf/WebServiceInjectionTest.java b/server/openejb-cxf/src/test/java/org/apache/openejb/server/cxf/WebServiceInjectionTest.java new file mode 100644 index 0000000..13c6088 --- /dev/null +++ b/server/openejb-cxf/src/test/java/org/apache/openejb/server/cxf/WebServiceInjectionTest.java @@ -0,0 +1,88 @@ +/** + * 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.openejb.server.cxf; + +import org.apache.cxf.endpoint.Client; +import org.apache.cxf.feature.LoggingFeature; +import org.apache.cxf.frontend.ClientProxy; +import org.apache.cxf.interceptor.LoggingOutInterceptor; +import org.apache.openejb.jee.WebApp; +import org.apache.openejb.junit.ApplicationComposer; +import org.apache.openejb.testing.ApplicationConfiguration; +import org.apache.openejb.testing.Classes; +import org.apache.openejb.testing.Configuration; +import org.apache.openejb.testing.EnableServices; +import org.apache.openejb.testing.Module; +import org.apache.openejb.testng.PropertiesBuilder; +import org.junit.Test; +import org.junit.runner.RunWith; + +import javax.ejb.Singleton; +import javax.jws.WebService; +import javax.xml.ws.WebServiceRef; + +import java.util.Properties; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +@EnableServices("jax-ws") +@RunWith(ApplicationComposer.class) +public class WebServiceInjectionTest { + @Module + @Classes(innerClassesAsBean = true) + public WebApp module() { + return new WebApp(); + } + + @WebServiceRef + private MyWsApi api; + + @Test + public void checkInjection() { + // assertEquals("ok", api.test()); // local call so skip it but check config which is actually the only interesting thing + final Client client = ClientProxy.getClient(api); + assertNotNull(client); + assertEquals(1, client.getOutInterceptors().size()); + assertTrue(LoggingOutInterceptor.class.isInstance(client.getOutInterceptors().iterator().next())); + } + + @ApplicationConfiguration + public Properties props() { + // return new PropertiesBuilder().p("cxf.jaxws.client.out-interceptors", LoggingOutInterceptor.class.getName()).build(); + // return new PropertiesBuilder().p("cxf.jaxws.client.{http://cxf.server.openejb.apache.org/}MyWebservicePort.out-interceptors", LoggingOutInterceptor.class.getName()).build(); + return new PropertiesBuilder() + .p("cxf.jaxws.client.{http://cxf.server.openejb.apache.org/}MyWebservicePort.out-interceptors", "loo") + .p("loo", "new://Service?class-name=" + LoggingOutInterceptor.class.getName()) + .build(); + } + + @WebService + public static interface MyWsApi { + String test(); + } + + @WebService + @Singleton + public static class MyWebservice implements MyWsApi { + @Override + public String test() { + return "ok"; + } + } +} http://git-wip-us.apache.org/repos/asf/tomee/blob/fc6160f1/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatWebAppBuilder.java ---------------------------------------------------------------------- diff --git a/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatWebAppBuilder.java b/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatWebAppBuilder.java index a24e6f0..743193e 100644 --- a/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatWebAppBuilder.java +++ b/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatWebAppBuilder.java @@ -1373,7 +1373,7 @@ public class TomcatWebAppBuilder implements WebAppBuilder, ContextListener, Pare // jndi bindings webContext.getBindings().putAll(appContext.getBindings()); - webContext.getBindings().putAll(getJndiBuilder(classLoader, webAppInfo, injections).buildBindings(JndiEncBuilder.JndiScope.comp)); + webContext.getBindings().putAll(getJndiBuilder(classLoader, webAppInfo, injections, appContext.getProperties()).buildBindings(JndiEncBuilder.JndiScope.comp)); final JavaeeInstanceManager instanceManager = new JavaeeInstanceManager(webContext); standardContext.setInstanceManager(instanceManager); @@ -1547,8 +1547,9 @@ public class TomcatWebAppBuilder implements WebAppBuilder, ContextListener, Pare return (LazyStopWebappClassLoader) old; } - private JndiEncBuilder getJndiBuilder(final ClassLoader classLoader, final WebAppInfo webAppInfo, final Set<Injection> injections) throws OpenEJBException { - return new JndiEncBuilder(webAppInfo.jndiEnc, injections, webAppInfo.moduleId, "Bean", null, webAppInfo.uniqueId, classLoader); + private JndiEncBuilder getJndiBuilder(final ClassLoader classLoader, final WebAppInfo webAppInfo, final Set<Injection> injections, + final Properties props) throws OpenEJBException { + return new JndiEncBuilder(webAppInfo.jndiEnc, injections, webAppInfo.moduleId, "Bean", null, webAppInfo.uniqueId, classLoader, props); } /** http://git-wip-us.apache.org/repos/asf/tomee/blob/fc6160f1/tomee/tomee-common/src/main/java/org/apache/tomee/common/WsFactory.java ---------------------------------------------------------------------- diff --git a/tomee/tomee-common/src/main/java/org/apache/tomee/common/WsFactory.java b/tomee/tomee-common/src/main/java/org/apache/tomee/common/WsFactory.java index 84f2d82..5e657cb 100644 --- a/tomee/tomee-common/src/main/java/org/apache/tomee/common/WsFactory.java +++ b/tomee/tomee-common/src/main/java/org/apache/tomee/common/WsFactory.java @@ -33,6 +33,7 @@ import java.net.URL; import java.util.Collections; import java.util.Hashtable; import java.util.List; +import java.util.Properties; public class WsFactory extends AbstractObjectFactory { public Object getObjectInstance(final Object object, final Name name, final Context context, final Hashtable environment) throws Exception { @@ -103,6 +104,8 @@ public class WsFactory extends AbstractObjectFactory { injections = Collections.emptyList(); } + final Properties properties = new Properties(); + properties.putAll(environment); final JaxWsServiceReference serviceReference = new JaxWsServiceReference(serviceId, serviceQName, serviceClass, portQName, @@ -110,7 +113,8 @@ public class WsFactory extends AbstractObjectFactory { wsdlUrl, portRefs, handlerChains, - injections); + injections, + properties); value = serviceReference.getObject(); }
