Repository: tomee Updated Branches: refs/heads/develop 13f9589b5 -> 867cf58a8
making new configuration of cxf @WebServiceRef more consistent Project: http://git-wip-us.apache.org/repos/asf/tomee/repo Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/d5cdca83 Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/d5cdca83 Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/d5cdca83 Branch: refs/heads/develop Commit: d5cdca83ffdbda8669710cf37dcd2d55a1f57af3 Parents: 13f9589 Author: Romain Manni-Bucau <[email protected]> Authored: Fri Nov 28 12:04:03 2014 +0100 Committer: Romain Manni-Bucau <[email protected]> Committed: Fri Nov 28 12:04:03 2014 +0100 ---------------------------------------------------------------------- .../assembler/classic/util/ServiceInfos.java | 50 ++++++++--------- .../apache/openejb/config/sys/MapFactory.java | 8 +-- .../openejb/observer/ObserverManager.java | 3 +- .../client/WebServiceInjectionConfigurator.java | 18 ++++--- .../cxf/config/WSS4JInInterceptorFactory.java | 24 +-------- .../cxf/config/WSS4JInterceptorFactoryBase.java | 56 ++++++++++++++++++++ .../cxf/config/WSS4JOutInterceptorFactory.java | 28 ++++++++++ .../server/cxf/WebServiceInjectionTest.java | 33 ++++++++++-- 8 files changed, 158 insertions(+), 62 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tomee/blob/d5cdca83/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/util/ServiceInfos.java ---------------------------------------------------------------------- diff --git a/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/util/ServiceInfos.java b/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/util/ServiceInfos.java index 95eea6f..b0b2fbb 100644 --- a/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/util/ServiceInfos.java +++ b/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/util/ServiceInfos.java @@ -134,48 +134,48 @@ public final class ServiceInfos { } public static Object build(final Collection<ServiceInfo> services, final ServiceInfo info, final ObjectRecipe serviceRecipe) { + if ("org.apache.openejb.config.sys.MapFactory".equals(info.className)) { + return info.properties; + } + if (!info.properties.containsKey("properties")) { info.properties.put("properties", new UnsetPropertiesRecipe()); } - // we can't ask to have a setter for existing code + // we can't ask for having a setter for existing code serviceRecipe.allow(Option.FIELD_INJECTION); serviceRecipe.allow(Option.PRIVATE_PROPERTIES); - if ("org.apache.openejb.config.sys.MapFactory".equals(info.className)) { - serviceRecipe.setProperty("prop", info.properties); - } else { - for (final Map.Entry<Object, Object> entry : info.properties.entrySet()) { // manage links - final String key = entry.getKey().toString(); - final Object value = entry.getValue(); - if (value instanceof String) { - final String valueStr = value.toString(); - if (valueStr.startsWith("$")) { - serviceRecipe.setProperty(key, resolve(services, valueStr.substring(1))); - } else if (valueStr.startsWith("@")) { - final Context jndiContext = SystemInstance.get().getComponent(ContainerSystem.class).getJNDIContext(); + for (final Map.Entry<Object, Object> entry : info.properties.entrySet()) { // manage links + final String key = entry.getKey().toString(); + final Object value = entry.getValue(); + if (value instanceof String) { + final String valueStr = value.toString(); + if (valueStr.startsWith("$")) { + serviceRecipe.setProperty(key, resolve(services, valueStr.substring(1))); + } else if (valueStr.startsWith("@")) { + final Context jndiContext = SystemInstance.get().getComponent(ContainerSystem.class).getJNDIContext(); + try { + serviceRecipe.setProperty(key, jndiContext.lookup(JndiConstants.OPENEJB_RESOURCE_JNDI_PREFIX + valueStr.substring(1))); + } catch (final NamingException e) { try { - serviceRecipe.setProperty(key, jndiContext.lookup(JndiConstants.OPENEJB_RESOURCE_JNDI_PREFIX + valueStr.substring(1))); - } catch (final NamingException e) { - try { - serviceRecipe.setProperty(key, jndiContext.lookup(valueStr.substring(1))); - } catch (final NamingException e1) { - Logger.getInstance(LogCategory.OPENEJB, ServiceInfos.class).warning("Value " + valueStr + " starting with @ but doesn't point to an existing resource, using raw value"); - serviceRecipe.setProperty(key, value); - } + serviceRecipe.setProperty(key, jndiContext.lookup(valueStr.substring(1))); + } catch (final NamingException e1) { + Logger.getInstance(LogCategory.OPENEJB, ServiceInfos.class).warning("Value " + valueStr + " starting with @ but doesn't point to an existing resource, using raw value"); + serviceRecipe.setProperty(key, value); } - } else { - serviceRecipe.setProperty(key, value); } } else { - serviceRecipe.setProperty(key, entry.getValue()); + serviceRecipe.setProperty(key, value); } + } else { + serviceRecipe.setProperty(key, entry.getValue()); } } final Object service = serviceRecipe.create(); - SystemInstance.get().addObserver(service); + SystemInstance.get().addObserver(service); // TODO: remove it? in all case the observer should remove itself when done Assembler.logUnusedProperties(serviceRecipe, info); return service; http://git-wip-us.apache.org/repos/asf/tomee/blob/d5cdca83/container/openejb-core/src/main/java/org/apache/openejb/config/sys/MapFactory.java ---------------------------------------------------------------------- diff --git a/container/openejb-core/src/main/java/org/apache/openejb/config/sys/MapFactory.java b/container/openejb-core/src/main/java/org/apache/openejb/config/sys/MapFactory.java index 8327100..0f58b2d 100644 --- a/container/openejb-core/src/main/java/org/apache/openejb/config/sys/MapFactory.java +++ b/container/openejb-core/src/main/java/org/apache/openejb/config/sys/MapFactory.java @@ -21,11 +21,13 @@ import java.util.Map; import java.util.Properties; public final class MapFactory { - private MapFactory() { - // no-op + private Properties props = new Properties(); + + public Map<?, ?> create() { + return props; } - public static Map<?, ?> create(final Properties props) { + public Properties getProps() { return props; } } http://git-wip-us.apache.org/repos/asf/tomee/blob/d5cdca83/container/openejb-loader/src/main/java/org/apache/openejb/observer/ObserverManager.java ---------------------------------------------------------------------- diff --git a/container/openejb-loader/src/main/java/org/apache/openejb/observer/ObserverManager.java b/container/openejb-loader/src/main/java/org/apache/openejb/observer/ObserverManager.java index fb53deb..37becbe 100644 --- a/container/openejb-loader/src/main/java/org/apache/openejb/observer/ObserverManager.java +++ b/container/openejb-loader/src/main/java/org/apache/openejb/observer/ObserverManager.java @@ -61,7 +61,8 @@ public class ObserverManager { } try { - if (observers.add(new Observer(observer))) { + final Observer wrapper = new Observer(observer); + if (wrapper.after.size() + wrapper.before.size() + wrapper.methods.size() > 0 && observers.add(wrapper)) { methods.clear(); fireEvent(new ObserverAdded(observer)); return true; http://git-wip-us.apache.org/repos/asf/tomee/blob/d5cdca83/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 78565a1..609b7c1 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 @@ -37,8 +37,6 @@ 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; /** @@ -59,7 +57,9 @@ public class WebServiceInjectionConfigurator implements JaxWsServiceReference.We @Override public void customize(final Object o, final Properties properties) { try { - configure(ClientProxy.getClient(o), properties); + if (!javax.xml.ws.Service.class.isInstance(o)) { + configure(ClientProxy.getClient(o), properties); + } } catch (final Exception e) { Logger.getInstance(LogCategory.CXF, WebServiceInjectionConfigurator.class.getName()) .error(e.getMessage(), e); @@ -72,11 +72,6 @@ public class WebServiceInjectionConfigurator implements JaxWsServiceReference.We } 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); @@ -102,6 +97,13 @@ public class WebServiceInjectionConfigurator implements JaxWsServiceReference.We final Collection<ServiceInfo> info = new ArrayList<ServiceInfo>(services.size()); for (final Service s : services) { + final String prefix = s.getId() + "."; + for (final String key : properties.stringPropertyNames()) { + if (key.startsWith(prefix)) { + s.getProperties().put(key.substring(prefix.length()), properties.getProperty(key)); + } + } + try { info.add(cf.configureService(s, ServiceInfo.class)); } catch (final OpenEJBException e) { http://git-wip-us.apache.org/repos/asf/tomee/blob/d5cdca83/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/config/WSS4JInInterceptorFactory.java ---------------------------------------------------------------------- diff --git a/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/config/WSS4JInInterceptorFactory.java b/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/config/WSS4JInInterceptorFactory.java index 518b510..b78bdd4 100644 --- a/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/config/WSS4JInInterceptorFactory.java +++ b/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/config/WSS4JInInterceptorFactory.java @@ -18,31 +18,11 @@ package org.apache.openejb.server.cxf.config; import org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor; -import java.util.HashMap; -import java.util.Map; -import java.util.Properties; - /** * @version $Rev$ $Date$ */ -public class WSS4JInInterceptorFactory { - - private Properties properties; - - public Properties getProperties() { - return properties; - } - - public void setProperties(Properties properties) { - this.properties = properties; - } - +public class WSS4JInInterceptorFactory extends WSS4JInterceptorFactoryBase { public WSS4JInInterceptor create() { - final Map<String, Object> map = new HashMap<String, Object>(); - for (Map.Entry<Object, Object> entry : properties.entrySet()) { - map.put(entry.getKey().toString(), entry.getValue()); - } - properties.clear(); - return new WSS4JInInterceptor(map); + return new WSS4JInInterceptor(getAndDestroyMap()); } } http://git-wip-us.apache.org/repos/asf/tomee/blob/d5cdca83/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/config/WSS4JInterceptorFactoryBase.java ---------------------------------------------------------------------- diff --git a/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/config/WSS4JInterceptorFactoryBase.java b/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/config/WSS4JInterceptorFactoryBase.java new file mode 100644 index 0000000..4b7be87 --- /dev/null +++ b/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/config/WSS4JInterceptorFactoryBase.java @@ -0,0 +1,56 @@ +/* + * 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.config; + +import org.apache.xbean.recipe.ExecutionContext; +import org.apache.xbean.recipe.ObjectRecipe; +import org.apache.xbean.recipe.Recipe; +import org.apache.xbean.recipe.RecipeHelper; + +import java.util.HashMap; +import java.util.Map; +import java.util.Properties; + +/** + * @version $Rev$ $Date$ + */ +public class WSS4JInterceptorFactoryBase { + + private Properties properties; + + public void setProperties(Properties properties) { + this.properties = properties; + } + + protected Map<String, Object> getAndDestroyMap() { + final Map<String, Object> map = new HashMap<String, Object>(); + for (Map.Entry<Object, Object> entry : properties.entrySet()) { + map.put(entry.getKey().toString(), entry.getValue()); + } + + // avoid warnings + final Recipe recipe = ExecutionContext.getContext().getStack().getLast(); + if (ObjectRecipe.class.isInstance(recipe)) { + final ObjectRecipe or = ObjectRecipe.class.cast(recipe); + if (or.getUnsetProperties() != null) { + or.getUnsetProperties().clear(); + } + } + + return map; + } +} http://git-wip-us.apache.org/repos/asf/tomee/blob/d5cdca83/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/config/WSS4JOutInterceptorFactory.java ---------------------------------------------------------------------- diff --git a/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/config/WSS4JOutInterceptorFactory.java b/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/config/WSS4JOutInterceptorFactory.java new file mode 100644 index 0000000..6728ab6 --- /dev/null +++ b/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/config/WSS4JOutInterceptorFactory.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.server.cxf.config; + +import org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor; + +/** + * @version $Rev$ $Date$ + */ +public class WSS4JOutInterceptorFactory extends WSS4JInterceptorFactoryBase { + public WSS4JOutInterceptor create() { + return new WSS4JOutInterceptor(getAndDestroyMap()); + } +} http://git-wip-us.apache.org/repos/asf/tomee/blob/d5cdca83/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 index 159e40c..c4f1606 100644 --- 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 @@ -18,9 +18,15 @@ package org.apache.openejb.server.cxf; import org.apache.cxf.endpoint.Client; import org.apache.cxf.frontend.ClientProxy; +import org.apache.cxf.interceptor.Interceptor; import org.apache.cxf.interceptor.LoggingOutInterceptor; +import org.apache.cxf.message.Message; +import org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor; +import org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor; +import org.apache.openejb.config.sys.MapFactory; import org.apache.openejb.jee.WebApp; import org.apache.openejb.junit.ApplicationComposer; +import org.apache.openejb.server.cxf.config.WSS4JInInterceptorFactory; import org.apache.openejb.testing.ApplicationConfiguration; import org.apache.openejb.testing.Classes; import org.apache.openejb.testing.EnableServices; @@ -32,6 +38,7 @@ import org.junit.runner.RunWith; import javax.ejb.Singleton; import javax.jws.WebService; import javax.xml.ws.WebServiceRef; +import java.util.Iterator; import java.util.Properties; import static org.junit.Assert.assertEquals; @@ -55,8 +62,16 @@ public class WebServiceInjectionTest { // 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())); + assertEquals(2, client.getOutInterceptors().size()); + assertEquals(1, client.getInInterceptors().size()); + final Iterator<Interceptor<? extends Message>> iterator = client.getOutInterceptors().iterator(); + assertTrue(LoggingOutInterceptor.class.isInstance(iterator.next())); + final Interceptor<? extends Message> wss4jout = iterator.next(); + assertTrue(WSS4JOutInterceptor.class.isInstance(wss4jout)); + assertEquals("d", WSS4JOutInterceptor.class.cast(wss4jout).getProperties().get("c")); + final Interceptor<? extends Message> wss4jin = client.getInInterceptors().iterator().next(); + assertTrue(WSS4JInInterceptor.class.isInstance(wss4jin)); + assertEquals("b", WSS4JInInterceptor.class.cast(wss4jin).getProperties().get("a")); } @ApplicationConfiguration @@ -64,8 +79,20 @@ public class WebServiceInjectionTest { // 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("cxf.jaxws.client.{http://cxf.server.openejb.apache.org/}MyWebservicePort.in-interceptors", "wss4jin") + .p("cxf.jaxws.client.{http://cxf.server.openejb.apache.org/}MyWebservicePort.out-interceptors", "loo,wss4jout") + .p("loo", "new://Service?class-name=" + LoggingOutInterceptor.class.getName()) + + .p("wss4jin", "new://Service?class-name=" + WSS4JInInterceptorFactory.class.getName() + "&factory-name=create") + .p("wss4jin.a", "b") + + .p("wss4jout", "new://Service?class-name=" + WSS4JOutInterceptor.class.getName() + "&constructor=properties") + .p("wss4jout.properties", "$properties") + + .p("properties", "new://Service?class-name=" + MapFactory.class.getName()) + .p("properties.c", "d") + .build(); }
