Author: alessio.soldano(a)jboss.com
Date: 2010-05-07 13:19:51 -0400 (Fri, 07 May 2010)
New Revision: 12197
Added:
stack/cxf/branches/jbossws-cxf-3.1.2/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/ServiceRefStubPropertyConfigurer.java
Removed:
stack/cxf/branches/jbossws-cxf-3.1.2/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/ServiceRefStubPropertyServiceDelegate.java
Modified:
stack/cxf/branches/jbossws-cxf-3.1.2/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/ServiceObjectFactory.java
Log:
[JBPAPP-4248] Refactor ServiceObjectFactory (merge 10370 from trunk)
Modified:
stack/cxf/branches/jbossws-cxf-3.1.2/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/ServiceObjectFactory.java
===================================================================
---
stack/cxf/branches/jbossws-cxf-3.1.2/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/ServiceObjectFactory.java 2010-05-07
15:42:12 UTC (rev 12196)
+++
stack/cxf/branches/jbossws-cxf-3.1.2/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/ServiceObjectFactory.java 2010-05-07
17:19:51 UTC (rev 12197)
@@ -23,6 +23,7 @@
import org.apache.cxf.Bus;
import org.apache.cxf.BusFactory;
+import org.apache.cxf.configuration.Configurer;
import org.jboss.wsf.spi.WSFException;
import org.jboss.wsf.spi.metadata.j2ee.serviceref.UnifiedServiceRefMetaData;
@@ -59,6 +60,7 @@
*
* @author Thomas.Diesler(a)jboss.com
* @author Richard.Opalka(a)jboss.com
+ * @author alessio.soldano(a)jboss.com
*/
public class ServiceObjectFactory implements ObjectFactory
{
@@ -89,8 +91,6 @@
{
try
{
- BusFactory.setThreadDefaultBus(null); // cleanup thread locals before
constructing Service
-
Reference ref = (Reference)obj;
// Get the target class name
@@ -98,6 +98,14 @@
// Unmarshall the UnifiedServiceRef
UnifiedServiceRefMetaData serviceRef = unmarshallServiceRef(ref);
+
+ //Reset bus before constructing Service
+ BusFactory.setThreadDefaultBus(null);
+ Bus bus = BusFactory.getThreadDefaultBus();
+ //Add extension to configure stub properties using the UnifiedServiceRefMetaData
+ Configurer configurer = bus.getExtension(Configurer.class);
+ bus.setExtension(new ServiceRefStubPropertyConfigurer(serviceRef, configurer),
Configurer.class);
+
String serviceRefName = serviceRef.getServiceRefName();
QName serviceQName = serviceRef.getServiceQName();
@@ -151,9 +159,6 @@
}
}
- // Configure the service
- configureService((Service)target, serviceRef);
-
if (targetClassName != null && targetClassName.equals(serviceImplClass)
== false)
{
try
@@ -189,11 +194,9 @@
if ((serviceRef.getHandlerChain() != null) && (target instanceof
Service))
{
- Bus bus = BusFactory.getThreadDefaultBus();
((Service)target).setHandlerResolver(new HandlerResolverImpl(bus,
serviceRef.getHandlerChain(), target.getClass()));
}
- hackServiceDelegate(target, serviceRef);
return target;
}
@@ -204,68 +207,6 @@
}
}
- // TODO: ugly hack that should be removed in the future
- private Object hackServiceDelegate(final Object service, final
UnifiedServiceRefMetaData serviceRef) throws Throwable
- {
- SecurityManager sm = System.getSecurityManager();
- if (sm != null)
- {
- try
- {
- return AccessController.doPrivileged(new
PrivilegedExceptionAction<Object>()
- {
- public Object run() throws Exception
- {
- Field delegateField = findServiceDelegateField(service.getClass());
- if (delegateField != null)
- {
- delegateField.setAccessible(true);
- ServiceDelegate delegate =
(ServiceDelegate)delegateField.get(service);
- delegateField.set(service, new
ServiceRefStubPropertyServiceDelegate(delegate, serviceRef));
- return delegate;
- } else {
- return null;
- }
- }
- });
- }
- catch (PrivilegedActionException e)
- {
- throw e.getCause();
- }
- }
- Field delegateField = findServiceDelegateField(service.getClass());
- if (delegateField != null)
- {
- delegateField.setAccessible(true);
- ServiceDelegate delegate = (ServiceDelegate)delegateField.get(service);
- delegateField.set(service, new ServiceRefStubPropertyServiceDelegate(delegate,
serviceRef));
- return delegate;
- } else {
- return null;
- }
- }
-
- private static Field findServiceDelegateField(Class<?> clazz)
- {
- while (clazz != null)
- {
- for (Field f : clazz.getDeclaredFields())
- {
- if (f.getType().equals(ServiceDelegate.class))
- return f;
- }
- clazz = clazz.getSuperclass();
- }
- return null;
- }
-
-
- private void configureService(Service service, UnifiedServiceRefMetaData serviceRef)
- {
- log.warn("Service configuration not available in Apache-CXF");
- }
-
private UnifiedServiceRefMetaData unmarshallServiceRef(Reference ref) throws
ClassNotFoundException, NamingException
{
UnifiedServiceRefMetaData sref;
Copied:
stack/cxf/branches/jbossws-cxf-3.1.2/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/ServiceRefStubPropertyConfigurer.java
(from rev 10370,
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/ServiceRefStubPropertyConfigurer.java)
===================================================================
---
stack/cxf/branches/jbossws-cxf-3.1.2/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/ServiceRefStubPropertyConfigurer.java
(rev 0)
+++
stack/cxf/branches/jbossws-cxf-3.1.2/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/ServiceRefStubPropertyConfigurer.java 2010-05-07
17:19:51 UTC (rev 12197)
@@ -0,0 +1,91 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.wsf.stack.cxf.client;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.cxf.configuration.Configurer;
+import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
+import org.jboss.wsf.spi.metadata.j2ee.serviceref.UnifiedPortComponentRefMetaData;
+import org.jboss.wsf.spi.metadata.j2ee.serviceref.UnifiedServiceRefMetaData;
+import org.jboss.wsf.spi.metadata.j2ee.serviceref.UnifiedStubPropertyMetaData;
+
+/**
+ * A CXF configurer that sets the serviceref stub properties in the
JaxWsProxyFactoryBean
+ *
+ * @author alessio.soldano(a)jboss.com
+ * @since 21-Jul-2009
+ */
+public class ServiceRefStubPropertyConfigurer implements Configurer
+{
+ private UnifiedServiceRefMetaData serviceRefMD;
+ private Configurer delegate;
+
+ public ServiceRefStubPropertyConfigurer(UnifiedServiceRefMetaData serviceRefMD,
Configurer delegate)
+ {
+ this.serviceRefMD = serviceRefMD;
+ this.delegate = delegate;
+ }
+
+ public void configureBean(Object beanInstance)
+ {
+ if (beanInstance instanceof JaxWsProxyFactoryBean)
+ {
+ configureJaxWsProxyFactoryBean((JaxWsProxyFactoryBean)beanInstance);
+ }
+ if (delegate != null)
+ {
+ delegate.configureBean(beanInstance);
+ }
+ }
+
+ public void configureBean(String name, Object beanInstance)
+ {
+ if (beanInstance instanceof JaxWsProxyFactoryBean)
+ {
+ configureJaxWsProxyFactoryBean((JaxWsProxyFactoryBean)beanInstance);
+ }
+ if (delegate != null)
+ {
+ delegate.configureBean(name, beanInstance);
+ }
+ }
+
+ private synchronized void configureJaxWsProxyFactoryBean(JaxWsProxyFactoryBean
proxyFactory)
+ {
+ Map<String, Object> properties = new HashMap<String, Object>();
+ for (UnifiedPortComponentRefMetaData pcRef : serviceRefMD.getPortComponentRefs())
+ {
+ String sei = pcRef.getServiceEndpointInterface();
+ if (sei != null &&
sei.equals(proxyFactory.getServiceClass().getName()))
+ {
+ for (UnifiedStubPropertyMetaData prop : pcRef.getStubProperties())
+ {
+ properties.put(prop.getPropName(), prop.getPropValue());
+ }
+ }
+ }
+ proxyFactory.setProperties(properties);
+ }
+
+}
Deleted:
stack/cxf/branches/jbossws-cxf-3.1.2/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/ServiceRefStubPropertyServiceDelegate.java
===================================================================
---
stack/cxf/branches/jbossws-cxf-3.1.2/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/ServiceRefStubPropertyServiceDelegate.java 2010-05-07
15:42:12 UTC (rev 12196)
+++
stack/cxf/branches/jbossws-cxf-3.1.2/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/ServiceRefStubPropertyServiceDelegate.java 2010-05-07
17:19:51 UTC (rev 12197)
@@ -1,247 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2009, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.jboss.wsf.stack.cxf.client;
-
-import java.net.URL;
-import java.util.Iterator;
-import java.util.concurrent.Executor;
-
-import javax.xml.bind.JAXBContext;
-import javax.xml.namespace.QName;
-import javax.xml.ws.BindingProvider;
-import javax.xml.ws.Dispatch;
-import javax.xml.ws.EndpointReference;
-import javax.xml.ws.WebServiceFeature;
-import javax.xml.ws.Service.Mode;
-import javax.xml.ws.handler.HandlerResolver;
-import javax.xml.ws.spi.ServiceDelegate;
-
-import org.jboss.wsf.spi.metadata.j2ee.serviceref.UnifiedPortComponentRefMetaData;
-import org.jboss.wsf.spi.metadata.j2ee.serviceref.UnifiedServiceRefMetaData;
-import org.jboss.wsf.spi.metadata.j2ee.serviceref.UnifiedStubPropertyMetaData;
-
-/**
- * ServiceDelegate that propagates service ref stub properties
- *
- * @author richard.opalka(a)jboss.com
- */
-public final class ServiceRefStubPropertyServiceDelegate extends ServiceDelegate
-{
-
- private ServiceDelegate delegate;
- private UnifiedServiceRefMetaData serviceRefMD;
-
- ServiceRefStubPropertyServiceDelegate(ServiceDelegate delegate,
UnifiedServiceRefMetaData serviceRefMD)
- {
- this.delegate = delegate;
- this.serviceRefMD = serviceRefMD;
- }
-
- private <T> T propagateProps(T proxy, Class<T> serviceEndpointInterface)
- {
- for (UnifiedPortComponentRefMetaData pcRef : serviceRefMD.getPortComponentRefs())
- {
- String sei = pcRef.getServiceEndpointInterface();
- if (sei != null && sei.equals(serviceEndpointInterface.getName())
&& proxy instanceof BindingProvider)
- {
- BindingProvider bp = (BindingProvider)proxy;
- for (UnifiedStubPropertyMetaData prop : pcRef.getStubProperties())
- {
- bp.getRequestContext().put(prop.getPropName(), prop.getPropValue());
- }
- }
- }
- return proxy;
- }
-
- /* (non-Javadoc)
- * @see javax.xml.ws.spi.ServiceDelegate#addPort(javax.xml.namespace.QName,
java.lang.String, java.lang.String)
- */
- @Override
- public void addPort(QName portName, String bindingId, String endpointAddress)
- {
- this.delegate.addPort(portName, bindingId, endpointAddress);
- }
-
- /* (non-Javadoc)
- * @see
javax.xml.ws.spi.ServiceDelegate#createDispatch(javax.xml.ws.EndpointReference,
java.lang.Class, javax.xml.ws.Service.Mode, javax.xml.ws.WebServiceFeature[])
- */
- @Override
- public <T> Dispatch<T> createDispatch(EndpointReference endpointReference,
Class<T> type, Mode mode, WebServiceFeature... features)
- {
- return this.delegate.createDispatch(endpointReference, type, mode, features);
- }
-
- /* (non-Javadoc)
- * @see
javax.xml.ws.spi.ServiceDelegate#createDispatch(javax.xml.ws.EndpointReference,
javax.xml.bind.JAXBContext, javax.xml.ws.Service.Mode, javax.xml.ws.WebServiceFeature[])
- */
- @Override
- public Dispatch<Object> createDispatch(EndpointReference endpointReference,
JAXBContext context, Mode mode, WebServiceFeature... features)
- {
- return this.delegate.createDispatch(endpointReference, context, mode, features);
- }
-
- /* (non-Javadoc)
- * @see javax.xml.ws.spi.ServiceDelegate#createDispatch(javax.xml.namespace.QName,
java.lang.Class, javax.xml.ws.Service.Mode, javax.xml.ws.WebServiceFeature[])
- */
- @Override
- public <T> Dispatch<T> createDispatch(QName portName, Class<T> type,
Mode mode, WebServiceFeature... features)
- {
- return this.delegate.createDispatch(portName, type, mode, features);
- }
-
- /* (non-Javadoc)
- * @see javax.xml.ws.spi.ServiceDelegate#createDispatch(javax.xml.namespace.QName,
java.lang.Class, javax.xml.ws.Service.Mode)
- */
- @Override
- public <T> Dispatch<T> createDispatch(QName portName, Class<T> type,
Mode mode)
- {
- return this.delegate.createDispatch(portName, type, mode);
- }
-
- /* (non-Javadoc)
- * @see javax.xml.ws.spi.ServiceDelegate#createDispatch(javax.xml.namespace.QName,
javax.xml.bind.JAXBContext, javax.xml.ws.Service.Mode, javax.xml.ws.WebServiceFeature[])
- */
- @Override
- public Dispatch<Object> createDispatch(QName portName, JAXBContext context, Mode
mode, WebServiceFeature... features)
- {
- return this.delegate.createDispatch(portName, context, mode, features);
- }
-
- /* (non-Javadoc)
- * @see javax.xml.ws.spi.ServiceDelegate#createDispatch(javax.xml.namespace.QName,
javax.xml.bind.JAXBContext, javax.xml.ws.Service.Mode)
- */
- @Override
- public Dispatch<Object> createDispatch(QName portName, JAXBContext context, Mode
mode)
- {
- return this.delegate.createDispatch(portName, context, mode);
- }
-
- /* (non-Javadoc)
- * @see javax.xml.ws.spi.ServiceDelegate#getExecutor()
- */
- @Override
- public Executor getExecutor()
- {
- return this.delegate.getExecutor();
- }
-
- /* (non-Javadoc)
- * @see javax.xml.ws.spi.ServiceDelegate#getHandlerResolver()
- */
- @Override
- public HandlerResolver getHandlerResolver()
- {
- return this.delegate.getHandlerResolver();
- }
-
- /* (non-Javadoc)
- * @see javax.xml.ws.spi.ServiceDelegate#getPort(java.lang.Class,
javax.xml.ws.WebServiceFeature[])
- */
- @Override
- public <T> T getPort(Class<T> serviceEndpointInterface,
WebServiceFeature... features)
- {
- return this.propagateProps(this.delegate.getPort(serviceEndpointInterface,
features), serviceEndpointInterface);
- }
-
- /* (non-Javadoc)
- * @see javax.xml.ws.spi.ServiceDelegate#getPort(java.lang.Class)
- */
- @Override
- public <T> T getPort(Class<T> serviceEndpointInterface)
- {
- return this.propagateProps(this.delegate.getPort(serviceEndpointInterface),
serviceEndpointInterface);
- }
-
- /* (non-Javadoc)
- * @see javax.xml.ws.spi.ServiceDelegate#getPort(javax.xml.ws.EndpointReference,
java.lang.Class, javax.xml.ws.WebServiceFeature[])
- */
- @Override
- public <T> T getPort(EndpointReference endpointReference, Class<T>
serviceEndpointInterface, WebServiceFeature... features)
- {
- return this.propagateProps(this.delegate.getPort(endpointReference,
serviceEndpointInterface, features), serviceEndpointInterface);
- }
-
- /* (non-Javadoc)
- * @see javax.xml.ws.spi.ServiceDelegate#getPort(javax.xml.namespace.QName,
java.lang.Class, javax.xml.ws.WebServiceFeature[])
- */
- @Override
- public <T> T getPort(QName portName, Class<T> serviceEndpointInterface,
WebServiceFeature... features)
- {
- return this.propagateProps(this.delegate.getPort(portName,
serviceEndpointInterface, features), serviceEndpointInterface);
- }
-
- /* (non-Javadoc)
- * @see javax.xml.ws.spi.ServiceDelegate#getPort(javax.xml.namespace.QName,
java.lang.Class)
- */
- @Override
- public <T> T getPort(QName portName, Class<T> serviceEndpointInterface)
- {
- return this.propagateProps(this.delegate.getPort(portName,
serviceEndpointInterface), serviceEndpointInterface);
- }
-
- /* (non-Javadoc)
- * @see javax.xml.ws.spi.ServiceDelegate#getPorts()
- */
- @Override
- public Iterator<QName> getPorts()
- {
- return this.delegate.getPorts();
- }
-
- /* (non-Javadoc)
- * @see javax.xml.ws.spi.ServiceDelegate#getServiceName()
- */
- @Override
- public QName getServiceName()
- {
- return this.delegate.getServiceName();
- }
-
- /* (non-Javadoc)
- * @see javax.xml.ws.spi.ServiceDelegate#getWSDLDocumentLocation()
- */
- @Override
- public URL getWSDLDocumentLocation()
- {
- return this.delegate.getWSDLDocumentLocation();
- }
-
- /* (non-Javadoc)
- * @see javax.xml.ws.spi.ServiceDelegate#setExecutor(java.util.concurrent.Executor)
- */
- @Override
- public void setExecutor(Executor executor)
- {
- this.delegate.setExecutor(executor);
- }
-
- /* (non-Javadoc)
- * @see
javax.xml.ws.spi.ServiceDelegate#setHandlerResolver(javax.xml.ws.handler.HandlerResolver)
- */
- @Override
- public void setHandlerResolver(HandlerResolver handlerResolver)
- {
- this.delegate.setHandlerResolver(handlerResolver);
- }
-
-}