geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject svn commit: r505174 - in /geronimo/server/trunk/modules: geronimo-cxf/src/main/java/org/apache/geronimo/cxf/client/ geronimo-jaxws-builder/src/main/java/org/apache/geronimo/jaxws/builder/ geronimo-jaxws/src/main/java/org/apache/geronimo/jaxws/ geronimo...
Date Fri, 09 Feb 2007 04:29:52 GMT
Author: dims
Date: Thu Feb  8 20:29:51 2007
New Revision: 505174

URL: http://svn.apache.org/viewvc?view=rev&rev=505174
Log:
Fix for GERONIMO-2807 - CXF: initial service-ref support

Added:
    geronimo/server/trunk/modules/geronimo-cxf/src/main/java/org/apache/geronimo/cxf/client/
    geronimo/server/trunk/modules/geronimo-cxf/src/main/java/org/apache/geronimo/cxf/client/CXFServiceReference.java
    geronimo/server/trunk/modules/geronimo-cxf/src/main/java/org/apache/geronimo/cxf/client/PortMethodFilter.java
    geronimo/server/trunk/modules/geronimo-cxf/src/main/java/org/apache/geronimo/cxf/client/PortMethodInterceptor.java
    geronimo/server/trunk/modules/geronimo-jaxws-builder/src/main/java/org/apache/geronimo/jaxws/builder/EndpointInfoBuilder.java
    geronimo/server/trunk/modules/geronimo-jaxws/src/main/java/org/apache/geronimo/jaxws/JAXWSUtils.java
    geronimo/server/trunk/modules/geronimo-jaxws/src/main/java/org/apache/geronimo/jaxws/client/
    geronimo/server/trunk/modules/geronimo-jaxws/src/main/java/org/apache/geronimo/jaxws/client/EndpointInfo.java
    geronimo/server/trunk/modules/geronimo-jaxws/src/main/java/org/apache/geronimo/jaxws/client/GenericService.java

