Author: thomas.diesler(a)jboss.com
Date: 2006-10-24 09:50:36 -0400 (Tue, 24 Oct 2006)
New Revision: 1295
Added:
branches/tdiesler/trunk/src/main/java/org/jboss/ws/jaxws/ServiceObjectFactory.java
branches/tdiesler/trunk/src/main/java/org/jboss/ws/jaxws/ServiceReferenceable.java
Modified:
branches/tdiesler/trunk/src/main/java/org/jboss/ws/integration/jboss/WebServiceRefDeployer.java
branches/tdiesler/trunk/src/test/java/org/jboss/test/ws/jaxws/webserviceref/ApplicationClient.java
branches/tdiesler/trunk/src/test/java/org/jboss/test/ws/jaxws/webserviceref/TestEndpointImpl.java
Log:
Implement @WebServiceRef
Modified:
branches/tdiesler/trunk/src/main/java/org/jboss/ws/integration/jboss/WebServiceRefDeployer.java
===================================================================
---
branches/tdiesler/trunk/src/main/java/org/jboss/ws/integration/jboss/WebServiceRefDeployer.java 2006-10-24
08:33:04 UTC (rev 1294)
+++
branches/tdiesler/trunk/src/main/java/org/jboss/ws/integration/jboss/WebServiceRefDeployer.java 2006-10-24
13:50:36 UTC (rev 1295)
@@ -23,17 +23,12 @@
// $Id$
-import java.lang.reflect.Constructor;
-import java.net.URL;
-
import javax.naming.Context;
-import javax.xml.namespace.QName;
-import javax.xml.ws.Service;
import javax.xml.ws.WebServiceRef;
import org.jboss.logging.Logger;
import org.jboss.naming.Util;
-import org.jboss.ws.deployment.JAXWSClientMetaDataBuilder;
+import org.jboss.ws.jaxws.ServiceReferenceable;
/**
* Binds a JAXWS Service object into JNDI
@@ -41,36 +36,19 @@
* @author Thomas.Diesler(a)jboss.org
* @since 24-Oct-2006
*/
-public class WebServiceRefDeployer
+public class WebServiceRefDeployer
{
// provide logging
private static Logger log = Logger.getLogger(WebServiceRefDeployer.class);
-
+
private WebServiceRefDeployer()
{
// Hide ctor
}
-
- public static void setupWebServiceRef(Context jndiCtx, String jndiName, Class type,
WebServiceRef ref) throws Exception
+
+ public static void setupWebServiceRef(Context ctx, String jndiName, Class type,
WebServiceRef ref) throws Exception
{
- String wsdlLocation = ref.wsdlLocation();
- log.debug("setupWebServiceRef [jndi=" + jndiName + ",type=" +
type + ",wsdl=" + wsdlLocation + "]");
-
- if (Service.class.isAssignableFrom(type) == false)
- throw new IllegalArgumentException("WebServiceRef type '" + type +
"' is not assignable to javax.xml.ws.Service");
-
- Service service;
- if (wsdlLocation.length() > 0)
- {
- Constructor ctor = type.getConstructor(new Class[]{URL.class, QName.class});
- URL wsdlURL = new URL(wsdlLocation);
- service = (Service)ctor.newInstance(new Object[]{wsdlURL, null});
- }
- else
- {
- service = (Service)type.newInstance();
- }
-
- Util.bind(jndiCtx, jndiName, service);
+ Util.bind(ctx, jndiName, new ServiceReferenceable(type.getName(),
ref.wsdlLocation()));
+ log.debug("WebServiceRef bound [jndi=" + jndiName + ",type=" +
type.getName() + "]");
}
}
Added: branches/tdiesler/trunk/src/main/java/org/jboss/ws/jaxws/ServiceObjectFactory.java
===================================================================
---
branches/tdiesler/trunk/src/main/java/org/jboss/ws/jaxws/ServiceObjectFactory.java 2006-10-24
08:33:04 UTC (rev 1294)
+++
branches/tdiesler/trunk/src/main/java/org/jboss/ws/jaxws/ServiceObjectFactory.java 2006-10-24
13:50:36 UTC (rev 1295)
@@ -0,0 +1,158 @@
+/*
+ * 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.jaxws;
+
+// $Id$
+
+import java.io.File;
+import java.lang.reflect.Constructor;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Hashtable;
+
+import javax.naming.Context;
+import javax.naming.Name;
+import javax.naming.Reference;
+import javax.naming.spi.ObjectFactory;
+import javax.xml.namespace.QName;
+import javax.xml.ws.Service;
+
+import org.jboss.logging.Logger;
+
+/**
+ * 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);
+
+ /**
+ * 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;
+
+ String serviceTypeName =
(String)ref.get(ServiceReferenceable.SERVICE_TYPE).getContent();
+ String wsdlLocation =
(String)ref.get(ServiceReferenceable.WSDL_LOCATION).getContent();
+
+ ClassLoader ctxLoader = Thread.currentThread().getContextClassLoader();
+ Class serviceType = ctxLoader.loadClass(serviceTypeName);
+
+ if (Service.class.isAssignableFrom(serviceType) == false)
+ throw new IllegalArgumentException("WebServiceRef type '" +
serviceType + "' is not assignable to javax.xml.ws.Service");
+
+ Service service;
+
+ URL wsdlURL = getWsdlLocationURL(serviceType, wsdlLocation);
+ if (wsdlURL != null)
+ {
+ Constructor ctor = serviceType.getConstructor(new Class[] { URL.class,
QName.class });
+ service = (Service)ctor.newInstance(new Object[] { wsdlURL, null });
+ }
+ else
+ {
+ service = (Service)serviceType.newInstance();
+ }
+
+ return service;
+ }
+ catch (Exception ex)
+ {
+ log.error("Cannot create service", ex);
+ throw ex;
+ }
+ }
+
+ private URL getWsdlLocationURL(Class type, String wsdlLocation)
+ {
+ URL wsdlURL = null;
+ if (wsdlLocation != null && wsdlLocation.length() > 0)
+ {
+ // Try the wsdlLocation as URL
+ try
+ {
+ wsdlURL = new URL(wsdlLocation);
+ }
+ catch (MalformedURLException ex)
+ {
+ // ignore
+ }
+
+ // Try the filename as File
+ if (wsdlURL == null)
+ {
+ try
+ {
+ File file = new File(wsdlLocation);
+ if (file.exists())
+ wsdlURL = file.toURL();
+ }
+ catch (MalformedURLException e)
+ {
+ // ignore
+ }
+ }
+
+ // Try the filename as Resource
+ if (wsdlURL == null)
+ {
+ ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ wsdlURL = loader.getResource(wsdlLocation);
+ }
+
+ // Try the filename relative to class
+ if (wsdlURL == null)
+ {
+ String packagePath = type.getPackage().getName().replace('.',
'/');
+ ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ wsdlURL = loader.getResource(packagePath + "/" + wsdlLocation);
+ }
+ }
+ return wsdlURL;
+ }
+}
Property changes on:
branches/tdiesler/trunk/src/main/java/org/jboss/ws/jaxws/ServiceObjectFactory.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: branches/tdiesler/trunk/src/main/java/org/jboss/ws/jaxws/ServiceReferenceable.java
===================================================================
---
branches/tdiesler/trunk/src/main/java/org/jboss/ws/jaxws/ServiceReferenceable.java 2006-10-24
08:33:04 UTC (rev 1294)
+++
branches/tdiesler/trunk/src/main/java/org/jboss/ws/jaxws/ServiceReferenceable.java 2006-10-24
13:50:36 UTC (rev 1295)
@@ -0,0 +1,70 @@
+/*
+ * 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.jaxws;
+
+// $Id$
+
+import javax.naming.NamingException;
+import javax.naming.Reference;
+import javax.naming.Referenceable;
+import javax.naming.StringRefAddr;
+
+/**
+ * A JNDI reference to a javax.xml.ws.Service
+ *
+ * It holds the information to reconstrut the javax.xml.ws.Service
+ * when the client does a JNDI lookup.
+ *
+ * @author Thomas.Diesler(a)jboss.org
+ * @since 24-Oct-2006
+ */
+public class ServiceReferenceable implements Referenceable
+{
+ public static final String WSDL_LOCATION = "WSDL_LOCATION";
+ public static final String SERVICE_TYPE = "SERVICE_TYPE";
+
+ private String serviceType;
+ private String wsdlLocation;
+
+ public ServiceReferenceable(String serviceType, String wsdlLocation)
+ {
+ this.serviceType = serviceType;
+ this.wsdlLocation = wsdlLocation;
+ }
+
+ /**
+ * Retrieves the Reference of this object.
+ *
+ * @return The non-null Reference of this object.
+ * @throws javax.naming.NamingException If a naming exception was encountered while
retrieving the reference.
+ */
+ public Reference getReference() throws NamingException
+ {
+ Reference myRef = new Reference(ServiceReferenceable.class.getName(),
ServiceObjectFactory.class.getName(), null);
+
+ myRef.add(new StringRefAddr(SERVICE_TYPE, serviceType));
+ myRef.add(new StringRefAddr(WSDL_LOCATION, wsdlLocation));
+
+ return myRef;
+ }
+}
\ No newline at end of file
Property changes on:
branches/tdiesler/trunk/src/main/java/org/jboss/ws/jaxws/ServiceReferenceable.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Modified:
branches/tdiesler/trunk/src/test/java/org/jboss/test/ws/jaxws/webserviceref/ApplicationClient.java
===================================================================
---
branches/tdiesler/trunk/src/test/java/org/jboss/test/ws/jaxws/webserviceref/ApplicationClient.java 2006-10-24
08:33:04 UTC (rev 1294)
+++
branches/tdiesler/trunk/src/test/java/org/jboss/test/ws/jaxws/webserviceref/ApplicationClient.java 2006-10-24
13:50:36 UTC (rev 1295)
@@ -23,16 +23,21 @@
import javax.xml.ws.WebServiceRef;
+import org.jboss.logging.Logger;
+
public class ApplicationClient
{
- @WebServiceRef
- public TestEndpointService service;
+ // Provide logging
+ private static Logger log = Logger.getLogger(ApplicationClient.class);
+
+ @WebServiceRef (name ="TestEndpointService", wsdlLocation
="META-INF/wsdl/TestEndpoint.wsdl")
+ public static TestEndpointService service;
public static void main(String[] args)
{
ApplicationClient client = new ApplicationClient();
String outStr = client.echo("Hello world!");
- System.out.println(outStr);
+ log.info(outStr);
}
public String echo(String inStr)
Modified:
branches/tdiesler/trunk/src/test/java/org/jboss/test/ws/jaxws/webserviceref/TestEndpointImpl.java
===================================================================
---
branches/tdiesler/trunk/src/test/java/org/jboss/test/ws/jaxws/webserviceref/TestEndpointImpl.java 2006-10-24
08:33:04 UTC (rev 1294)
+++
branches/tdiesler/trunk/src/test/java/org/jboss/test/ws/jaxws/webserviceref/TestEndpointImpl.java 2006-10-24
13:50:36 UTC (rev 1295)
@@ -24,6 +24,8 @@
import javax.jws.WebMethod;
import javax.jws.WebService;
+import org.jboss.logging.Logger;
+
/**
* Test the JAXWS annotation: javax.jws.WebServiceRef
*
@@ -33,9 +35,13 @@
@WebService(name = "TestEndpoint", targetNamespace =
"http://org.jboss.ws/wsref")
public class TestEndpointImpl
{
+ // Provide logging
+ private static Logger log = Logger.getLogger(TestEndpointImpl.class);
+
@WebMethod
public String echo(String input)
{
+ log.info(input);
return input;
}
}