Author: thomas.diesler(a)jboss.com
Date: 2007-04-16 06:31:31 -0400 (Mon, 16 Apr 2007)
New Revision: 2877
Added:
trunk/jbossws-core/src/java/org/jboss/ws/core/client/ServiceObjectFactory.java
trunk/jbossws-core/src/java/org/jboss/ws/core/jaxrpc/client/ServiceObjectFactoryJAXRPC.java
trunk/jbossws-core/src/java/org/jboss/ws/core/jaxws/client/ServiceObjectFactoryJAXWS.java
Removed:
trunk/jbossws-core/src/java/org/jboss/ws/core/jaxrpc/client/ServiceObjectFactory.java
trunk/jbossws-core/src/java/org/jboss/ws/core/jaxws/client/ServiceObjectFactory.java
Modified:
trunk/jbossws-core/src/java/org/jboss/ws/core/jaxrpc/client/ServiceReferenceable.java
trunk/jbossws-core/src/java/org/jboss/ws/core/jaxws/client/ServiceReferenceable.java
trunk/jbossws-core/src/java/org/jboss/ws/core/jaxws/spi/ServiceDelegateImpl.java
trunk/jbossws-core/src/java/org/jboss/ws/metadata/builder/jaxws/JAXWSClientMetaDataBuilder.java
Log:
Fix CTS regression
Added: trunk/jbossws-core/src/java/org/jboss/ws/core/client/ServiceObjectFactory.java
===================================================================
--- trunk/jbossws-core/src/java/org/jboss/ws/core/client/ServiceObjectFactory.java
(rev 0)
+++
trunk/jbossws-core/src/java/org/jboss/ws/core/client/ServiceObjectFactory.java 2007-04-16
10:31:31 UTC (rev 2877)
@@ -0,0 +1,118 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.
+ */
+// $Id$
+package org.jboss.ws.core.client;
+
+// $Id$
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.naming.spi.ObjectFactory;
+import javax.xml.namespace.QName;
+
+import org.jboss.logging.Logger;
+import org.jboss.ws.WSException;
+import org.jboss.ws.metadata.j2ee.serviceref.UnifiedPortComponentRefMetaData;
+import org.jboss.ws.metadata.j2ee.serviceref.UnifiedServiceRefMetaData;
+import org.jboss.ws.metadata.umdm.EndpointMetaData;
+import org.jboss.ws.metadata.umdm.ServiceMetaData;
+
+/**
+ * This ServiceObjectFactory reconstructs a service for a given WSDL when the webservice
client does a JNDI lookup
+ * <p/>
+ * It uses the information provided by the service-ref element in application-client.xml
+ *
+ * @author Thomas.Diesler(a)jboss.org
+ * @since 15-April-2004
+ */
+public abstract class ServiceObjectFactory implements ObjectFactory
+{
+ // provide logging
+ private static final Logger log = Logger.getLogger(ServiceObjectFactory.class);
+
+ /**
+ * Narrow available endpoints by <port-component-ref> declarations.
+ * Service.getPort(SEI) must be able to retrieve a distinct port definition.
+ */
+ protected void narrowPortSelection(UnifiedServiceRefMetaData serviceRef,
ServiceMetaData serviceMetaData)
+ {
+ Map<String, UnifiedPortComponentRefMetaData> pcrefs = new HashMap<String,
UnifiedPortComponentRefMetaData>();
+ for (UnifiedPortComponentRefMetaData pcref : serviceRef.getPortComponentRefs())
+ {
+ String seiName = pcref.getServiceEndpointInterface();
+
+ // Constraint#1: within a service-ref it's not allowed to use a SEI across
different pcref's
+ if (pcrefs.get(seiName) != null)
+ throw new WSException("Within a <service-ref> it's not allowed
to use a SEI across different <port-component-ref>'s: " + seiName);
+
+ pcrefs.put(seiName, pcref);
+ }
+
+ // Constraint#2: A pcref may only match one EndpointMetaData
+ for (String sei : pcrefs.keySet())
+ {
+ // Narrow available endpoints by port-component-ref declaration
+ List<QName> narrowedEndpoints = new ArrayList<QName>();
+
+ UnifiedPortComponentRefMetaData pcref = pcrefs.get(sei);
+
+ // Constraint#3: Port selection only applies when both SEI and QName are given
+ if (pcref.getServiceEndpointInterface() != null && pcref.getPortQName()
!= null)
+ {
+ List<QName> pcRef2EndpointMapping = new ArrayList<QName>();
+ for (EndpointMetaData epMetaData : serviceMetaData.getEndpoints())
+ {
+ if
(pcref.getServiceEndpointInterface().equals(epMetaData.getServiceEndpointInterfaceName()))
+ {
+ pcRef2EndpointMapping.add(epMetaData.getPortName());
+ }
+ }
+
+ for (QName q : pcRef2EndpointMapping)
+ {
+ EndpointMetaData mappedEndpoint = serviceMetaData.getEndpoint(q);
+ if (!pcref.getPortQName().equals(mappedEndpoint.getPortName()))
+ narrowedEndpoints.add(q);
+ }
+
+ // Constraint: Dont exclude all of them ;)
+ if (pcRef2EndpointMapping.size() > 0 &&
(pcRef2EndpointMapping.size() == narrowedEndpoints.size()))
+ throw new WSException("Failed to narrow available endpoints by
<port-component-ref> declaration");
+
+ for (QName q : narrowedEndpoints)
+ {
+ EndpointMetaData removed = serviceMetaData.removeEndpoint(q);
+ log.debug("Narrowed endpoint " + q + "(" + removed +
")");
+ }
+ }
+ else
+ {
+ // TODO: In case there is more then one EMPD this should cause an exception
+ log.warn("Unable to narrow port selection for " + pcref);
+ }
+
+ }
+ }
+}
Property changes on:
trunk/jbossws-core/src/java/org/jboss/ws/core/client/ServiceObjectFactory.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Deleted:
trunk/jbossws-core/src/java/org/jboss/ws/core/jaxrpc/client/ServiceObjectFactory.java
===================================================================
---
trunk/jbossws-core/src/java/org/jboss/ws/core/jaxrpc/client/ServiceObjectFactory.java 2007-04-15
22:38:49 UTC (rev 2876)
+++
trunk/jbossws-core/src/java/org/jboss/ws/core/jaxrpc/client/ServiceObjectFactory.java 2007-04-16
10:31:31 UTC (rev 2877)
@@ -1,366 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt 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.
- */
-// $Id$
-package org.jboss.ws.core.jaxrpc.client;
-
-// $Id$
-
-import org.jboss.logging.Logger;
-import org.jboss.ws.Constants;
-import org.jboss.ws.WSException;
-import org.jboss.ws.core.server.ServiceEndpoint;
-import org.jboss.ws.core.server.ServiceEndpointManager;
-import org.jboss.ws.core.server.ServiceEndpointManagerFactory;
-import org.jboss.ws.metadata.j2ee.serviceref.UnifiedCallPropertyMetaData;
-import org.jboss.ws.metadata.j2ee.serviceref.UnifiedPortComponentRefMetaData;
-import org.jboss.ws.metadata.j2ee.serviceref.UnifiedServiceRefMetaData;
-import org.jboss.ws.metadata.jaxrpcmapping.JavaWsdlMapping;
-import org.jboss.ws.metadata.jaxrpcmapping.JavaWsdlMappingFactory;
-import org.jboss.ws.metadata.umdm.EndpointMetaData;
-import org.jboss.ws.metadata.umdm.ServiceMetaData;
-import org.jboss.ws.metadata.wsse.WSSecurityConfiguration;
-import org.jboss.ws.tools.wsdl.WSDL11DefinitionFactory;
-
-import javax.naming.*;
-import javax.naming.spi.ObjectFactory;
-import javax.wsdl.Definition;
-import javax.xml.namespace.QName;
-import javax.xml.rpc.JAXRPCException;
-import javax.xml.rpc.Service;
-import java.io.*;
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.Proxy;
-import java.net.URL;
-import java.net.URLEncoder;
-import java.rmi.Remote;
-import java.util.*;
-
-/**
- * This ServiceObjectFactory reconstructs a javax.xml.rpc.Service
- * for a given WSDL when the webservice client does a JNDI lookup
- * <p/>
- * It uses the information provided by the service-ref element in application-client.xml
- *
- * @author Thomas.Diesler(a)jboss.org
- * @since 15-April-2004
- */
-public class ServiceObjectFactory implements ObjectFactory
-{
- // provide logging
- private static final Logger log = Logger.getLogger(ServiceObjectFactory.class);
-
- /**
- * Creates an object using the location or reference information specified.
- * <p/>
- *
- * @param obj The possibly null object containing location or reference
- * information that can be used in creating an object.
- * @param name The name of this object relative to
<code>nameCtx</code>,
- * or null if no name is specified.
- * @param nameCtx The context relative to which the <code>name</code>
- * parameter is specified, or null if <code>name</code>
is
- * relative to the default initial context.
- * @param environment The possibly null environment that is used in
- * creating the object.
- * @return The object created; null if an object cannot be created.
- * @throws Exception if this object factory encountered an exception
- * while attempting to create an object, and no other object
factories are
- * to be tried.
- * @see javax.naming.spi.NamingManager#getObjectInstance
- * @see javax.naming.spi.NamingManager#getURLContext
- */
- public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable
environment) throws Exception
- {
- try
- {
- Reference ref = (Reference)obj;
-
- // Unmarshall the ServiceRefMetaData
- UnifiedServiceRefMetaData serviceRef = null;
- RefAddr metaRefAddr = ref.get(ServiceReferenceable.SERVICE_REF_META_DATA);
- ByteArrayInputStream bais = new
ByteArrayInputStream((byte[])metaRefAddr.getContent());
- try
- {
- ObjectInputStream ois = new ObjectInputStream(bais);
- serviceRef = (UnifiedServiceRefMetaData)ois.readObject();
- ois.close();
- }
- catch (IOException ex)
- {
- NamingException ne = new NamingException("Cannot unmarshall service ref
meta data");
- ne.setRootCause(ex);
- throw ne;
- }
-
- // Unmarshall the WSSecurityConfiguration
- WSSecurityConfiguration securityConfig = null;
- RefAddr wsseRefAddr = ref.get(ServiceReferenceable.SECURITY_CONFIG);
- if (wsseRefAddr != null)
- {
- bais = new ByteArrayInputStream((byte[])wsseRefAddr.getContent());
- try
- {
- ObjectInputStream ois = new ObjectInputStream(bais);
- securityConfig = (WSSecurityConfiguration)ois.readObject();
- ois.close();
- }
- catch (IOException e)
- {
- throw new NamingException("Cannot unmarshall security config, cause:
" + e.toString());
- }
- }
-
- ServiceImpl jaxrpcService = null;
- URL wsdlLocation = serviceRef.getWsdlLocation();
- if (wsdlLocation != null)
- {
- if(log.isDebugEnabled()) log.debug("Create jaxrpc service from
wsdl");
-
- // Create the actual service object
- QName serviceName = serviceRef.getServiceQName();
- JavaWsdlMapping javaWsdlMapping = getJavaWsdlMapping(serviceRef);
- jaxrpcService = new ServiceImpl(serviceName, wsdlLocation, javaWsdlMapping,
securityConfig, serviceRef);
- }
- else
- {
- if(log.isDebugEnabled()) log.debug("Create jaxrpc service with no
wsdl");
- jaxrpcService = new ServiceImpl(new QName(Constants.NS_JBOSSWS_URI,
"AnonymousService"));
- }
-
- ServiceMetaData serviceMetaData = jaxrpcService.getServiceMetaData();
-
- // Set any service level properties
- if (serviceRef.getCallProperties().size() > 0)
- {
- Properties callProps = new Properties();
- serviceMetaData.setProperties(callProps);
- for (UnifiedCallPropertyMetaData prop : serviceRef.getCallProperties())
- callProps.setProperty(prop.getPropName(), prop.getPropValue());
- }
-
- // The web service client using a port-component-link, the contet is the URL to
- // the PortComponentLinkServlet that will return the actual endpoint address
- RefAddr pcLinkRef = ref.get(ServiceReferenceable.PORT_COMPONENT_LINK);
- if (pcLinkRef != null)
- {
- String pcLink = (String)pcLinkRef.getContent();
- if(log.isDebugEnabled()) log.debug("Resolving port-component-link:
" + pcLink);
-
- // First try to obtain the endpoint address loacally
- String endpointAddress = null;
- try
- {
- ServiceEndpointManagerFactory factory =
ServiceEndpointManagerFactory.getInstance();
- ServiceEndpointManager epManager = factory.getServiceEndpointManager();
- ServiceEndpoint serviceEndpoint =
epManager.resolvePortComponentLink(pcLink);
- if (serviceEndpoint == null)
- throw new WSException("Cannot resolve port-component-link: "
+ pcLink);
-
- endpointAddress =
serviceEndpoint.getServiceEndpointInfo().getServerEndpointMetaData().getEndpointAddress();
- }
- catch (Throwable ex)
- {
- // ignore, we are probably a remote client
- }
-
- // We may be remote in the esoteric case where an appclient uses the
port-comonent-link feature
- if (endpointAddress == null)
- {
- String servletPath =
(String)ref.get(ServiceReferenceable.PORT_COMPONENT_LINK_SERVLET).getContent();
- servletPath += "?pcLink=" + URLEncoder.encode(pcLink,
"UTF-8");
- InputStream is = new URL(servletPath).openStream();
- BufferedReader br = new BufferedReader(new InputStreamReader(is));
- endpointAddress = br.readLine();
- is.close();
- }
-
- if(log.isDebugEnabled()) log.debug("Resolved to: " +
endpointAddress);
- if (serviceMetaData.getEndpoints().size() == 1)
- {
- EndpointMetaData epMetaData = serviceMetaData.getEndpoints().get(0);
- epMetaData.setEndpointAddress(endpointAddress);
- }
- else
- {
- log.warn("Cannot set endpoint address for port-component-link,
unsuported number of endpoints");
- }
- }
-
- //narrowPortSelection(serviceRef, serviceMetaData);
-
- /********************************************************
- * Setup the Proxy that implements the service-interface
- ********************************************************/
-
- // load the service interface class
- ClassLoader contextCL = Thread.currentThread().getContextClassLoader();
- Class siClass = contextCL.loadClass(serviceRef.getServiceInterface());
- if (Service.class.isAssignableFrom(siClass) == false)
- throw new JAXRPCException("The service interface does not implement
javax.xml.rpc.Service: " + siClass.getName());
-
- // load all service endpoint interface classes
- for (UnifiedPortComponentRefMetaData pcr : serviceRef.getPortComponentRefs())
- {
- Class seiClass = contextCL.loadClass(pcr.getServiceEndpointInterface());
- if (Remote.class.isAssignableFrom(seiClass) == false)
- throw new IllegalArgumentException("The SEI does not implement
java.rmi.Remote: " + seiClass.getName());
- }
-
- // Setup the handler chain
- setupHandlerChain(jaxrpcService);
-
- InvocationHandler handler = new ServiceProxy(jaxrpcService, siClass);
- return Proxy.newProxyInstance(contextCL, new Class[] { siClass, ServiceExt.class
}, handler);
- }
- catch (Exception ex)
- {
- log.error("Cannot create service", ex);
- throw ex;
- }
- }
-
- /**
- * Narrow port selection tries to nail down available endpoints
- * by <port-component-ref> declarations. A selection base upon
- * Service.getPort(SEI) later on needs to be distinct to an endpoint, or in this case
EndpointMetaData.
- *
- * @param serviceRef
- * @param serviceMetaData
- */
- private void narrowPortSelection(UnifiedServiceRefMetaData serviceRef, ServiceMetaData
serviceMetaData)
- {
- Map<String, List<UnifiedPortComponentRefMetaData>> seiGroups = new
HashMap<String, List<UnifiedPortComponentRefMetaData>>();
- for(UnifiedPortComponentRefMetaData pcref : serviceRef.getPortComponentRefs())
- {
- String sei = pcref.getServiceEndpointInterface();
- if(null==seiGroups.get(sei))
- seiGroups.put(sei, new ArrayList<UnifiedPortComponentRefMetaData>());
- List<UnifiedPortComponentRefMetaData> group = seiGroups.get(sei);
- group.add(pcref);
-
- // Constraint#1: within a service-ref it's not allowed to use a SEI across
different pcref's
- if(group.size()>1)
- throw new WSException("Within a <service-ref> it's not allowed
to use a SEI across different <port-component-ref>'s: "+group);
- }
-
- // Constraint#2: A pcref may only match one EndpointMetaData
- for( String sei : seiGroups.keySet())
- {
- // Narrow available endpoints by port-component-ref declaration
- List<QName> narrowedEndpoints = new ArrayList<QName>();
-
- List<UnifiedPortComponentRefMetaData> group = seiGroups.get(sei);
- UnifiedPortComponentRefMetaData pcref = group.get(0); // distinct, see above
Constraint#1
-
- // Constraint#3: Port selection only applies when both SEI and QName are given
- if(pcref.getServiceEndpointInterface()!=null &&
pcref.getPortQName()!=null)
- {
- List<QName> pcRef2EndpointMapping = new ArrayList<QName>();
- for(EndpointMetaData epMeta : serviceMetaData.getEndpoints())
- {
-
if(pcref.getServiceEndpointInterface().equals(epMeta.getServiceEndpointInterfaceName()))
- {
- pcRef2EndpointMapping.add(epMeta.getPortName());
- }
-
- }
-
- for(QName q : pcRef2EndpointMapping)
- {
- EndpointMetaData mappedEndpoint = serviceMetaData.getEndpoint(q);
- if(! pcref.getPortQName().equals( mappedEndpoint.getPortName()) )
- narrowedEndpoints.add(q);
- }
-
- // Constraint: Dont exclude all of them ;)
- if(pcRef2EndpointMapping.size()>0 && (pcRef2EndpointMapping.size()
== narrowedEndpoints.size()))
- throw new WSException("Failed to narrow available endpoints by
<port-component-ref> declaration");
-
- for(QName q : narrowedEndpoints)
- {
- EndpointMetaData removed = serviceMetaData.removeEndpoint(q);
- log.debug("Narrowed endpoint " + q +
"("+removed+")");
- }
- }
- else
- {
- // TODO: In case there is more then one EMPD this should cause an exception
- log.warn("Unable to narrow port selection for "+ pcref);
- }
-
- }
- }
-
- /**
- * Setup the handler chain(s) for this service
- */
- private void setupHandlerChain(ServiceImpl jaxrpcService) throws Exception
- {
- List<EndpointMetaData> endpoints =
jaxrpcService.getServiceMetaData().getEndpoints();
- for (EndpointMetaData epMetaData : endpoints)
- {
- jaxrpcService.setupHandlerChain(epMetaData);
- }
- }
-
- private JavaWsdlMapping getJavaWsdlMapping(UnifiedServiceRefMetaData serviceRef)
- {
- JavaWsdlMapping javaWsdlMapping = null;
- if (serviceRef.getMappingFile() != null)
- {
- String mappingFile = serviceRef.getMappingFile();
- try
- {
- JavaWsdlMappingFactory mappingFactory =
JavaWsdlMappingFactory.newInstance();
- URL mappingURL = serviceRef.getVfsRoot().findChild(mappingFile).toURL();
- javaWsdlMapping = mappingFactory.parse(mappingURL);
- }
- catch (Exception e)
- {
- throw new WSException("Cannot unmarshal jaxrpc-mapping-file: " +
mappingFile, e);
- }
- }
- return javaWsdlMapping;
- }
-
- private Definition getWsdlDefinition(UnifiedServiceRefMetaData serviceRef)
- {
- Definition wsdlDefinition = null;
- {
- URL wsdlLocation = serviceRef.getWsdlLocation();
- if (wsdlLocation != null)
- {
- try
- {
- WSDL11DefinitionFactory factory = WSDL11DefinitionFactory.newInstance();
- wsdlDefinition = factory.parse(wsdlLocation);
- }
- catch (Exception e)
- {
- throw new WSException("Cannot unmarshall wsdl-file: " +
wsdlLocation, e);
- }
- }
- }
- return wsdlDefinition;
- }
-
-}
Copied:
trunk/jbossws-core/src/java/org/jboss/ws/core/jaxrpc/client/ServiceObjectFactoryJAXRPC.java
(from rev 2876,
trunk/jbossws-core/src/java/org/jboss/ws/core/jaxrpc/client/ServiceObjectFactory.java)
===================================================================
---
trunk/jbossws-core/src/java/org/jboss/ws/core/jaxrpc/client/ServiceObjectFactoryJAXRPC.java
(rev 0)
+++
trunk/jbossws-core/src/java/org/jboss/ws/core/jaxrpc/client/ServiceObjectFactoryJAXRPC.java 2007-04-16
10:31:31 UTC (rev 2877)
@@ -0,0 +1,286 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.
+ */
+// $Id$
+package org.jboss.ws.core.jaxrpc.client;
+
+// $Id$
+
+import java.io.BufferedReader;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.ObjectInputStream;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Proxy;
+import java.net.URL;
+import java.net.URLEncoder;
+import java.rmi.Remote;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Properties;
+
+import javax.naming.Context;
+import javax.naming.Name;
+import javax.naming.NamingException;
+import javax.naming.RefAddr;
+import javax.naming.Reference;
+import javax.xml.namespace.QName;
+import javax.xml.rpc.JAXRPCException;
+import javax.xml.rpc.Service;
+
+import org.jboss.logging.Logger;
+import org.jboss.ws.Constants;
+import org.jboss.ws.WSException;
+import org.jboss.ws.core.client.ServiceObjectFactory;
+import org.jboss.ws.core.server.ServiceEndpoint;
+import org.jboss.ws.core.server.ServiceEndpointManager;
+import org.jboss.ws.core.server.ServiceEndpointManagerFactory;
+import org.jboss.ws.metadata.j2ee.serviceref.UnifiedCallPropertyMetaData;
+import org.jboss.ws.metadata.j2ee.serviceref.UnifiedPortComponentRefMetaData;
+import org.jboss.ws.metadata.j2ee.serviceref.UnifiedServiceRefMetaData;
+import org.jboss.ws.metadata.jaxrpcmapping.JavaWsdlMapping;
+import org.jboss.ws.metadata.jaxrpcmapping.JavaWsdlMappingFactory;
+import org.jboss.ws.metadata.umdm.EndpointMetaData;
+import org.jboss.ws.metadata.umdm.ServiceMetaData;
+import org.jboss.ws.metadata.wsse.WSSecurityConfiguration;
+
+/**
+ * This ServiceObjectFactory reconstructs a javax.xml.rpc.Service
+ * for a given WSDL when the webservice client does a JNDI lookup
+ * <p/>
+ * It uses the information provided by the service-ref element in application-client.xml
+ *
+ * @author Thomas.Diesler(a)jboss.org
+ * @since 15-April-2004
+ */
+public class ServiceObjectFactoryJAXRPC extends ServiceObjectFactory
+{
+ // provide logging
+ private static final Logger log = Logger.getLogger(ServiceObjectFactoryJAXRPC.class);
+
+ /**
+ * Creates an object using the location or reference information specified.
+ * <p/>
+ *
+ * @param obj The possibly null object containing location or reference
+ * information that can be used in creating an object.
+ * @param name The name of this object relative to
<code>nameCtx</code>,
+ * or null if no name is specified.
+ * @param nameCtx The context relative to which the <code>name</code>
+ * parameter is specified, or null if <code>name</code>
is
+ * relative to the default initial context.
+ * @param environment The possibly null environment that is used in
+ * creating the object.
+ * @return The object created; null if an object cannot be created.
+ * @throws Exception if this object factory encountered an exception
+ * while attempting to create an object, and no other object
factories are
+ * to be tried.
+ * @see javax.naming.spi.NamingManager#getObjectInstance
+ * @see javax.naming.spi.NamingManager#getURLContext
+ */
+ public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable
environment) throws Exception
+ {
+ try
+ {
+ Reference ref = (Reference)obj;
+
+ // Unmarshall the ServiceRefMetaData
+ UnifiedServiceRefMetaData serviceRef = null;
+ RefAddr metaRefAddr = ref.get(ServiceReferenceable.SERVICE_REF_META_DATA);
+ ByteArrayInputStream bais = new
ByteArrayInputStream((byte[])metaRefAddr.getContent());
+ try
+ {
+ ObjectInputStream ois = new ObjectInputStream(bais);
+ serviceRef = (UnifiedServiceRefMetaData)ois.readObject();
+ ois.close();
+ }
+ catch (IOException ex)
+ {
+ NamingException ne = new NamingException("Cannot unmarshall service ref
meta data");
+ ne.setRootCause(ex);
+ throw ne;
+ }
+
+ // Unmarshall the WSSecurityConfiguration
+ WSSecurityConfiguration securityConfig = null;
+ RefAddr wsseRefAddr = ref.get(ServiceReferenceable.SECURITY_CONFIG);
+ if (wsseRefAddr != null)
+ {
+ bais = new ByteArrayInputStream((byte[])wsseRefAddr.getContent());
+ try
+ {
+ ObjectInputStream ois = new ObjectInputStream(bais);
+ securityConfig = (WSSecurityConfiguration)ois.readObject();
+ ois.close();
+ }
+ catch (IOException e)
+ {
+ throw new NamingException("Cannot unmarshall security config, cause:
" + e.toString());
+ }
+ }
+
+ ServiceImpl jaxrpcService = null;
+ URL wsdlLocation = serviceRef.getWsdlLocation();
+ if (wsdlLocation != null)
+ {
+ if (log.isDebugEnabled())
+ log.debug("Create jaxrpc service from wsdl");
+
+ // Create the actual service object
+ QName serviceName = serviceRef.getServiceQName();
+ JavaWsdlMapping javaWsdlMapping = getJavaWsdlMapping(serviceRef);
+ jaxrpcService = new ServiceImpl(serviceName, wsdlLocation, javaWsdlMapping,
securityConfig, serviceRef);
+ }
+ else
+ {
+ if (log.isDebugEnabled())
+ log.debug("Create jaxrpc service with no wsdl");
+ jaxrpcService = new ServiceImpl(new QName(Constants.NS_JBOSSWS_URI,
"AnonymousService"));
+ }
+
+ ServiceMetaData serviceMetaData = jaxrpcService.getServiceMetaData();
+
+ // Set any service level properties
+ if (serviceRef.getCallProperties().size() > 0)
+ {
+ Properties callProps = new Properties();
+ serviceMetaData.setProperties(callProps);
+ for (UnifiedCallPropertyMetaData prop : serviceRef.getCallProperties())
+ callProps.setProperty(prop.getPropName(), prop.getPropValue());
+ }
+
+ // The web service client using a port-component-link, the contet is the URL to
+ // the PortComponentLinkServlet that will return the actual endpoint address
+ RefAddr pcLinkRef = ref.get(ServiceReferenceable.PORT_COMPONENT_LINK);
+ if (pcLinkRef != null)
+ {
+ String pcLink = (String)pcLinkRef.getContent();
+ if (log.isDebugEnabled())
+ log.debug("Resolving port-component-link: " + pcLink);
+
+ // First try to obtain the endpoint address loacally
+ String endpointAddress = null;
+ try
+ {
+ ServiceEndpointManagerFactory factory =
ServiceEndpointManagerFactory.getInstance();
+ ServiceEndpointManager epManager = factory.getServiceEndpointManager();
+ ServiceEndpoint serviceEndpoint =
epManager.resolvePortComponentLink(pcLink);
+ if (serviceEndpoint == null)
+ throw new WSException("Cannot resolve port-component-link: "
+ pcLink);
+
+ endpointAddress =
serviceEndpoint.getServiceEndpointInfo().getServerEndpointMetaData().getEndpointAddress();
+ }
+ catch (Throwable ex)
+ {
+ // ignore, we are probably a remote client
+ }
+
+ // We may be remote in the esoteric case where an appclient uses the
port-comonent-link feature
+ if (endpointAddress == null)
+ {
+ String servletPath =
(String)ref.get(ServiceReferenceable.PORT_COMPONENT_LINK_SERVLET).getContent();
+ servletPath += "?pcLink=" + URLEncoder.encode(pcLink,
"UTF-8");
+ InputStream is = new URL(servletPath).openStream();
+ BufferedReader br = new BufferedReader(new InputStreamReader(is));
+ endpointAddress = br.readLine();
+ is.close();
+ }
+
+ if (log.isDebugEnabled())
+ log.debug("Resolved to: " + endpointAddress);
+ if (serviceMetaData.getEndpoints().size() == 1)
+ {
+ EndpointMetaData epMetaData = serviceMetaData.getEndpoints().get(0);
+ epMetaData.setEndpointAddress(endpointAddress);
+ }
+ else
+ {
+ log.warn("Cannot set endpoint address for port-component-link,
unsuported number of endpoints");
+ }
+ }
+
+ narrowPortSelection(serviceRef, serviceMetaData);
+
+ /********************************************************
+ * Setup the Proxy that implements the service-interface
+ ********************************************************/
+
+ // load the service interface class
+ ClassLoader contextCL = Thread.currentThread().getContextClassLoader();
+ Class siClass = contextCL.loadClass(serviceRef.getServiceInterface());
+ if (Service.class.isAssignableFrom(siClass) == false)
+ throw new JAXRPCException("The service interface does not implement
javax.xml.rpc.Service: " + siClass.getName());
+
+ // load all service endpoint interface classes
+ for (UnifiedPortComponentRefMetaData pcr : serviceRef.getPortComponentRefs())
+ {
+ Class seiClass = contextCL.loadClass(pcr.getServiceEndpointInterface());
+ if (Remote.class.isAssignableFrom(seiClass) == false)
+ throw new IllegalArgumentException("The SEI does not implement
java.rmi.Remote: " + seiClass.getName());
+ }
+
+ // Setup the handler chain
+ setupHandlerChain(jaxrpcService);
+
+ InvocationHandler handler = new ServiceProxy(jaxrpcService, siClass);
+ return Proxy.newProxyInstance(contextCL, new Class[] { siClass, ServiceExt.class
}, handler);
+ }
+ catch (Exception ex)
+ {
+ log.error("Cannot create service", ex);
+ throw ex;
+ }
+ }
+
+ /**
+ * Setup the handler chain(s) for this service
+ */
+ private void setupHandlerChain(ServiceImpl jaxrpcService) throws Exception
+ {
+ List<EndpointMetaData> endpoints =
jaxrpcService.getServiceMetaData().getEndpoints();
+ for (EndpointMetaData epMetaData : endpoints)
+ {
+ jaxrpcService.setupHandlerChain(epMetaData);
+ }
+ }
+
+ private JavaWsdlMapping getJavaWsdlMapping(UnifiedServiceRefMetaData serviceRef)
+ {
+ JavaWsdlMapping javaWsdlMapping = null;
+ if (serviceRef.getMappingFile() != null)
+ {
+ String mappingFile = serviceRef.getMappingFile();
+ try
+ {
+ JavaWsdlMappingFactory mappingFactory =
JavaWsdlMappingFactory.newInstance();
+ URL mappingURL = serviceRef.getVfsRoot().findChild(mappingFile).toURL();
+ javaWsdlMapping = mappingFactory.parse(mappingURL);
+ }
+ catch (Exception e)
+ {
+ throw new WSException("Cannot unmarshal jaxrpc-mapping-file: " +
mappingFile, e);
+ }
+ }
+ return javaWsdlMapping;
+ }
+}
Modified:
trunk/jbossws-core/src/java/org/jboss/ws/core/jaxrpc/client/ServiceReferenceable.java
===================================================================
---
trunk/jbossws-core/src/java/org/jboss/ws/core/jaxrpc/client/ServiceReferenceable.java 2007-04-15
22:38:49 UTC (rev 2876)
+++
trunk/jbossws-core/src/java/org/jboss/ws/core/jaxrpc/client/ServiceReferenceable.java 2007-04-16
10:31:31 UTC (rev 2877)
@@ -83,7 +83,7 @@
*/
public Reference getReference() throws NamingException
{
- Reference myRef = new Reference(ServiceReferenceable.class.getName(),
ServiceObjectFactory.class.getName(), null);
+ Reference myRef = new Reference(ServiceReferenceable.class.getName(),
ServiceObjectFactoryJAXRPC.class.getName(), null);
// Add a reference to the ServiceRefMetaData and WSDLDefinitions
myRef.add(new BinaryRefAddr(SERVICE_REF_META_DATA, marshallServiceRef()));
Deleted:
trunk/jbossws-core/src/java/org/jboss/ws/core/jaxws/client/ServiceObjectFactory.java
===================================================================
---
trunk/jbossws-core/src/java/org/jboss/ws/core/jaxws/client/ServiceObjectFactory.java 2007-04-15
22:38:49 UTC (rev 2876)
+++
trunk/jbossws-core/src/java/org/jboss/ws/core/jaxws/client/ServiceObjectFactory.java 2007-04-16
10:31:31 UTC (rev 2877)
@@ -1,240 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt 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.
- */
-// $Id$
-package org.jboss.ws.core.jaxws.client;
-
-// $Id$
-
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.net.URL;
-import java.util.Hashtable;
-
-import javax.naming.Context;
-import javax.naming.Name;
-import javax.naming.NamingException;
-import javax.naming.RefAddr;
-import javax.naming.Reference;
-import javax.naming.spi.ObjectFactory;
-import javax.xml.namespace.QName;
-import javax.xml.ws.Service;
-
-import org.jboss.logging.Logger;
-import org.jboss.ws.WSException;
-import org.jboss.ws.core.ConfigProvider;
-import org.jboss.ws.metadata.j2ee.serviceref.UnifiedServiceRefMetaData;
-
-/**
- * This ServiceObjectFactory reconstructs a javax.xml.ws.Service
- * for a given WSDL when the webservice client does a JNDI lookup
- *
- * @author Thomas.Diesler(a)jboss.org
- * @since 24-Oct-2004
- */
-public class ServiceObjectFactory implements ObjectFactory
-{
- // provide logging
- private static final Logger log = Logger.getLogger(ServiceObjectFactory.class);
-
- // The ServiceRefMetaData association
- private static ThreadLocal<UnifiedServiceRefMetaData> serviceRefAssociation =
new ThreadLocal<UnifiedServiceRefMetaData>();
-
- /**
- * Creates an object using the location or reference information specified.
- * <p/>
- *
- * @param obj The possibly null object containing location or reference
- * information that can be used in creating an object.
- * @param name The name of this object relative to
<code>nameCtx</code>,
- * or null if no name is specified.
- * @param nameCtx The context relative to which the <code>name</code>
- * parameter is specified, or null if <code>name</code>
is
- * relative to the default initial context.
- * @param environment The possibly null environment that is used in
- * creating the object.
- * @return The object created; null if an object cannot be created.
- * @throws Exception if this object factory encountered an exception
- * while attempting to create an object, and no other object
factories are
- * to be tried.
- * @see javax.naming.spi.NamingManager#getObjectInstance
- * @see javax.naming.spi.NamingManager#getURLContext
- */
- public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable
environment) throws Exception
- {
- try
- {
- Reference ref = (Reference)obj;
-
- // Get the target class name
- String targetClassName =
(String)ref.get(ServiceReferenceable.TARGET_CLASS_NAME).getContent();
-
- // Unmarshall the UnifiedServiceRef
- UnifiedServiceRefMetaData serviceRef = unmarshallServiceRef(ref);
- String serviceRefName = serviceRef.getServiceRefName();
- QName serviceQName = serviceRef.getServiceQName();
-
- String serviceImplClass = serviceRef.getServiceImplClass();
- if (serviceImplClass == null)
- serviceImplClass =
(String)ref.get(ServiceReferenceable.SERVICE_IMPL_CLASS).getContent();
-
- // If the target defaults to javax.xml.ws.Service, use the service as the
target
- if (Service.class.getName().equals(targetClassName))
- targetClassName = serviceImplClass;
-
- log.debug("[name=" + serviceRefName + ",service=" +
serviceImplClass + ",target=" + targetClassName + "]");
-
- // Load the service class
- ClassLoader ctxLoader = Thread.currentThread().getContextClassLoader();
- Class serviceClass = ctxLoader.loadClass(serviceImplClass);
- Class targetClass = (targetClassName != null ?
ctxLoader.loadClass(targetClassName) : null);
-
- if (Service.class.isAssignableFrom(serviceClass) == false)
- throw new IllegalArgumentException("WebServiceRef type '" +
serviceClass + "' is not assignable to javax.xml.ws.Service");
-
- // Receives either a javax.xml.ws.Service or a dynamic proxy
- Object target;
-
- // Get the URL to the wsdl
- URL wsdlURL = serviceRef.getWsdlLocation();
- try
- {
- // Associate the ServiceRefMetaData with this thread
- serviceRefAssociation.set(serviceRef);
-
- // Generic javax.xml.ws.Service
- if (serviceClass == Service.class)
- {
- if (wsdlURL != null)
- {
- target = Service.create(wsdlURL, serviceQName);
- }
- else
- {
- throw new IllegalArgumentException("Cannot create generic
javax.xml.ws.Service without wsdlLocation: " + serviceRefName);
- }
- }
- // Generated javax.xml.ws.Service subclass
- else
- {
- if (wsdlURL != null)
- {
- Constructor ctor = serviceClass.getConstructor(new Class[] { URL.class,
QName.class });
- target = ctor.newInstance(new Object[] { wsdlURL, serviceQName });
- }
- else
- {
- target = (Service)serviceClass.newInstance();
- }
- }
- }
- finally
- {
- serviceRefAssociation.set(null);
- }
-
- // Configure the service
- configureService((Service)target, serviceRef);
-
- if (targetClassName != null && targetClassName.equals(serviceImplClass)
== false)
- {
- try
- {
- Object port = null;
- if (serviceClass != Service.class)
- {
- for (Method method : serviceClass.getDeclaredMethods())
- {
- String methodName = method.getName();
- Class retType = method.getReturnType();
- if (methodName.startsWith("get") &&
targetClass.isAssignableFrom(retType))
- {
- port = method.invoke(target, new Object[0]);
- target = port;
- break;
- }
- }
- }
-
- if (port == null)
- {
- Method method = serviceClass.getMethod("getPort", new Class[]
{ Class.class });
- port = method.invoke(target, new Object[] { targetClass });
- target = port;
- }
- }
- catch (InvocationTargetException ex)
- {
- throw ex.getTargetException();
- }
- }
-
- return target;
- }
- catch (Throwable ex)
- {
- WSException.rethrow("Cannot create service", ex);
- return null;
- }
- }
-
- public static UnifiedServiceRefMetaData getServiceRefAssociation()
- {
- // The ServiceDelegateImpl get the usRef at ctor time
- return (UnifiedServiceRefMetaData)serviceRefAssociation.get();
- }
-
- private void configureService(Service service, UnifiedServiceRefMetaData serviceRef)
- {
- String configFile = serviceRef.getConfigFile();
- String configName = serviceRef.getConfigName();
- if (service instanceof ConfigProvider)
- {
- if(log.isDebugEnabled()) log.debug("Configure Service: [configName=" +
configName + ",configFile=" + configFile + "]");
-
- ConfigProvider cp = (ConfigProvider)service;
- if (configName != null || configFile != null)
- cp.setConfigName(configName, configFile);
- }
- }
-
- private UnifiedServiceRefMetaData unmarshallServiceRef(Reference ref) throws
ClassNotFoundException, NamingException
- {
- UnifiedServiceRefMetaData sref;
- RefAddr refAddr = ref.get(ServiceReferenceable.SERVICE_REF_META_DATA);
- ByteArrayInputStream bais = new
ByteArrayInputStream((byte[])refAddr.getContent());
- try
- {
- ObjectInputStream ois = new ObjectInputStream(bais);
- sref = (UnifiedServiceRefMetaData)ois.readObject();
- ois.close();
- }
- catch (IOException e)
- {
- throw new NamingException("Cannot unmarshall service ref meta data, cause:
" + e.toString());
- }
- return sref;
- }
-}
Added:
trunk/jbossws-core/src/java/org/jboss/ws/core/jaxws/client/ServiceObjectFactoryJAXWS.java
===================================================================
---
trunk/jbossws-core/src/java/org/jboss/ws/core/jaxws/client/ServiceObjectFactoryJAXWS.java
(rev 0)
+++
trunk/jbossws-core/src/java/org/jboss/ws/core/jaxws/client/ServiceObjectFactoryJAXWS.java 2007-04-16
10:31:31 UTC (rev 2877)
@@ -0,0 +1,241 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.
+ */
+// $Id$
+package org.jboss.ws.core.jaxws.client;
+
+// $Id$
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.net.URL;
+import java.util.Hashtable;
+
+import javax.naming.Context;
+import javax.naming.Name;
+import javax.naming.NamingException;
+import javax.naming.RefAddr;
+import javax.naming.Reference;
+import javax.naming.spi.ObjectFactory;
+import javax.xml.namespace.QName;
+import javax.xml.ws.Service;
+
+import org.jboss.logging.Logger;
+import org.jboss.ws.WSException;
+import org.jboss.ws.core.ConfigProvider;
+import org.jboss.ws.core.client.ServiceObjectFactory;
+import org.jboss.ws.metadata.j2ee.serviceref.UnifiedServiceRefMetaData;
+
+/**
+ * This ServiceObjectFactory reconstructs a javax.xml.ws.Service
+ * for a given WSDL when the webservice client does a JNDI lookup
+ *
+ * @author Thomas.Diesler(a)jboss.org
+ * @since 24-Oct-2004
+ */
+public class ServiceObjectFactoryJAXWS extends ServiceObjectFactory
+{
+ // provide logging
+ private static final Logger log = Logger.getLogger(ServiceObjectFactoryJAXWS.class);
+
+ // The ServiceRefMetaData association
+ private static ThreadLocal<UnifiedServiceRefMetaData> serviceRefAssociation =
new ThreadLocal<UnifiedServiceRefMetaData>();
+
+ /**
+ * Creates an object using the location or reference information specified.
+ * <p/>
+ *
+ * @param obj The possibly null object containing location or reference
+ * information that can be used in creating an object.
+ * @param name The name of this object relative to
<code>nameCtx</code>,
+ * or null if no name is specified.
+ * @param nameCtx The context relative to which the <code>name</code>
+ * parameter is specified, or null if <code>name</code>
is
+ * relative to the default initial context.
+ * @param environment The possibly null environment that is used in
+ * creating the object.
+ * @return The object created; null if an object cannot be created.
+ * @throws Exception if this object factory encountered an exception
+ * while attempting to create an object, and no other object
factories are
+ * to be tried.
+ * @see javax.naming.spi.NamingManager#getObjectInstance
+ * @see javax.naming.spi.NamingManager#getURLContext
+ */
+ public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable
environment) throws Exception
+ {
+ try
+ {
+ Reference ref = (Reference)obj;
+
+ // Get the target class name
+ String targetClassName =
(String)ref.get(ServiceReferenceable.TARGET_CLASS_NAME).getContent();
+
+ // Unmarshall the UnifiedServiceRef
+ UnifiedServiceRefMetaData serviceRef = unmarshallServiceRef(ref);
+ String serviceRefName = serviceRef.getServiceRefName();
+ QName serviceQName = serviceRef.getServiceQName();
+
+ String serviceImplClass = serviceRef.getServiceImplClass();
+ if (serviceImplClass == null)
+ serviceImplClass =
(String)ref.get(ServiceReferenceable.SERVICE_IMPL_CLASS).getContent();
+
+ // If the target defaults to javax.xml.ws.Service, use the service as the
target
+ if (Service.class.getName().equals(targetClassName))
+ targetClassName = serviceImplClass;
+
+ log.debug("[name=" + serviceRefName + ",service=" +
serviceImplClass + ",target=" + targetClassName + "]");
+
+ // Load the service class
+ ClassLoader ctxLoader = Thread.currentThread().getContextClassLoader();
+ Class serviceClass = ctxLoader.loadClass(serviceImplClass);
+ Class targetClass = (targetClassName != null ?
ctxLoader.loadClass(targetClassName) : null);
+
+ if (Service.class.isAssignableFrom(serviceClass) == false)
+ throw new IllegalArgumentException("WebServiceRef type '" +
serviceClass + "' is not assignable to javax.xml.ws.Service");
+
+ // Receives either a javax.xml.ws.Service or a dynamic proxy
+ Object target;
+
+ // Get the URL to the wsdl
+ URL wsdlURL = serviceRef.getWsdlLocation();
+ try
+ {
+ // Associate the ServiceRefMetaData with this thread
+ serviceRefAssociation.set(serviceRef);
+
+ // Generic javax.xml.ws.Service
+ if (serviceClass == Service.class)
+ {
+ if (wsdlURL != null)
+ {
+ target = Service.create(wsdlURL, serviceQName);
+ }
+ else
+ {
+ throw new IllegalArgumentException("Cannot create generic
javax.xml.ws.Service without wsdlLocation: " + serviceRefName);
+ }
+ }
+ // Generated javax.xml.ws.Service subclass
+ else
+ {
+ if (wsdlURL != null)
+ {
+ Constructor ctor = serviceClass.getConstructor(new Class[] { URL.class,
QName.class });
+ target = ctor.newInstance(new Object[] { wsdlURL, serviceQName });
+ }
+ else
+ {
+ target = (Service)serviceClass.newInstance();
+ }
+ }
+ }
+ finally
+ {
+ serviceRefAssociation.set(null);
+ }
+
+ // Configure the service
+ configureService((Service)target, serviceRef);
+
+ if (targetClassName != null && targetClassName.equals(serviceImplClass)
== false)
+ {
+ try
+ {
+ Object port = null;
+ if (serviceClass != Service.class)
+ {
+ for (Method method : serviceClass.getDeclaredMethods())
+ {
+ String methodName = method.getName();
+ Class retType = method.getReturnType();
+ if (methodName.startsWith("get") &&
targetClass.isAssignableFrom(retType))
+ {
+ port = method.invoke(target, new Object[0]);
+ target = port;
+ break;
+ }
+ }
+ }
+
+ if (port == null)
+ {
+ Method method = serviceClass.getMethod("getPort", new Class[]
{ Class.class });
+ port = method.invoke(target, new Object[] { targetClass });
+ target = port;
+ }
+ }
+ catch (InvocationTargetException ex)
+ {
+ throw ex.getTargetException();
+ }
+ }
+
+ return target;
+ }
+ catch (Throwable ex)
+ {
+ WSException.rethrow("Cannot create service", ex);
+ return null;
+ }
+ }
+
+ public static UnifiedServiceRefMetaData getServiceRefAssociation()
+ {
+ // The ServiceDelegateImpl get the usRef at ctor time
+ return (UnifiedServiceRefMetaData)serviceRefAssociation.get();
+ }
+
+ private void configureService(Service service, UnifiedServiceRefMetaData serviceRef)
+ {
+ String configFile = serviceRef.getConfigFile();
+ String configName = serviceRef.getConfigName();
+ if (service instanceof ConfigProvider)
+ {
+ if(log.isDebugEnabled()) log.debug("Configure Service: [configName=" +
configName + ",configFile=" + configFile + "]");
+
+ ConfigProvider cp = (ConfigProvider)service;
+ if (configName != null || configFile != null)
+ cp.setConfigName(configName, configFile);
+ }
+ }
+
+ private UnifiedServiceRefMetaData unmarshallServiceRef(Reference ref) throws
ClassNotFoundException, NamingException
+ {
+ UnifiedServiceRefMetaData sref;
+ RefAddr refAddr = ref.get(ServiceReferenceable.SERVICE_REF_META_DATA);
+ ByteArrayInputStream bais = new
ByteArrayInputStream((byte[])refAddr.getContent());
+ try
+ {
+ ObjectInputStream ois = new ObjectInputStream(bais);
+ sref = (UnifiedServiceRefMetaData)ois.readObject();
+ ois.close();
+ }
+ catch (IOException e)
+ {
+ throw new NamingException("Cannot unmarshall service ref meta data, cause:
" + e.toString());
+ }
+ return sref;
+ }
+}
Property changes on:
trunk/jbossws-core/src/java/org/jboss/ws/core/jaxws/client/ServiceObjectFactoryJAXWS.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Modified:
trunk/jbossws-core/src/java/org/jboss/ws/core/jaxws/client/ServiceReferenceable.java
===================================================================
---
trunk/jbossws-core/src/java/org/jboss/ws/core/jaxws/client/ServiceReferenceable.java 2007-04-15
22:38:49 UTC (rev 2876)
+++
trunk/jbossws-core/src/java/org/jboss/ws/core/jaxws/client/ServiceReferenceable.java 2007-04-16
10:31:31 UTC (rev 2877)
@@ -71,7 +71,7 @@
*/
public Reference getReference() throws NamingException
{
- Reference myRef = new Reference(ServiceReferenceable.class.getName(),
ServiceObjectFactory.class.getName(), null);
+ Reference myRef = new Reference(ServiceReferenceable.class.getName(),
ServiceObjectFactoryJAXWS.class.getName(), null);
myRef.add(new StringRefAddr(SERVICE_IMPL_CLASS, serviceImplClass));
myRef.add(new StringRefAddr(TARGET_CLASS_NAME, targetClassName));
Modified:
trunk/jbossws-core/src/java/org/jboss/ws/core/jaxws/spi/ServiceDelegateImpl.java
===================================================================
---
trunk/jbossws-core/src/java/org/jboss/ws/core/jaxws/spi/ServiceDelegateImpl.java 2007-04-15
22:38:49 UTC (rev 2876)
+++
trunk/jbossws-core/src/java/org/jboss/ws/core/jaxws/spi/ServiceDelegateImpl.java 2007-04-16
10:31:31 UTC (rev 2877)
@@ -23,8 +23,6 @@
// $Id$
-import java.io.IOException;
-import java.io.InputStream;
import java.lang.reflect.Proxy;
import java.net.URL;
import java.util.ArrayList;
@@ -41,7 +39,6 @@
import javax.xml.ws.BindingProvider;
import javax.xml.ws.Dispatch;
import javax.xml.ws.EndpointReference;
-import javax.xml.ws.Service;
import javax.xml.ws.WebServiceException;
import javax.xml.ws.WebServiceFeature;
import javax.xml.ws.Service.Mode;
@@ -54,7 +51,7 @@
import org.jboss.ws.core.jaxws.client.ClientImpl;
import org.jboss.ws.core.jaxws.client.ClientProxy;
import org.jboss.ws.core.jaxws.client.DispatchImpl;
-import org.jboss.ws.core.jaxws.client.ServiceObjectFactory;
+import org.jboss.ws.core.jaxws.client.ServiceObjectFactoryJAXWS;
import org.jboss.ws.core.jaxws.handler.HandlerResolverImpl;
import org.jboss.ws.integration.ResourceLoaderAdapter;
import org.jboss.ws.integration.UnifiedVirtualFile;
@@ -105,35 +102,11 @@
public ServiceDelegateImpl(URL wsdlURL, QName serviceName, Class serviceClass)
{
- UnifiedVirtualFile vfsRoot;
-
// If this Service was constructed through the ServiceObjectFactory
// this thread local association should be available
- usRef = ServiceObjectFactory.getServiceRefAssociation();
- if (usRef != null)
- {
- vfsRoot = usRef.getVfsRoot();
+ usRef = ServiceObjectFactoryJAXWS.getServiceRefAssociation();
+ UnifiedVirtualFile vfsRoot = (usRef != null ? vfsRoot = usRef.getVfsRoot() : new
ResourceLoaderAdapter());
- // Verify wsdl access if this is not a generic Service
- if (wsdlURL != null && serviceClass != Service.class)
- {
- try
- {
- InputStream is = wsdlURL.openStream();
- is.close();
- }
- catch (IOException e)
- {
- log.warn("Cannot access wsdlURL: " + wsdlURL);
- wsdlURL = null;
- }
- }
- }
- else
- {
- vfsRoot = new ResourceLoaderAdapter();
- }
-
if (wsdlURL != null)
{
JAXWSClientMetaDataBuilder builder = new JAXWSClientMetaDataBuilder();
@@ -182,18 +155,12 @@
if (serviceMetaData == null)
throw new WebServiceException("Service meta data not available");
+ // com/sun/ts/tests/jaxws/api/javax_xml_ws/Service
+ // GetPort1NegTest1WithWsdl_from_wsappclient
EndpointMetaData epMetaData = serviceMetaData.getEndpoint(portName);
if (epMetaData == null)
- {
- log.warn("Cannot get port meta data for: " + portName);
+ throw new WebServiceException("Cannot get port meta data for: " +
portName);
- if (!seiClass.isAnnotationPresent(WebService.class))
- throw new IllegalArgumentException("Cannot find @WebService on: " +
seiClass.getName());
-
- QName portType = getPortTypeName(seiClass);
- epMetaData = new ClientEndpointMetaData(serviceMetaData, portName, portType,
Type.JAXWS);
- }
-
String seiClassName = seiClass.getName();
epMetaData.setServiceEndpointInterfaceName(seiClassName);
@@ -215,11 +182,11 @@
return portType;
}
- @Override
/**
* The getPort method returns a stub. A service client uses this stub to invoke
operations on the target service endpoint.
* The serviceEndpointInterface specifies the service endpoint interface that is
supported by the created dynamic proxy or stub instance.
*/
+ @Override
public <T> T getPort(Class<T> seiClass)
{
assertSEIConstraints(seiClass);
@@ -237,18 +204,10 @@
}
else
{
- // resolve PortType by name
- WebService ws = seiClass.getAnnotation(WebService.class);
- String ns = ws.targetNamespace();
- String name = ws.name();
-
- // TODO: default name mapping when annotations not used
- QName portTypeName = new QName(ns, name);
-
+ QName portTypeName = getPortTypeName(seiClass);
for (EndpointMetaData epmd : serviceMetaData.getEndpoints())
{
- QName interfaceQName = epmd.getPortTypeName(); // skip namespaces here
- if (interfaceQName.getLocalPart().equals(portTypeName.getLocalPart()))
+ if (portTypeName.equals(epmd.getPortTypeName()))
{
epmd.setServiceEndpointInterfaceName(seiClass.getName());
epMetaData = epmd;
Modified:
trunk/jbossws-core/src/java/org/jboss/ws/metadata/builder/jaxws/JAXWSClientMetaDataBuilder.java
===================================================================
---
trunk/jbossws-core/src/java/org/jboss/ws/metadata/builder/jaxws/JAXWSClientMetaDataBuilder.java 2007-04-15
22:38:49 UTC (rev 2876)
+++
trunk/jbossws-core/src/java/org/jboss/ws/metadata/builder/jaxws/JAXWSClientMetaDataBuilder.java 2007-04-16
10:31:31 UTC (rev 2877)
@@ -34,7 +34,7 @@
import org.jboss.ws.Constants;
import org.jboss.ws.WSException;
import org.jboss.ws.core.jaxrpc.Style;
-import org.jboss.ws.core.jaxws.client.ServiceObjectFactory;
+import org.jboss.ws.core.jaxws.client.ServiceObjectFactoryJAXWS;
import org.jboss.ws.integration.ResourceLoaderAdapter;
import org.jboss.ws.integration.UnifiedVirtualFile;
import org.jboss.ws.metadata.umdm.ClientEndpointMetaData;
@@ -161,7 +161,7 @@
*/
private void bufferServiceRefContributions(EndpointMetaData epMetaData)
{
- UnifiedServiceRefMetaData serviceRefMetaData =
ServiceObjectFactory.getServiceRefAssociation();
+ UnifiedServiceRefMetaData serviceRefMetaData =
ServiceObjectFactoryJAXWS.getServiceRefAssociation();
if(serviceRefMetaData!=null)
{