Added: geronimo/server/trunk/modules/geronimo-cxf/src/main/java/org/apache/geronimo/cxf/client/CXFServiceReference.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-cxf/src/main/java/org/apache/geronimo/cxf/client/CXFServiceReference.java?view=auto&rev=505174
==============================================================================
--- geronimo/server/trunk/modules/geronimo-cxf/src/main/java/org/apache/geronimo/cxf/client/CXFServiceReference.java
(added)
+++ geronimo/server/trunk/modules/geronimo-cxf/src/main/java/org/apache/geronimo/cxf/client/CXFServiceReference.java
Thu Feb  8 20:29:51 2007
@@ -0,0 +1,210 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.geronimo.cxf.client;
+
+import java.lang.reflect.InvocationTargetException;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URL;
+import java.util.Map;
+
+import javax.naming.NamingException;
+import javax.xml.bind.JAXBException;
+import javax.xml.namespace.QName;
+import javax.xml.ws.Service;
+
+import net.sf.cglib.proxy.Callback;
+import net.sf.cglib.proxy.Enhancer;
+import net.sf.cglib.proxy.MethodInterceptor;
+import net.sf.cglib.proxy.NoOp;
+import net.sf.cglib.reflect.FastClass;
+import net.sf.cglib.reflect.FastConstructor;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.cxf.jaxws.context.WebServiceContextImpl;
+import org.apache.cxf.jaxws.javaee.HandlerChainsType;
+import org.apache.geronimo.cxf.CXFHandlerResolver;
+import org.apache.geronimo.gbean.AbstractName;
+import org.apache.geronimo.jaxws.HandlerChainsUtils;
+import org.apache.geronimo.jaxws.JAXWSAnnotationProcessor;
+import org.apache.geronimo.jaxws.JNDIResolver;
+import org.apache.geronimo.jaxws.client.EndpointInfo;
+import org.apache.geronimo.jaxws.client.GenericService;
+import org.apache.geronimo.kernel.Kernel;
+import org.apache.geronimo.naming.reference.ClassLoaderAwareReference;
+import org.apache.geronimo.naming.reference.KernelAwareReference;
+import org.apache.geronimo.naming.reference.SimpleReference;
+
+public class CXFServiceReference extends SimpleReference implements
+        ClassLoaderAwareReference, KernelAwareReference {
+
+    private static final Log LOG = LogFactory.getLog(CXFServiceReference.class);
+
+    private static final Class[] URL_SERVICE_NAME_CONSTRUCTOR = 
+        new Class[] { URL.class, QName.class };
+    
+    private String serviceClassName;
+
+    private ClassLoader classLoader;
+
+    private AbstractName moduleName;
+
+    private URI wsdlURI;
+
+    private QName serviceQName;
+
+    private Kernel kernel;
+
+    private String handlerChainsXML;
+
+    private Map<Object, EndpointInfo> seiInfoMap;
+
+    private String referenceClassName;
+
+    public CXFServiceReference(String serviceClassName,
+                               String referenceClassName,
+                               URI wsdlURI,
+                               QName serviceQName,
+                               AbstractName name,
+                               String handlerChainsXML,
+                               Map<Object, EndpointInfo> seiInfoMap) {
+        this.serviceClassName = serviceClassName;
+        this.referenceClassName = referenceClassName;
+        this.wsdlURI = wsdlURI;
+        this.serviceQName = serviceQName;
+        this.moduleName = name;
+        this.handlerChainsXML = handlerChainsXML;
+        this.seiInfoMap = seiInfoMap;
+    }
+   
+    private HandlerChainsType getHandlerChains() {
+        try {
+            return HandlerChainsUtils.toHandlerChains(this.handlerChainsXML, HandlerChainsType.class);
+        } catch (JAXBException e) {          
+            // this should not happen
+            LOG.warn("Failed to deserialize handler chains", e);
+            return null;
+        }
+    }
+ 
+    public void setClassLoader(ClassLoader classLoader) {
+        this.classLoader = classLoader;
+    }
+
+    public void setKernel(Kernel kernel) {
+        this.kernel = kernel;
+    }
+
+    private Class loadClass(String name) throws NamingException {
+        try {
+            return this.classLoader.loadClass(name);
+        } catch (ClassNotFoundException e) {
+            NamingException exception = new NamingException(
+                    "Count not load class " + name);
+            exception.initCause(e);
+            throw exception;
+        }
+    }
+
+    private URL getWsdlURL() {
+        if (this.wsdlURI == null) {
+            return null;
+        }
+        try {
+            return new URL(this.wsdlURI.toString());
+        } catch (MalformedURLException e1) {
+            // not a URL, assume it's a local reference
+            try {
+                URL moduleBaseUrl = (URL) this.kernel.getAttribute(
+                        this.moduleName, "configurationBaseUrl");
+                return new URL(moduleBaseUrl.toString() + this.wsdlURI.toString());
+            } catch (Exception e) {
+                // this should not happen
+                LOG.warn("Error constructing WSDL location", e);
+                return null;
+            }
+        }
+    }
+    
+    private Class getReferenceClass() throws NamingException {
+        return (this.referenceClassName != null) ? loadClass(this.referenceClassName) : null;
+    }
+
+    public Object getContent() throws NamingException {
+        Service instance = null;
+        URL wsdlURL = getWsdlURL();
+        Class serviceClass = loadClass(this.serviceClassName);
+                
+        if (Service.class.equals(serviceClass)) {
+            serviceClass = GenericService.class;
+        }
+        
+        instance = createServiceProxy(serviceClass, this.classLoader, this.serviceQName,
wsdlURL);
+        
+        HandlerChainsType handlerChains = getHandlerChains();
+        if (handlerChains != null) {
+            JAXWSAnnotationProcessor annotationProcessor = 
+                new JAXWSAnnotationProcessor(new JNDIResolver(), new WebServiceContextImpl());
+            CXFHandlerResolver handlerResolver =
+                new CXFHandlerResolver(this.classLoader, serviceClass, handlerChains, annotationProcessor);
+            instance.setHandlerResolver(handlerResolver);
+        }
+        
+        Class referenceClass = getReferenceClass();
+        if (referenceClass != null && !Service.class.isAssignableFrom(referenceClass))
{
+            // do port lookup
+            return instance.getPort(referenceClass);
+        } else {
+            // return service
+            return instance;
+        }
+    }
+    
+    private Service createServiceProxy(Class superClass, ClassLoader classLoader, QName serviceName,
URL wsdlLocation) throws NamingException {
+        Callback callback = new PortMethodInterceptor(this.seiInfoMap);
+        Callback[] methodInterceptors = new Callback[]{NoOp.INSTANCE, callback};
+
+        Enhancer enhancer = new Enhancer();
+        enhancer.setClassLoader(classLoader);
+        enhancer.setSuperclass(superClass);
+        enhancer.setCallbackFilter(new PortMethodFilter());
+        enhancer.setCallbackTypes(new Class[]{NoOp.class, MethodInterceptor.class});    
   
+        enhancer.setUseFactory(false);
+        enhancer.setUseCache(false);        
+        Class serviceClass = enhancer.createClass();
+
+        Enhancer.registerCallbacks(serviceClass, methodInterceptors);
+        
+        FastConstructor constructor = 
+            FastClass.create(serviceClass).getConstructor(URL_SERVICE_NAME_CONSTRUCTOR);
+        Object[] arguments = 
+            new Object[]{wsdlLocation, serviceName};
+        
+        LOG.debug("Initializing service with: " + wsdlLocation + " " + serviceName);
+        
+        try {
+            return (Service)constructor.newInstance(arguments);
+        } catch (InvocationTargetException e) {
+            NamingException exception = new NamingException("Could not construct service
proxy");
+            exception.initCause(e.getTargetException());
+            throw exception;
+        }
+    }
+
+}

Added: geronimo/server/trunk/modules/geronimo-cxf/src/main/java/org/apache/geronimo/cxf/client/PortMethodFilter.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-cxf/src/main/java/org/apache/geronimo/cxf/client/PortMethodFilter.java?view=auto&rev=505174
==============================================================================
--- geronimo/server/trunk/modules/geronimo-cxf/src/main/java/org/apache/geronimo/cxf/client/PortMethodFilter.java
(added)
+++ geronimo/server/trunk/modules/geronimo-cxf/src/main/java/org/apache/geronimo/cxf/client/PortMethodFilter.java
Thu Feb  8 20:29:51 2007
@@ -0,0 +1,33 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.geronimo.cxf.client;
+
+import java.lang.reflect.Method;
+
+import net.sf.cglib.proxy.CallbackFilter;
+
+public class PortMethodFilter implements CallbackFilter {
+
+    public int accept(Method method) {
+        if (method.getName().equals("getPort")) {
+            return 1; // use second method interceptor
+        } else {
+            return 0; // use first method interceptor
+        }
+    }
+
+}

Added: geronimo/server/trunk/modules/geronimo-cxf/src/main/java/org/apache/geronimo/cxf/client/PortMethodInterceptor.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-cxf/src/main/java/org/apache/geronimo/cxf/client/PortMethodInterceptor.java?view=auto&rev=505174
==============================================================================
--- geronimo/server/trunk/modules/geronimo-cxf/src/main/java/org/apache/geronimo/cxf/client/PortMethodInterceptor.java
(added)
+++ geronimo/server/trunk/modules/geronimo-cxf/src/main/java/org/apache/geronimo/cxf/client/PortMethodInterceptor.java
Thu Feb  8 20:29:51 2007
@@ -0,0 +1,127 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.geronimo.cxf.client;
+
+import java.lang.reflect.Method;
+import java.net.URL;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+import javax.security.auth.Subject;
+import javax.xml.namespace.QName;
+import javax.xml.ws.BindingProvider;
+
+import net.sf.cglib.proxy.MethodInterceptor;
+import net.sf.cglib.proxy.MethodProxy;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.geronimo.jaxws.JAXWSUtils;
+import org.apache.geronimo.jaxws.client.EndpointInfo;
+import org.apache.geronimo.security.ContextManager;
+import org.apache.geronimo.security.jaas.NamedUsernamePasswordCredential;
+
+public class PortMethodInterceptor implements MethodInterceptor {
+
+    private static final Log LOG = LogFactory.getLog(PortMethodInterceptor.class);
+    
+    private Map<Object, EndpointInfo> seiInfoMap;
+
+    public PortMethodInterceptor(Map<Object, EndpointInfo> seiInfoMap) {
+        this.seiInfoMap = seiInfoMap;
+    }
+
+    public Object intercept(Object target, Method method, Object[] arguments, MethodProxy
methodProxy) throws Throwable {
+        Object proxy = methodProxy.invokeSuper(target, arguments);       
+        
+        if (method.getName().equals("getPort")) {            
+            if (arguments.length == 1) {
+                // getPort(Class) called - use SEI annotation
+                setProperties((BindingProvider)proxy, JAXWSUtils.getPortType((Class)arguments[0]));
+            } else if (arguments.length == 2) {
+                // getPort(QName, Class) called
+                if (arguments[0] == null) {
+                    // port qname not specified - use SEI annotation
+                    setProperties((BindingProvider)proxy, JAXWSUtils.getPortType((Class)arguments[1]));
+                } else {
+                    // port qname specified
+                    setProperties((BindingProvider)proxy, ((QName)arguments[0]).getLocalPart());
+                }
+            }
+        }
+                
+        return proxy;
+    }
+    
+    private void setProperties(BindingProvider proxy, QName portType) {
+        if (portType == null) {
+            return;
+        }
+        EndpointInfo info = this.seiInfoMap.get(portType);
+        setProperties(proxy, info);        
+    }
+    
+    private void setProperties(BindingProvider proxy, String portName) {
+        if (portName == null) {
+            return;
+        }
+        EndpointInfo info = this.seiInfoMap.get(portName);
+        setProperties(proxy, info);
+    }
+    
+    private void setProperties(BindingProvider proxy, EndpointInfo info) {
+        if (info == null) {
+            return;
+        }       
+        
+        // set address
+        URL location = info.getLocation();
+        if (location != null) {
+            proxy.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, location.toString());
+            LOG.debug("Set address property: " + location);
+        }
+        
+        // set credentials
+        String credentialsName = info.getCredentialsName();
+        if (credentialsName != null) {
+            Subject subject = ContextManager.getNextCaller();
+            if (subject == null) {
+                throw new IllegalStateException("Subject missing but authentication turned
on");
+            } else {
+                Set creds = subject.getPrivateCredentials(NamedUsernamePasswordCredential.class);
+                boolean found = false;
+                
+                for (Iterator iterator = creds.iterator(); iterator.hasNext();) {
+                    NamedUsernamePasswordCredential namedUsernamePasswordCredential = (NamedUsernamePasswordCredential)
iterator.next();
+                    if (credentialsName.equals(namedUsernamePasswordCredential.getName()))
{
+                        proxy.getRequestContext().put(BindingProvider.USERNAME_PROPERTY,

+                                                      namedUsernamePasswordCredential.getUsername());
+                        proxy.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY,

+                                                      new String(namedUsernamePasswordCredential.getPassword()));
+                        LOG.debug("Set username/password property: " + credentialsName);
+                        found = true;
+                        break;
+                    }
+                }
+                if (!found) {
+                    throw new IllegalStateException("no NamedUsernamePasswordCredential found
for name " + credentialsName);
+                }
+            }
+        }
+    }
+}

Added: geronimo/server/trunk/modules/geronimo-jaxws-builder/src/main/java/org/apache/geronimo/jaxws/builder/EndpointInfoBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-jaxws-builder/src/main/java/org/apache/geronimo/jaxws/builder/EndpointInfoBuilder.java?view=auto&rev=505174
==============================================================================
--- geronimo/server/trunk/modules/geronimo-jaxws-builder/src/main/java/org/apache/geronimo/jaxws/builder/EndpointInfoBuilder.java
(added)
+++ geronimo/server/trunk/modules/geronimo-jaxws-builder/src/main/java/org/apache/geronimo/jaxws/builder/EndpointInfoBuilder.java
Thu Feb  8 20:29:51 2007
@@ -0,0 +1,383 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.geronimo.jaxws.builder;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.jar.JarFile;
+import java.util.zip.ZipEntry;
+
+import javax.wsdl.Binding;
+import javax.wsdl.Definition;
+import javax.wsdl.Port;
+import javax.wsdl.PortType;
+import javax.wsdl.Service;
+import javax.wsdl.WSDLException;
+import javax.wsdl.extensions.ExtensibilityElement;
+import javax.wsdl.extensions.soap.SOAPAddress;
+import javax.wsdl.factory.WSDLFactory;
+import javax.wsdl.xml.WSDLLocator;
+import javax.wsdl.xml.WSDLReader;
+import javax.xml.namespace.QName;
+import javax.xml.ws.WebServiceClient;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.geronimo.common.DeploymentException;
+import org.apache.geronimo.jaxws.JAXWSUtils;
+import org.apache.geronimo.jaxws.client.EndpointInfo;
+import org.apache.geronimo.xbeans.geronimo.naming.GerPortType;
+import org.apache.geronimo.xbeans.geronimo.naming.GerServiceRefType;
+import org.xml.sax.InputSource;
+
+public class EndpointInfoBuilder {
+
+    private static final Log LOG = LogFactory.getLog(EndpointInfoBuilder.class);
+
+    private JarFile moduleFile;
+
+    private URI wsdlURI;
+
+    private QName serviceQName;
+
+    private Class serviceClass;
+
+    private GerServiceRefType serviceRefType;
+
+    private Map<Object, EndpointInfo> portInfoMap = new HashMap<Object, EndpointInfo>();
+
+    private Map<Class, String> portComponentRefMap;
+
+    public EndpointInfoBuilder(Class serviceClass,
+                               GerServiceRefType serviceRefType,
+                               Map<Class, String> portComponentRefMap,
+                               JarFile moduleFile,
+                               URI wsdlURI,
+                               QName serviceQName) {
+        this.serviceClass = serviceClass;
+        this.serviceRefType = serviceRefType;
+        this.portComponentRefMap = portComponentRefMap;
+        this.moduleFile = moduleFile;
+        this.wsdlURI = wsdlURI;
+        this.serviceQName = serviceQName;
+    }
+
+    public URI getWsdlURI() {
+        return this.wsdlURI;
+    }
+    
+    public QName getServiceQName() {
+        return this.serviceQName;
+    }
+
+    public Map<Object, EndpointInfo> getEndpointInfo() {
+        return this.portInfoMap;
+    }
+    
+    public void build() throws DeploymentException {
+        if (this.wsdlURI == null) {
+            // wsdl explitely not specified, try to get it from 
+            // the service class annotation
+            WebServiceClient webServiceClient = 
+                (WebServiceClient) this.serviceClass.getAnnotation(WebServiceClient.class);
+            if (webServiceClient != null) {
+                this.wsdlURI = getWSDLLocation(webServiceClient);               
+                this.serviceQName = getServiceQName(webServiceClient);
+            }
+           
+            if (this.wsdlURI == null) {                
+                return;
+            }
+        }
+        
+        JarWSDLLocator wsdlLocator = null;
+        URL wsdlURL = null;
+        try {
+            wsdlURL = new URL(this.wsdlURI.toString());
+        } catch (MalformedURLException e1) {
+            // not a URL, assume it's a local reference
+            wsdlLocator = new JarWSDLLocator(this.wsdlURI);
+        }
+
+        Definition definition;
+        WSDLFactory wsdlFactory;
+        try {
+            wsdlFactory = WSDLFactory.newInstance();
+        } catch (WSDLException e) {
+            throw new DeploymentException("Could not create WSDLFactory", e);
+        }
+        WSDLReader wsdlReader = wsdlFactory.newWSDLReader();
+        wsdlReader.setFeature("javax.wsdl.importDocuments", false);
+        try {
+            if (wsdlURL != null) {
+                definition = wsdlReader.readWSDL(wsdlURL.toString());
+            } else if (wsdlLocator != null) {
+                definition = wsdlReader.readWSDL(wsdlLocator);
+            } else {
+                throw new DeploymentException("unknown");
+            }
+        } catch (WSDLException e) {
+            throw new DeploymentException("Failed to read wsdl document", e);
+        } catch (RuntimeException e) {
+            throw new DeploymentException(e.getMessage(), e);
+        }
+
+        verifyPortComponentList(definition);
+        
+        Map services = definition.getServices();
+        if (services.size() == 0) {
+            // partial wsdl, return as is
+
+            if (this.serviceRefType != null && this.serviceRefType.isSetServiceCompletion())
{
+                LOG.warn("Service completion is not supported with partial wsdl");
+            }
+        } else {
+            // full wsdl
+
+            if (this.serviceRefType != null && this.serviceRefType.isSetServiceCompletion())
{
+                throw new DeploymentException("Full wsdl, but service completion supplied");
+            }
+            
+            Service service = null;
+            if (this.serviceQName != null) {
+                service = definition.getService(this.serviceQName);
+                if (service == null) {
+                    throw new DeploymentException(
+                            "No service wsdl for supplied service qname "
+                                    + this.serviceQName);
+                }
+            } else if (services.size() == 1) {
+                service = (Service) services.values().iterator().next();
+                this.serviceQName = service.getQName();
+            } else {
+                throw new DeploymentException(
+                        "No service qname supplied, and there are "
+                                + services.size() + " services");
+            }
+
+            // organize the extra port info
+            Map<String, GerPortType> portMap = new HashMap<String, GerPortType>();
+            if (serviceRefType != null) {
+                GerPortType[] ports = serviceRefType.getPortArray();
+                for (int i = 0; i < ports.length; i++) {
+                    GerPortType port = ports[i];
+                    String portName = port.getPortName().trim();
+                    portMap.put(portName, port);
+                }
+            }
+
+            Map wsdlPortMap = service.getPorts();
+            for (Iterator iterator = wsdlPortMap.entrySet().iterator(); iterator.hasNext();)
{
+                Map.Entry entry = (Map.Entry) iterator.next();
+                String portName = (String) entry.getKey();
+                Port port = (Port) entry.getValue();
+
+                GerPortType gerPort = portMap.get(portName);
+
+                URL location = (gerPort == null) ? getAddressLocation(port) : getLocation(gerPort);
+                // skip non-soap ports
+                if (location == null) {
+                    continue;
+                }
+                String credentialsName = (gerPort == null) ? null : getCredentialsName(gerPort);
+                
+                Binding binding = port.getBinding();
+                if (binding == null) {
+                    throw new DeploymentException("No binding for port: " + portName);
+                }
+                
+                PortType portType = binding.getPortType();
+                if (portType == null) {
+                    throw new DeploymentException("No portType for binding: " + binding.getQName());
+                }
+
+                EndpointInfo info = new EndpointInfo(location, credentialsName);
+                this.portInfoMap.put(portName, info);
+                // prefer first binding listed in wsdl
+                if (!this.portInfoMap.containsKey(portType.getQName())) {
+                    this.portInfoMap.put(portType.getQName(), info);
+                }
+            }
+        }
+    }
+
+    private QName getServiceQName(WebServiceClient webServiceClient) {
+        if (webServiceClient.targetNamespace() != null && webServiceClient.name()
!= null) {
+            return new QName(webServiceClient.targetNamespace(), webServiceClient.name());
+        } else {
+            return null;
+        }
+    }
+    
+    private URI getWSDLLocation(WebServiceClient webServiceClient) throws DeploymentException
{
+        String wsdlLocation = webServiceClient.wsdlLocation();
+        if (wsdlLocation != null) {
+            try {
+                return new URI(wsdlLocation);
+            } catch (URISyntaxException e) {
+                throw new DeploymentException(
+                        "Invalid wsdl location in annotation: " + wsdlLocation);
+            }
+        }
+
+        return null;
+    }
+
+    private String getCredentialsName(GerPortType port) {
+        String credentialsName = port.getCredentialsName();
+        return (credentialsName == null) ? null : credentialsName.trim();        
+    }
+    
+    private URL getLocation(GerPortType port) throws DeploymentException {
+        String protocol = port.getProtocol().trim();
+        String host = port.getHost().trim();
+        int portNum = port.getPort();
+        String uri = port.getUri().trim();
+        String locationURIString = protocol + "://" + host + ":" + portNum + uri;
+        URL location = getURL(locationURIString);
+        return location;
+    }
+
+    private URL getAddressLocation(Port port) throws DeploymentException {
+        SOAPAddress soapAddress = 
+            (SOAPAddress) getExtensibilityElement(SOAPAddress.class, port.getExtensibilityElements());
+        URL location = null;
+        if (soapAddress != null) {
+            String locationURIString = soapAddress.getLocationURI();
+            location = getURL(locationURIString);
+        }
+        return location;
+    }
+
+    private URL getURL(String locationURIString) throws DeploymentException {
+        try {
+            return new URL(locationURIString);
+        } catch (MalformedURLException e) {
+            throw new DeploymentException(
+                    "Could not construct web service location URL from "
+                            + locationURIString);
+        }
+    }
+    
+    public static ExtensibilityElement getExtensibilityElement(Class clazz,
+                                                               List extensibilityElements)
{
+        for (Iterator iterator = extensibilityElements.iterator(); iterator
+                .hasNext();) {
+            ExtensibilityElement extensibilityElement = (ExtensibilityElement) iterator
+                    .next();
+            if (clazz.isAssignableFrom(extensibilityElement.getClass())) {
+                return extensibilityElement;
+            }
+        }
+        return null;
+    }
+    
+    private void verifyPortComponentList(Definition wsdl) throws DeploymentException {
+        if (this.portComponentRefMap == null) {
+            return;
+        }
+        for (Class sei : this.portComponentRefMap.keySet()) {
+            QName portType = JAXWSUtils.getPortType(sei);
+            if (portType == null) {
+                continue;
+            }
+            if (wsdl.getPortType(portType) == null) {
+                throw new DeploymentException("No portType found in WSDL for SEI: " + sei.getName());
+            }            
+        }        
+    }
+    
+    private class JarWSDLLocator implements WSDLLocator {
+
+        private final List<InputStream> streams = new ArrayList<InputStream>();
+
+        private final URI wsdlURI;
+
+        private URI latestImportURI;
+
+        public JarWSDLLocator(URI wsdlURI) {
+            this.wsdlURI = wsdlURI;
+        }
+
+        public InputSource getBaseInputSource() {
+            InputStream wsdlInputStream;
+            ZipEntry entry = moduleFile.getEntry(wsdlURI.toString());
+            if (entry == null) {
+                throw new RuntimeException(
+                        "WSDL file does not exist in the module " + wsdlURI.toString());
+            }
+            try {
+                wsdlInputStream = moduleFile.getInputStream(entry);
+                streams.add(wsdlInputStream);
+            } catch (Exception e) {
+                throw new RuntimeException(
+                        "Could not open stream to wsdl file", e);
+            }
+            return new InputSource(wsdlInputStream);
+        }
+
+        public String getBaseURI() {
+            return wsdlURI.toString();
+        }
+
+        public InputSource getImportInputSource(String parentLocation,
+                                                String relativeLocation) {
+            URI parentURI = URI.create(parentLocation);
+            latestImportURI = parentURI.resolve(relativeLocation);
+            InputStream importInputStream;
+            ZipEntry entry = moduleFile.getEntry(latestImportURI.toString());
+            if (entry == null) {
+                throw new RuntimeException(
+                        "File does not exist in the module " + latestImportURI.toString());
+            }
+            try {                
+                importInputStream = moduleFile.getInputStream(entry);
+                streams.add(importInputStream);
+            } catch (Exception e) {
+                throw new RuntimeException(
+                        "Could not open stream to import file", e);
+            }
+            InputSource inputSource = new InputSource(importInputStream);
+            inputSource.setSystemId(getLatestImportURI());
+            return inputSource;
+        }
+
+        public String getLatestImportURI() {
+            return latestImportURI.toString();
+        }
+
+        public void close() {
+            for (InputStream inputStream : this.streams) {
+                try {
+                    inputStream.close();
+                } catch (IOException e) {
+                    // ignore
+                }
+            }
+            streams.clear();
+        }
+    }
+}

Added: geronimo/server/trunk/modules/geronimo-jaxws/src/main/java/org/apache/geronimo/jaxws/JAXWSUtils.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-jaxws/src/main/java/org/apache/geronimo/jaxws/JAXWSUtils.java?view=auto&rev=505174
==============================================================================
--- geronimo/server/trunk/modules/geronimo-jaxws/src/main/java/org/apache/geronimo/jaxws/JAXWSUtils.java
(added)
+++ geronimo/server/trunk/modules/geronimo-jaxws/src/main/java/org/apache/geronimo/jaxws/JAXWSUtils.java
Thu Feb  8 20:29:51 2007
@@ -0,0 +1,40 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.geronimo.jaxws;
+
+import javax.jws.WebService;
+import javax.xml.namespace.QName;
+
+public class JAXWSUtils {
+
+    private JAXWSUtils() {
+    }
+
+    public static QName getPortType(Class seiClass) {
+        WebService webService = (WebService) seiClass.getAnnotation(WebService.class);  
     
+        if (webService != null) {
+            String localName = webService.name();
+            if (localName == null || localName.length() == 0) {
+                localName = seiClass.getName();
+            }
+            String namespace = webService.targetNamespace();
+            return new QName(namespace, localName);
+        }
+        return null;
+    }
+
+}

Added: geronimo/server/trunk/modules/geronimo-jaxws/src/main/java/org/apache/geronimo/jaxws/client/EndpointInfo.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-jaxws/src/main/java/org/apache/geronimo/jaxws/client/EndpointInfo.java?view=auto&rev=505174
==============================================================================
--- geronimo/server/trunk/modules/geronimo-jaxws/src/main/java/org/apache/geronimo/jaxws/client/EndpointInfo.java
(added)
+++ geronimo/server/trunk/modules/geronimo-jaxws/src/main/java/org/apache/geronimo/jaxws/client/EndpointInfo.java
Thu Feb  8 20:29:51 2007
@@ -0,0 +1,43 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.geronimo.jaxws.client;
+
+import java.io.Serializable;
+import java.net.URL;
+
+public class EndpointInfo implements Serializable {
+
+    private URL location;
+    private String credentialsName;
+    
+    public EndpointInfo(URL location, String credentialsName) {
+        this.location = location;
+        this.credentialsName = credentialsName;        
+    }
+
+    public URL getLocation() {
+        return this.location;
+    }
+    
+    public String getCredentialsName() {
+        return this.credentialsName;
+    }
+    
+    public String toString() {
+        return this.location + " " + this.credentialsName;
+    }
+}

Added: geronimo/server/trunk/modules/geronimo-jaxws/src/main/java/org/apache/geronimo/jaxws/client/GenericService.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-jaxws/src/main/java/org/apache/geronimo/jaxws/client/GenericService.java?view=auto&rev=505174
==============================================================================
--- geronimo/server/trunk/modules/geronimo-jaxws/src/main/java/org/apache/geronimo/jaxws/client/GenericService.java
(added)
+++ geronimo/server/trunk/modules/geronimo-jaxws/src/main/java/org/apache/geronimo/jaxws/client/GenericService.java
Thu Feb  8 20:29:51 2007
@@ -0,0 +1,30 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.geronimo.jaxws.client;
+
+import java.net.URL;
+
+import javax.xml.namespace.QName;
+import javax.xml.ws.Service;
+
+public class GenericService extends Service {
+
+    public GenericService(URL wsdlLocation, QName serviceName) {
+        super(wsdlLocation, serviceName);
+    }
+
+}



Mime
View raw message