From: Chris L. <chr...@jb...> - 2006-05-10 22:45:33
|
User: claprun Date: 06/05/10 18:45:31 Modified: wsrp/src/main/org/jboss/portal/wsrp PerEndpointSOAPInvokerServiceFactory.java RMIInvokerServiceFactory.java RemoteSOAPInvokerServiceFactory.java SOAPInvokerServiceFactory.java ServiceFactory.java ServiceFactoryImpl.java Log: - Re-factored ServiceFactory hierarchy. - Re-implemented RemoteSOAPInvokerServiceFactory (which now seems to work but needs more testing). Revision Changes Path 1.2 +143 -159 jboss-portal/wsrp/src/main/org/jboss/portal/wsrp/PerEndpointSOAPInvokerServiceFactory.java (In the diff below, changes in quantity of whitespace are not shown.) Index: PerEndpointSOAPInvokerServiceFactory.java =================================================================== RCS file: /cvsroot/jboss/jboss-portal/wsrp/src/main/org/jboss/portal/wsrp/PerEndpointSOAPInvokerServiceFactory.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -b -r1.1 -r1.2 --- PerEndpointSOAPInvokerServiceFactory.java 9 May 2006 02:19:20 -0000 1.1 +++ PerEndpointSOAPInvokerServiceFactory.java 10 May 2006 22:45:31 -0000 1.2 @@ -21,23 +21,20 @@ */ package org.jboss.portal.wsrp; -import org.jboss.portal.wsrp.core.WSRP_v1_ServiceDescription_PortType; import org.jboss.portal.wsrp.core.WSRP_v1_Markup_PortType; -import org.jboss.portal.wsrp.core.WSRP_v1_Registration_PortType; import org.jboss.portal.wsrp.core.WSRP_v1_PortletManagement_PortType; +import org.jboss.portal.wsrp.core.WSRP_v1_Registration_PortType; +import org.jboss.portal.wsrp.core.WSRP_v1_ServiceDescription_PortType; import javax.xml.rpc.Service; import javax.xml.rpc.Stub; -import java.util.Map; -import java.util.Properties; -import java.util.Iterator; /** * todo : cache created configured proxies * * @author <a href="mailto:chr...@jb...">Chris Laprun</a> * @author <a href="mailto:ju...@jb...">Julien Viet</a> - * @version $Revision: 1.1 $ + * @version $Revision: 1.2 $ * @since 2.4 */ public class PerEndpointSOAPInvokerServiceFactory extends ServiceFactoryImpl @@ -47,19 +44,16 @@ private static final String ENDPOINT_ADDRESS_PROP = "javax.xml.rpc.service.endpoint.address"; /** . */ - private Properties portJNDIMapping; + protected String serviceDescriptionURL; /** . */ - private String serviceDescriptionURL; + protected String markupURL; /** . */ - private String markupURL; + protected String registrationURL; /** . */ - private String registrationURL; - - /** . */ - private String portletManagementURL; + protected String portletManagementURL; public String getServiceDescriptionURL() { @@ -101,17 +95,7 @@ this.portletManagementURL = portletManagementURL; } - public Properties getPortJNDIMapping() - { - return portJNDIMapping; - } - - public void setPortJNDIMapping(Properties portJNDIMapping) - { - this.portJNDIMapping = portJNDIMapping; - } - - protected void initPortTypeClassToJDNINameMap() + /*protected void initPortTypeClassToJDNINameMap() { for (Iterator i = portJNDIMapping.entrySet().iterator(); i.hasNext();) { @@ -121,7 +105,7 @@ portTypeClassToJNDIName.put(portTypeClassName, portTypeJNDIName); log.debug("Use jndi name " + portTypeJNDIName + " for port of type " + portTypeClassName); } - } + }*/ public Object getService(Class clazz) throws Exception { 1.3 +9 -7 jboss-portal/wsrp/src/main/org/jboss/portal/wsrp/RMIInvokerServiceFactory.java (In the diff below, changes in quantity of whitespace are not shown.) Index: RMIInvokerServiceFactory.java =================================================================== RCS file: /cvsroot/jboss/jboss-portal/wsrp/src/main/org/jboss/portal/wsrp/RMIInvokerServiceFactory.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -b -r1.2 -r1.3 --- RMIInvokerServiceFactory.java 6 May 2006 12:21:46 -0000 1.2 +++ RMIInvokerServiceFactory.java 10 May 2006 22:45:31 -0000 1.3 @@ -26,20 +26,22 @@ import org.jboss.portal.wsrp.core.WSRP_v1_PortletManagement_PortType; import org.jboss.portal.wsrp.core.WSRP_v1_Registration_PortType; import org.jboss.portal.wsrp.core.WSRP_v1_ServiceDescription_PortType; -import org.jboss.portal.wsrp.ServiceFactoryImpl; + +import java.util.Properties; /** * @author <a href="mailto:chr...@jb...">Chris Laprun</a> - * @version $Revision: 1.2 $ + * @version $Revision: 1.3 $ * @since 2.4 */ public class RMIInvokerServiceFactory extends ServiceFactoryImpl { - protected void initPortTypeClassToJDNINameMap() + public RMIInvokerServiceFactory() { - portTypeClassToJNDIName.put(WSRP_v1_ServiceDescription_PortType.class.getName(), "wsrp/invoker/ServiceDescriptionService"); - portTypeClassToJNDIName.put(WSRP_v1_Markup_PortType.class.getName(), "wsrp/invoker/MarkupService"); - portTypeClassToJNDIName.put(WSRP_v1_Registration_PortType.class.getName(), "wsrp/invoker/RegistrationService"); - portTypeClassToJNDIName.put(WSRP_v1_PortletManagement_PortType.class.getName(), "wsrp/invoker/PortletManagementService"); + portJNDIMapping = new Properties(); + portJNDIMapping.put(WSRP_v1_ServiceDescription_PortType.class.getName(), "wsrp/invoker/ServiceDescriptionService"); + portJNDIMapping.put(WSRP_v1_Markup_PortType.class.getName(), "wsrp/invoker/MarkupService"); + portJNDIMapping.put(WSRP_v1_Registration_PortType.class.getName(), "wsrp/invoker/RegistrationService"); + portJNDIMapping.put(WSRP_v1_PortletManagement_PortType.class.getName(), "wsrp/invoker/PortletManagementService"); } } 1.6 +28 -128 jboss-portal/wsrp/src/main/org/jboss/portal/wsrp/RemoteSOAPInvokerServiceFactory.java (In the diff below, changes in quantity of whitespace are not shown.) Index: RemoteSOAPInvokerServiceFactory.java =================================================================== RCS file: /cvsroot/jboss/jboss-portal/wsrp/src/main/org/jboss/portal/wsrp/RemoteSOAPInvokerServiceFactory.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -b -r1.5 -r1.6 --- RemoteSOAPInvokerServiceFactory.java 6 May 2006 07:42:59 -0000 1.5 +++ RemoteSOAPInvokerServiceFactory.java 10 May 2006 22:45:31 -0000 1.6 @@ -23,11 +23,6 @@ package org.jboss.portal.wsrp; import org.jboss.logging.Logger; -import org.jboss.portal.common.system.AbstractJBossService; -import org.jboss.portal.wsrp.core.WSRP_v1_Markup_PortType; -import org.jboss.portal.wsrp.core.WSRP_v1_PortletManagement_PortType; -import org.jboss.portal.wsrp.core.WSRP_v1_Registration_PortType; -import org.jboss.portal.wsrp.core.WSRP_v1_ServiceDescription_PortType; import org.xml.sax.InputSource; import javax.wsdl.Definition; @@ -38,80 +33,35 @@ import javax.wsdl.factory.WSDLFactory; import javax.wsdl.xml.WSDLLocator; import javax.xml.namespace.QName; -import javax.xml.rpc.Service; import javax.xml.rpc.ServiceException; import java.io.IOException; import java.io.InputStream; import java.net.MalformedURLException; import java.net.URL; import java.util.Collection; -import java.util.HashMap; import java.util.Iterator; -import java.util.Map; /** * @author <a href="mailto:chr...@jb...">Chris Laprun</a> - * @version $Revision: 1.5 $ + * @version $Revision: 1.6 $ * @since 2.4 (May 3, 2006) */ -public class RemoteSOAPInvokerServiceFactory extends AbstractJBossService implements ServiceFactory +public class RemoteSOAPInvokerServiceFactory extends PerEndpointSOAPInvokerServiceFactory { private final Logger log = Logger.getLogger(getClass()); - private WSRP_v1_ServiceDescription_PortType serviceDescriptionService; - private WSRP_v1_Markup_PortType markupService; - private WSRP_v1_PortletManagement_PortType portletManagementService; - private WSRP_v1_Registration_PortType registrationService; private String wsdlDefinitionURL; private static final String WSRP_URN = "urn:oasis:names:tc:wsrp:v1:wsdl"; private static final String DEFAULT_SERVICE_NAME = "WSRPService"; - /** Used to heuristically determine which interface to use for a port based on its name */ - private static final Map SERVICE_NAME_TO_INTERFACE = new HashMap(4); + // Used to heuristically determine which interface to use for a port based on its name private static final String DESCRIPTION = "description"; private static final String MARKUP = "markup"; + private static final String BASE = "base"; // some WSDL use WSRPBaseService instead of Markup private static final String MANAGEMENT = "management"; private static final String REGISTRATION = "registration"; - static - { - SERVICE_NAME_TO_INTERFACE.put(DESCRIPTION, WSRP_v1_ServiceDescription_PortType.class); - SERVICE_NAME_TO_INTERFACE.put(MARKUP, WSRP_v1_Markup_PortType.class); - SERVICE_NAME_TO_INTERFACE.put(MANAGEMENT, WSRP_v1_PortletManagement_PortType.class); - SERVICE_NAME_TO_INTERFACE.put(REGISTRATION, WSRP_v1_Registration_PortType.class); - } - - public Object getService(Class clazz) throws Exception - { - if (WSRP_v1_Markup_PortType.class.equals(clazz)) - { - return markupService; - } - if (WSRP_v1_ServiceDescription_PortType.class.equals(clazz)) - { - return serviceDescriptionService; - } - if (WSRP_v1_PortletManagement_PortType.class.equals(clazz)) - { - return portletManagementService; - } - if (WSRP_v1_Registration_PortType.class.equals(clazz)) - { - return registrationService; - } - throw new IllegalArgumentException("Unknown service interface type: " + clazz); - } - - protected void startService() - { -// initServices(wsdlDefinitionURL); - } - - public void test() - { - initServices(wsdlDefinitionURL); - } public String getWsdlDefinitionURL() { @@ -120,23 +70,20 @@ public void setWsdlDefinitionURL(String wsdlDefinitionURL) { - this.wsdlDefinitionURL = wsdlDefinitionURL; - } - - private void initServices(String serviceURL) - { - if (serviceURL == null || serviceURL.length() == 0) + if (wsdlDefinitionURL == null || wsdlDefinitionURL.length() == 0) { throw new IllegalArgumentException("Require a non-empty, non-null URL specifying where to find the WSRP " + "services definition"); } + this.wsdlDefinitionURL = wsdlDefinitionURL; + initServices(); + } + private void initServices() + { try { - URL wsdlURL = new URL(serviceURL); - - // Create an instance of service factory - javax.xml.rpc.ServiceFactory serviceFactory = javax.xml.rpc.ServiceFactory.newInstance(); + URL wsdlURL = new URL(wsdlDefinitionURL); Definition def = getWSDLDefinition(wsdlURL); javax.wsdl.Service serve = def.getService(new QName(WSRP_URN, DEFAULT_SERVICE_NAME)); @@ -144,16 +91,8 @@ for (Iterator iterator = ports.iterator(); iterator.hasNext();) { Port port = (Port)iterator.next(); - System.out.println("port = " + port); + initServiceURL(port.getName(), getLocation(port)); } - - // Create a service object to act as a factory for proxies. - Service service = serviceFactory.createService(new QName(WSRP_URN, DEFAULT_SERVICE_NAME)); - - serviceDescriptionService = (WSRP_v1_ServiceDescription_PortType)service.getPort(WSRP_v1_ServiceDescription_PortType.class); - markupService = (WSRP_v1_Markup_PortType)service.getPort(WSRP_v1_Markup_PortType.class); - portletManagementService = (WSRP_v1_PortletManagement_PortType)service.getPort(WSRP_v1_PortletManagement_PortType.class); - registrationService = (WSRP_v1_Registration_PortType)service.getPort(WSRP_v1_Registration_PortType.class); } catch (MalformedURLException e) { @@ -162,10 +101,6 @@ iae.initCause(e); throw iae; } - catch (ServiceException e) - { - log.info("Service Exception", e); - } catch (WSDLException e) { log.info("WSDL Exception", e); @@ -179,55 +114,35 @@ * @param portName * @throws ServiceException */ - private void initService(Service service, QName portName) throws ServiceException - { - String localPart = portName.getLocalPart().toLowerCase(); - Class serviceInterface = null; - String key = null; - for (Iterator entries = SERVICE_NAME_TO_INTERFACE.entrySet().iterator(); entries.hasNext();) - { - Map.Entry entry = (Map.Entry)entries.next(); - key = (String)entry.getKey(); - - // we're assuming that if the local part of the port name contains the discrimator key, we have a match... - if (doesString1ContainString2(localPart, key)) + private void initServiceURL(String portName, String serviceURL) { - serviceInterface = (Class)entry.getValue(); - break; // exit - } - } + String normalizedPortName = portName.toLowerCase(); - if (serviceInterface == null) + if (doesString1ContainString2(normalizedPortName, DESCRIPTION)) { - // fix-me: use better exception so that this could bubble up and be handled in management GUI - throw new ServiceException("Could perform automatic service initialization: we couldn't match port name: " - + portName + " to one of the known WSRP interfaces."); - } - - if (DESCRIPTION.equals(key)) - { - log.info("Found service description port from port name: " + key); - serviceDescriptionService = (WSRP_v1_ServiceDescription_PortType)service.getPort(portName, serviceInterface); + log.info("Found service description port from port name: " + normalizedPortName); + serviceDescriptionURL = serviceURL; return; } - if (MARKUP.equals(key)) + if (doesString1ContainString2(normalizedPortName, MARKUP) || doesString1ContainString2(normalizedPortName, BASE)) { - log.info("Found markup port from port name: " + key); - markupService = (WSRP_v1_Markup_PortType)service.getPort(portName, serviceInterface); + log.info("Found markup port from port name: " + normalizedPortName); + markupURL = serviceURL; return; } - if (MANAGEMENT.equals(key)) + if (doesString1ContainString2(normalizedPortName, MANAGEMENT)) { - log.info("Found porlet management port from port name: " + key); - portletManagementService = (WSRP_v1_PortletManagement_PortType)service.getPort(portName, serviceInterface); + log.info("Found porlet management port from port name: " + normalizedPortName); + portletManagementURL = serviceURL; return; } - if (REGISTRATION.equals(key)) + if (doesString1ContainString2(normalizedPortName, REGISTRATION)) { - log.info("Found registration port from port name: " + key); - registrationService = (WSRP_v1_Registration_PortType)service.getPort(portName, serviceInterface); + log.info("Found registration port from port name: " + normalizedPortName); + registrationURL = serviceURL; + return; } - throw new ServiceException("Could not find service port matching port name: " + key); + log.warn("Could not find service port matching port name: " + normalizedPortName); } private boolean doesString1ContainString2(String string1, String string2) @@ -235,21 +150,6 @@ return string1.indexOf(string2) > 0; } - public void testEndpointGrab() throws Exception - { - String wsdlURL = "http://localhost:8080/wsrp/MarkupService?wsdl"; - Definition def = getWSDLDefinition(new URL(wsdlURL)); - javax.wsdl.Service serve = def.getService(new QName(WSRP_URN, DEFAULT_SERVICE_NAME)); - Collection ports = serve.getPorts().values(); - /*for (Iterator entries = ports.entrySet().iterator(); entries.hasNext();) - { - Map.Entry entry = (Map.Entry)entries.next(); - String portName - - }*/ - Port markupPort = serve.getPort("WSRPMarkupService"); - } - //Requires wsdl4j private Definition getWSDLDefinition(URL url) throws WSDLException { 1.5 +1 -14 jboss-portal/wsrp/src/main/org/jboss/portal/wsrp/SOAPInvokerServiceFactory.java (In the diff below, changes in quantity of whitespace are not shown.) Index: SOAPInvokerServiceFactory.java =================================================================== RCS file: /cvsroot/jboss/jboss-portal/wsrp/src/main/org/jboss/portal/wsrp/SOAPInvokerServiceFactory.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -b -r1.4 -r1.5 --- SOAPInvokerServiceFactory.java 6 May 2006 15:43:32 -0000 1.4 +++ SOAPInvokerServiceFactory.java 10 May 2006 22:45:31 -0000 1.5 @@ -32,14 +32,13 @@ import java.util.HashMap; import java.util.Map; import java.util.Properties; -import java.util.Iterator; /** * todo : cache created configured proxies * * @author <a href="mailto:chr...@jb...">Chris Laprun</a> * @author <a href="mailto:ju...@jb...">Julien Viet</a> - * @version $Revision: 1.4 $ + * @version $Revision: 1.5 $ * @since 2.4 */ public class SOAPInvokerServiceFactory extends ServiceFactoryImpl @@ -85,18 +84,6 @@ this.portJNDIMapping = portJNDIMapping; } - protected void initPortTypeClassToJDNINameMap() - { - for (Iterator i = portJNDIMapping.entrySet().iterator(); i.hasNext();) - { - Map.Entry entry = (Map.Entry)i.next(); - String portTypeClassName = (String)entry.getKey(); - String portTypeJNDIName = (String)entry.getValue(); - portTypeClassToJNDIName.put(portTypeClassName, portTypeJNDIName); - log.debug("Use jndi name " + portTypeJNDIName + " for port of type " + portTypeClassName); - } - } - public Object getService(Class clazz) throws Exception { // If retrieve object is of javax.xml.rpc.Service class, we're using the WS stack and we need to get the port 1.3 +7 -1 jboss-portal/wsrp/src/main/org/jboss/portal/wsrp/ServiceFactory.java (In the diff below, changes in quantity of whitespace are not shown.) Index: ServiceFactory.java =================================================================== RCS file: /cvsroot/jboss/jboss-portal/wsrp/src/main/org/jboss/portal/wsrp/ServiceFactory.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -b -r1.2 -r1.3 --- ServiceFactory.java 3 May 2006 22:04:20 -0000 1.2 +++ ServiceFactory.java 10 May 2006 22:45:31 -0000 1.3 @@ -23,13 +23,19 @@ import org.jboss.system.Service; +import java.util.Properties; + /** * A factory that gives access to remote services. * * @author <a href="mailto:ju...@jb...">Julien Viet</a> - * @version $Revision: 1.2 $ + * @version $Revision: 1.3 $ */ public interface ServiceFactory extends Service { Object getService(Class clazz) throws Exception; + + Properties getPortJNDIMapping(); + + void setPortJNDIMapping(Properties portJNDIMapping); } 1.7 +13 -10 jboss-portal/wsrp/src/main/org/jboss/portal/wsrp/ServiceFactoryImpl.java (In the diff below, changes in quantity of whitespace are not shown.) Index: ServiceFactoryImpl.java =================================================================== RCS file: /cvsroot/jboss/jboss-portal/wsrp/src/main/org/jboss/portal/wsrp/ServiceFactoryImpl.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -b -r1.6 -r1.7 --- ServiceFactoryImpl.java 6 May 2006 17:16:21 -0000 1.6 +++ ServiceFactoryImpl.java 10 May 2006 22:45:31 -0000 1.7 @@ -34,7 +34,7 @@ /** * @author <a href="mailto:ju...@jb...">Julien Viet</a> * @author <a href="mailto:chr...@jb...">Chris Laprun</a> - * @version $Revision: 1.6 $ + * @version $Revision: 1.7 $ * @noinspection ALL * @since 2.4 */ @@ -47,11 +47,12 @@ /** . */ private Properties env; - /** A Map recording the mapping between WSRP port type and JDNI name of the implementing service. */ - protected final Map portTypeClassToJNDIName = new HashMap(4); - + /** A Map caching the already looked up services to avoid subsequent JNDI lookups once the service has been resolved. */ private final Map services = new HashMap(4); + /** A Map recording the mapping between WSRP port type class name and JDNI name of the implementing service. */ + protected Properties portJNDIMapping; + public Properties getEnv() { return env; @@ -89,8 +90,8 @@ // String className = clazz.getName(); - String jndiName = (String)portTypeClassToJNDIName.get(className); - log.debug("Looking up service for class " + clazz.getName() + " using JNDI name " + jndiName); + String jndiName = (String)portJNDIMapping.get(className); + log.debug("Looking up service for class " + className + " using JNDI name " + jndiName); if (jndiName == null) { throw new IllegalArgumentException("No such service " + clazz); @@ -131,11 +132,13 @@ } } - protected void startService() throws Exception + public Properties getPortJNDIMapping() { - initPortTypeClassToJDNINameMap(); + return portJNDIMapping; } - /** Initializes the mappings. */ - protected abstract void initPortTypeClassToJDNINameMap(); + public void setPortJNDIMapping(Properties portJNDIMapping) + { + this.portJNDIMapping = portJNDIMapping; + } } |