Return-Path: Delivered-To: apmail-geronimo-scm-archive@www.apache.org Received: (qmail 45958 invoked from network); 5 Feb 2007 13:59:08 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 5 Feb 2007 13:59:08 -0000 Received: (qmail 64605 invoked by uid 500); 5 Feb 2007 13:59:14 -0000 Delivered-To: apmail-geronimo-scm-archive@geronimo.apache.org Received: (qmail 64565 invoked by uid 500); 5 Feb 2007 13:59:14 -0000 Mailing-List: contact scm-help@geronimo.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: dev@geronimo.apache.org List-Id: Delivered-To: mailing list scm@geronimo.apache.org Received: (qmail 64554 invoked by uid 99); 5 Feb 2007 13:59:14 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 05 Feb 2007 05:59:14 -0800 X-ASF-Spam-Status: No, hits=-8.6 required=10.0 tests=ALL_TRUSTED,INFO_TLD,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 05 Feb 2007 05:59:05 -0800 Received: by eris.apache.org (Postfix, from userid 65534) id D42E21A981A; Mon, 5 Feb 2007 05:58:44 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r503682 [1/2] - in /geronimo/server/trunk/modules: geronimo-cxf-builder/src/main/java/org/apache/geronimo/cxf/builder/ geronimo-cxf/src/main/java/org/apache/geronimo/cxf/ geronimo-cxf/src/test/ geronimo-cxf/src/test/java/ geronimo-cxf/src/t... Date: Mon, 05 Feb 2007 13:58:44 -0000 To: scm@geronimo.apache.org From: dims@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20070205135844.D42E21A981A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: dims Date: Mon Feb 5 05:58:42 2007 New Revision: 503682 URL: http://svn.apache.org/viewvc?view=rev&rev=503682 Log: Fix for GERONIMO-2796 - HandlerResolver for CXF web servies & other improvements Added: geronimo/server/trunk/modules/geronimo-cxf/src/main/java/org/apache/geronimo/cxf/CXFHandlerResolver.java geronimo/server/trunk/modules/geronimo-cxf/src/main/java/org/apache/geronimo/cxf/GeronimoHandlerChainBuilder.java geronimo/server/trunk/modules/geronimo-cxf/src/test/ geronimo/server/trunk/modules/geronimo-cxf/src/test/java/ geronimo/server/trunk/modules/geronimo-cxf/src/test/java/org/ geronimo/server/trunk/modules/geronimo-cxf/src/test/java/org/apache/ geronimo/server/trunk/modules/geronimo-cxf/src/test/java/org/apache/geronimo/ geronimo/server/trunk/modules/geronimo-cxf/src/test/java/org/apache/geronimo/cxf/ geronimo/server/trunk/modules/geronimo-cxf/src/test/java/org/apache/geronimo/cxf/CXFHandlerResolverTest.java geronimo/server/trunk/modules/geronimo-cxf/src/test/java/org/apache/geronimo/cxf/TestHandler.java geronimo/server/trunk/modules/geronimo-cxf/src/test/resources/ geronimo/server/trunk/modules/geronimo-cxf/src/test/resources/handlers.xml geronimo/server/trunk/modules/geronimo-cxf/src/test/resources/handlers_bindings.xml geronimo/server/trunk/modules/geronimo-cxf/src/test/resources/handlers_mixed.xml geronimo/server/trunk/modules/geronimo-cxf/src/test/resources/handlers_port.xml geronimo/server/trunk/modules/geronimo-cxf/src/test/resources/handlers_service.xml geronimo/server/trunk/modules/geronimo-jaxws-builder/src/main/java/org/apache/geronimo/jaxws/builder/JAXWSServiceRefBuilder.java geronimo/server/trunk/modules/geronimo-jaxws/src/main/java/org/apache/geronimo/jaxws/HandlerChainsUtils.java geronimo/server/trunk/modules/geronimo-jaxws/src/main/java/org/apache/geronimo/jaxws/ServerJNDIResolver.java Modified: geronimo/server/trunk/modules/geronimo-cxf-builder/src/main/java/org/apache/geronimo/cxf/builder/CXFBuilder.java geronimo/server/trunk/modules/geronimo-cxf-builder/src/main/java/org/apache/geronimo/cxf/builder/CXFServiceRefBuilder.java geronimo/server/trunk/modules/geronimo-cxf/src/main/java/org/apache/geronimo/cxf/CXFEndpoint.java geronimo/server/trunk/modules/geronimo-cxf/src/main/java/org/apache/geronimo/cxf/CXFWebServiceContainer.java geronimo/server/trunk/modules/geronimo-jaxws-builder/pom.xml geronimo/server/trunk/modules/geronimo-jaxws-builder/src/main/java/org/apache/geronimo/jaxws/builder/JAXWSServiceBuilder.java geronimo/server/trunk/modules/geronimo-jaxws/src/main/java/org/apache/geronimo/jaxws/JNDIResolver.java geronimo/server/trunk/modules/geronimo-jaxws/src/main/java/org/apache/geronimo/jaxws/PortInfo.java Modified: geronimo/server/trunk/modules/geronimo-cxf-builder/src/main/java/org/apache/geronimo/cxf/builder/CXFBuilder.java URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-cxf-builder/src/main/java/org/apache/geronimo/cxf/builder/CXFBuilder.java?view=diff&rev=503682&r1=503681&r2=503682 ============================================================================== --- geronimo/server/trunk/modules/geronimo-cxf-builder/src/main/java/org/apache/geronimo/cxf/builder/CXFBuilder.java (original) +++ geronimo/server/trunk/modules/geronimo-cxf-builder/src/main/java/org/apache/geronimo/cxf/builder/CXFBuilder.java Mon Feb 5 05:58:42 2007 @@ -32,8 +32,10 @@ import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory; import org.apache.geronimo.kernel.repository.Environment; import org.apache.geronimo.xbeans.geronimo.naming.GerServiceRefType; +import org.apache.geronimo.xbeans.javaee.ServiceRefHandlerChainsType; import org.apache.geronimo.jaxws.builder.JAXWSServiceBuilder; import org.apache.geronimo.cxf.CXFWebServiceContainerFactoryGBean; +//import org.apache.geronimo.cxf.client.CXFServiceReference; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBElement; @@ -44,6 +46,7 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; +import java.io.StringWriter; import java.net.URL; import java.net.URI; import java.util.Collections; @@ -171,22 +174,44 @@ URI wsdlURI, QName serviceQName, Map portComponentRefMap, - Object object, + ServiceRefHandlerChainsType handlerChains, GerServiceRefType serviceRefType, Module module, ClassLoader cl) throws DeploymentException { System.out.println("createService"); /* - WSDLInfoBuilder builder = new WSDLInfoBuilder(serviceInterface, module.getModuleFile(), wsdlURI, serviceQName, cl); + WSDLInfoBuilder builder = new WSDLInfoBuilder(serviceInterface, module + .getModuleFile(), wsdlURI, serviceQName, cl); builder.build(); - - serviceQName = builder.getServiceQName(); - - return new CXFServiceReference(serviceInterface.getName(), wsdlURI, serviceQName, module.getModuleName(), object, null, null); + + serviceQName = builder.getServiceQName(); + + String handlerChainsXML = null; + try { + handlerChainsXML = getHanderChainAsString(handlerChains); + } catch (IOException e) { + // should not happen + // TODO: log error + } + + return new CXFServiceReference(serviceInterface.getName(), wsdlURI, + serviceQName, module.getModuleName(), handlerChainsXML, null, + null); */ return null; } - + + private static String getHanderChainAsString(ServiceRefHandlerChainsType handlerChains) + throws IOException { + String xml = null; + if (handlerChains != null) { + StringWriter w = new StringWriter(); + handlerChains.save(w); + xml = w.toString(); + } + return xml; + } + private static String getString(String in) { if (in != null) { in = in.trim(); Modified: geronimo/server/trunk/modules/geronimo-cxf-builder/src/main/java/org/apache/geronimo/cxf/builder/CXFServiceRefBuilder.java URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-cxf-builder/src/main/java/org/apache/geronimo/cxf/builder/CXFServiceRefBuilder.java?view=diff&rev=503682&r1=503681&r2=503682 ============================================================================== --- geronimo/server/trunk/modules/geronimo-cxf-builder/src/main/java/org/apache/geronimo/cxf/builder/CXFServiceRefBuilder.java (original) +++ geronimo/server/trunk/modules/geronimo-cxf-builder/src/main/java/org/apache/geronimo/cxf/builder/CXFServiceRefBuilder.java Mon Feb 5 05:58:42 2007 @@ -18,9 +18,6 @@ package org.apache.geronimo.cxf.builder; import java.net.URI; -import java.net.URISyntaxException; -import java.util.HashMap; -import java.util.List; import java.util.Map; import javax.xml.namespace.QName; @@ -30,157 +27,32 @@ import org.apache.geronimo.gbean.GBeanInfoBuilder; import org.apache.geronimo.j2ee.deployment.Module; import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory; -import org.apache.geronimo.kernel.config.Configuration; +import org.apache.geronimo.jaxws.builder.JAXWSServiceRefBuilder; import org.apache.geronimo.kernel.repository.Environment; -import org.apache.geronimo.naming.deployment.AbstractNamingBuilder; import org.apache.geronimo.naming.deployment.ServiceRefBuilder; -import org.apache.geronimo.xbeans.geronimo.naming.GerServiceRefDocument; import org.apache.geronimo.xbeans.geronimo.naming.GerServiceRefType; -import org.apache.geronimo.xbeans.javaee.PortComponentRefType; -import org.apache.geronimo.xbeans.javaee.ServiceRefHandlerChainType; -import org.apache.geronimo.xbeans.javaee.ServiceRefHandlerChainsType; -import org.apache.geronimo.xbeans.javaee.ServiceRefHandlerType; import org.apache.geronimo.xbeans.javaee.ServiceRefType; -import org.apache.xmlbeans.QNameSet; -import org.apache.xmlbeans.XmlObject; +public class CXFServiceRefBuilder extends JAXWSServiceRefBuilder { -public class CXFServiceRefBuilder extends AbstractNamingBuilder implements ServiceRefBuilder { - - private static final QName GER_SERVICE_REF_QNAME = - GerServiceRefDocument.type.getDocumentElementName(); - - private static final QNameSet GER_SERVICE_REF_QNAME_SET = - QNameSet.singleton(GER_SERVICE_REF_QNAME); - - private final QNameSet serviceRefQNameSet; private final CXFBuilder cxfBuilder; public CXFServiceRefBuilder(Environment defaultEnvironment, String[] eeNamespaces, CXFBuilder cxfBuilder) { - super(defaultEnvironment); + super(defaultEnvironment, eeNamespaces); this.cxfBuilder = cxfBuilder; - serviceRefQNameSet = buildQNameSet(eeNamespaces, "service-ref"); - } - - protected boolean willMergeEnvironment(XmlObject specDD, XmlObject plan) { - return specDD.selectChildren(serviceRefQNameSet).length > 0; - } - - public void buildNaming(XmlObject specDD, - XmlObject plan, - Configuration localConfiguration, - Configuration remoteConfiguration, - Module module, - Map componentContext) throws DeploymentException { - List serviceRefsUntyped = convert(specDD.selectChildren(serviceRefQNameSet), JEE_CONVERTER, ServiceRefType.class, ServiceRefType.type); - XmlObject[] gerServiceRefsUntyped = plan == null ? NO_REFS : plan.selectChildren(GER_SERVICE_REF_QNAME_SET); - Map serviceRefMap = mapServiceRefs(gerServiceRefsUntyped); - - for (ServiceRefType serviceRef : serviceRefsUntyped) { - String name = getStringValue(serviceRef.getServiceRefName()); - GerServiceRefType serviceRefType = (GerServiceRefType) serviceRefMap.get(name); - - buildNaming(serviceRef, serviceRefType, module, componentContext); - } - } - - private Class loadClass(String name, ClassLoader cl) throws DeploymentException { - try { - return cl.loadClass(name); - } catch (ClassNotFoundException e) { - throw new DeploymentException("Could not load service class " + name, e); - } - } - - public void buildNaming(XmlObject serviceRef, GerServiceRefType gerServiceRefType, Module module, Map componentContext) throws DeploymentException { - ServiceRefType serviceRefType = - (ServiceRefType)convert(serviceRef, JEE_CONVERTER, ServiceRefType.type); - buildNaming(serviceRefType, gerServiceRefType, module, componentContext); - } - - public void buildNaming(ServiceRefType serviceRef, GerServiceRefType gerServiceRef, Module module, Map componentContext) throws DeploymentException { - ClassLoader cl = module.getEarContext().getClassLoader(); - Class jaxwsServiceClass = loadClass("javax.xml.ws.Service", cl); - String name = getStringValue(serviceRef.getServiceRefName()); - String serviceInterfaceName = getStringValue(serviceRef.getServiceInterface()); - Class serviceInterfaceClass = loadClass(serviceInterfaceName, cl); - - if (!jaxwsServiceClass.isAssignableFrom(serviceInterfaceClass)) { - throw new DeploymentException(serviceInterfaceName + " class does not extend " + jaxwsServiceClass.getName()); - } - // TODO: check if service class is abstract??? - - QName serviceQName = null; - if (serviceRef.isSetServiceQname()) { - serviceQName = serviceRef.getServiceQname().getQNameValue(); - } - - URI wsdlURI = null; - if (serviceRef.isSetWsdlFile()) { - try { - wsdlURI = new URI(serviceRef.getWsdlFile().getStringValue().trim()); - } catch (URISyntaxException e) { - throw new DeploymentException("could not construct wsdl uri from " + serviceRef.getWsdlFile().getStringValue(), e); - } - } - - Class serviceReferenceType = null; - if (serviceRef.isSetServiceRefType()) { - String referenceClassName = getStringValue(serviceRef.getServiceRefType()); - serviceReferenceType = loadClass(referenceClassName, cl); - } - - // TODO: handle handler chains - if (serviceRef.isSetHandlerChains()) { - ServiceRefHandlerChainsType handlerChains = serviceRef.getHandlerChains(); - for (ServiceRefHandlerChainType handlerChain : handlerChains.getHandlerChainArray()) { - // bindings, port, service - for (ServiceRefHandlerType handler : handlerChain.getHandlerArray()) { - // handler class - } - } - } - - Map portComponentRefMap = new HashMap(); - PortComponentRefType[] portComponentRefs = serviceRef.getPortComponentRefArray(); - if (portComponentRefs != null) { - for (int j = 0; j < portComponentRefs.length; j++) { - PortComponentRefType portComponentRef = portComponentRefs[j]; - String serviceEndpointInterfaceType = getStringValue(portComponentRef.getServiceEndpointInterface()); - Class serviceEndpointClass = loadClass(serviceEndpointInterfaceType, cl); - String portComponentLink = getStringValue(portComponentRef.getPortComponentLink()); - - portComponentRefMap.put(serviceEndpointClass, portComponentLink); - } - } - - Object ref = cxfBuilder.createService(serviceInterfaceClass, serviceReferenceType, wsdlURI, serviceQName, portComponentRefMap, serviceRef.getHandlerChains(), gerServiceRef, module, cl); - getJndiContextMap(componentContext).put(ENV + name, ref); } - private static Map mapServiceRefs(XmlObject[] refs) { - Map refMap = new HashMap(); - if (refs != null) { - for (int i = 0; i < refs.length; i++) { - GerServiceRefType ref = (GerServiceRefType) refs[i].copy() - .changeType(GerServiceRefType.type); - String serviceRefName = ref.getServiceRefName().trim(); - refMap.put(serviceRefName, ref); - } - } - return refMap; - } - - public QNameSet getSpecQNameSet() { - return serviceRefQNameSet; - } - - public QNameSet getPlanQNameSet() { - return GER_SERVICE_REF_QNAME_SET; + public Object createService(ServiceRefType serviceRef, GerServiceRefType gerServiceRef, + Module module, ClassLoader cl, Class serviceInterfaceClass, + QName serviceQName, URI wsdlURI, Class serviceReferenceType, + Map portComponentRefMap) throws DeploymentException { + return this.cxfBuilder.createService(serviceInterfaceClass, serviceReferenceType, wsdlURI, + serviceQName, portComponentRefMap, serviceRef.getHandlerChains(), + gerServiceRef, module, cl); } - + public static final GBeanInfo GBEAN_INFO; static { @@ -202,6 +74,4 @@ public static GBeanInfo getGBeanInfo() { return GBEAN_INFO; } - - } Modified: geronimo/server/trunk/modules/geronimo-cxf/src/main/java/org/apache/geronimo/cxf/CXFEndpoint.java URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-cxf/src/main/java/org/apache/geronimo/cxf/CXFEndpoint.java?view=diff&rev=503682&r1=503681&r2=503682 ============================================================================== --- geronimo/server/trunk/modules/geronimo-cxf/src/main/java/org/apache/geronimo/cxf/CXFEndpoint.java (original) +++ geronimo/server/trunk/modules/geronimo-cxf/src/main/java/org/apache/geronimo/cxf/CXFEndpoint.java Mon Feb 5 05:58:42 2007 @@ -20,7 +20,6 @@ import java.net.MalformedURLException; import java.net.URL; -import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.concurrent.Executor; @@ -29,6 +28,7 @@ import javax.xml.ws.Binding; import javax.xml.ws.Provider; import javax.xml.ws.Endpoint; +import javax.xml.ws.WebServiceException; import javax.xml.ws.handler.Handler; import javax.xml.ws.http.HTTPBinding; @@ -42,8 +42,6 @@ import org.apache.cxf.jaxws.ProviderChainObserver; import org.apache.cxf.jaxws.ProviderInvoker; import org.apache.cxf.jaxws.binding.soap.JaxWsSoapBindingInfoFactoryBean; -import org.apache.cxf.jaxws.handler.AnnotationHandlerChainBuilder; -import org.apache.cxf.jaxws.javaee.HandlerChainType; import org.apache.cxf.jaxws.javaee.HandlerChainsType; import org.apache.cxf.jaxws.support.AbstractJaxWsServiceFactoryBean; import org.apache.cxf.jaxws.support.JaxWsEndpointImpl; @@ -123,8 +121,7 @@ service.setInvoker(new JAXWSMethodInvoker(instance)); } - JNDIResolver jndiResolver = (JNDIResolver) bus - .getExtension(JNDIResolver.class); + JNDIResolver jndiResolver = (JNDIResolver) bus.getExtension(JNDIResolver.class); this.annotationProcessor = new JAXWSAnnotationProcessor(jndiResolver, new CXFWebServiceContext()); } @@ -233,11 +230,11 @@ bindingFactory = new XMLBindingInfoFactoryBean(); } else { // Just assume soap otherwise... - bindingFactory = new JaxWsSoapBindingInfoFactoryBean(); + bindingFactory = new JaxWsSoapBindingInfoFactoryBean(); } svrFactory.setBindingFactory(bindingFactory); - + server = svrFactory.create(); init(); @@ -256,32 +253,19 @@ server.start(); } - protected void init() { - // configure handlers + protected void init() { + // configure and inject handlers try { configureHandlers(); } catch (Exception e) { - throw new RuntimeException("Error configuring handlers", e); + throw new WebServiceException("Error configuring handlers", e); } // inject resources into service try { injectResources(this.implementor); } catch (AnnotationException e) { - // TODO: better way to deal with it - throw new RuntimeException("Service resource injection failed", e); - } - - // inject resources into handlers - List handlers = getBinding().getHandlerChain(); - for (Handler handler : handlers) { - try { - injectResources(handler); - } catch (AnnotationException e) { - // TODO: better way to deal with it - throw new RuntimeException("Handler resource injection failed", - e); - } + throw new WebServiceException("Service resource injection failed", e); } } @@ -290,33 +274,21 @@ this.annotationProcessor.invokePostConstruct(instance); } - protected void configureHandlers() throws Exception { - AnnotationHandlerChainBuilder builder = (new AnnotationHandlerChainBuilder() { - public ClassLoader getHandlerClassLoader() { - return implementor.getClass().getClassLoader(); - } - }); - - // we'll do our own resource injection - builder.setHandlerInitEnabled(false); - - List chain = null; - - // handlers in DD overwrite the handlers in annotation - HandlerChainsType handlerChains = (HandlerChainsType)this.portInfo.getHandlers(HandlerChainsType.class); - if (handlerChains != null && handlerChains.getHandlerChain() != null - && handlerChains.getHandlerChain().size() > 0) { - chain = new ArrayList(); - for (HandlerChainType chainType : handlerChains.getHandlerChain()) { - // TODO: check if the handler chain should be added to this - // service - chain.addAll(builder - .buildHandlerChainFromConfiguration(chainType)); - } - chain = builder.sortHandlers(chain); - } else { - chain = builder.buildHandlerChainFromClass(implementor.getClass()); - } + /* + * Gets the right handlers for the port/service/bindings and + * performs injection. + */ + protected void configureHandlers() throws Exception { + HandlerChainsType handlerChains = this.portInfo.getHandlers(HandlerChainsType.class); + CXFHandlerResolver handlerResolver = + new CXFHandlerResolver(this.implementor.getClass().getClassLoader(), + this.implementor.getClass(), + handlerChains, + this.annotationProcessor); + + + // TODO: pass non-null PortInfo to get the right handlers + List chain = handlerResolver.getHandlerChain(null); getBinding().setHandlerChain(chain); } Added: geronimo/server/trunk/modules/geronimo-cxf/src/main/java/org/apache/geronimo/cxf/CXFHandlerResolver.java URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-cxf/src/main/java/org/apache/geronimo/cxf/CXFHandlerResolver.java?view=auto&rev=503682 ============================================================================== --- geronimo/server/trunk/modules/geronimo-cxf/src/main/java/org/apache/geronimo/cxf/CXFHandlerResolver.java (added) +++ geronimo/server/trunk/modules/geronimo-cxf/src/main/java/org/apache/geronimo/cxf/CXFHandlerResolver.java Mon Feb 5 05:58:42 2007 @@ -0,0 +1,82 @@ +/** + * 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; + +import java.util.ArrayList; +import java.util.List; + +import javax.xml.ws.WebServiceException; +import javax.xml.ws.handler.Handler; +import javax.xml.ws.handler.HandlerResolver; +import javax.xml.ws.handler.PortInfo; + +import org.apache.cxf.jaxws.javaee.HandlerChainType; +import org.apache.cxf.jaxws.javaee.HandlerChainsType; +import org.apache.geronimo.jaxws.annotations.AnnotationException; +import org.apache.geronimo.jaxws.annotations.AnnotationProcessor; + +public class CXFHandlerResolver implements HandlerResolver { + + private HandlerChainsType handlerChains; + + private ClassLoader classLoader; + + private Class serviceClass; + + private AnnotationProcessor annotationProcessor; + + public CXFHandlerResolver(ClassLoader classLoader, + Class serviceClass, + HandlerChainsType handlerChains, + AnnotationProcessor annotationProcessor) { + this.classLoader = classLoader; + this.serviceClass = serviceClass; + this.handlerChains = handlerChains; + this.annotationProcessor = annotationProcessor; + } + + public List getHandlerChain(PortInfo portInfo) { + + GeronimoHandlerChainBuilder builder = + new GeronimoHandlerChainBuilder(this.classLoader, portInfo); + + List handlers = null; + if (this.handlerChains == null) { + handlers = builder.buildHandlerChainFromClass(this.serviceClass); + } else { + handlers = new ArrayList(); + for (HandlerChainType handlerChain : this.handlerChains.getHandlerChain()) { + handlers.addAll(builder.buildHandlerChainFromConfiguration(handlerChain)); + } + handlers = builder.sortHandlers(handlers); + } + + if (this.annotationProcessor != null) { + try { + for (Handler handler : handlers) { + this.annotationProcessor.processAnnotations(handler); + this.annotationProcessor.invokePostConstruct(handler); + } + } catch (AnnotationException e) { + throw new WebServiceException("Handler annotation failed", e); + } + } + + return handlers; + } + +} Modified: geronimo/server/trunk/modules/geronimo-cxf/src/main/java/org/apache/geronimo/cxf/CXFWebServiceContainer.java URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-cxf/src/main/java/org/apache/geronimo/cxf/CXFWebServiceContainer.java?view=diff&rev=503682&r1=503681&r2=503682 ============================================================================== --- geronimo/server/trunk/modules/geronimo-cxf/src/main/java/org/apache/geronimo/cxf/CXFWebServiceContainer.java (original) +++ geronimo/server/trunk/modules/geronimo-cxf/src/main/java/org/apache/geronimo/cxf/CXFWebServiceContainer.java Mon Feb 5 05:58:42 2007 @@ -31,6 +31,7 @@ import org.apache.geronimo.webservices.WebServiceContainer; import org.apache.geronimo.jaxws.JNDIResolver; import org.apache.geronimo.jaxws.PortInfo; +import org.apache.geronimo.jaxws.ServerJNDIResolver; import org.xmlsoap.schemas.wsdl.http.AddressType; import javax.wsdl.Definition; @@ -68,7 +69,7 @@ List ids = new ArrayList(); ids.add("http://schemas.xmlsoap.org/wsdl/soap/http"); - bus.setExtension(new JNDIResolver(context), JNDIResolver.class); + bus.setExtension(new ServerJNDIResolver(context), JNDIResolver.class); bus.setExtension(portInfo, PortInfo.class); DestinationFactoryManager destinationFactoryManager = bus Added: geronimo/server/trunk/modules/geronimo-cxf/src/main/java/org/apache/geronimo/cxf/GeronimoHandlerChainBuilder.java URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-cxf/src/main/java/org/apache/geronimo/cxf/GeronimoHandlerChainBuilder.java?view=auto&rev=503682 ============================================================================== --- geronimo/server/trunk/modules/geronimo-cxf/src/main/java/org/apache/geronimo/cxf/GeronimoHandlerChainBuilder.java (added) +++ geronimo/server/trunk/modules/geronimo-cxf/src/main/java/org/apache/geronimo/cxf/GeronimoHandlerChainBuilder.java Mon Feb 5 05:58:42 2007 @@ -0,0 +1,112 @@ +/** + * 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; + +import java.util.Collections; +import java.util.List; + +import javax.xml.namespace.QName; +import javax.xml.ws.handler.Handler; +import javax.xml.ws.handler.PortInfo; + +import org.apache.cxf.jaxws.handler.AnnotationHandlerChainBuilder; +import org.apache.cxf.jaxws.javaee.HandlerChainType; + +public class GeronimoHandlerChainBuilder extends AnnotationHandlerChainBuilder { + + private ClassLoader classLoader = null; + private PortInfo portInfo; + + public GeronimoHandlerChainBuilder(ClassLoader classloader, + PortInfo portInfo) { + this.classLoader = classloader; + this.portInfo = portInfo; + + // we'll do our own resource injection + setHandlerInitEnabled(false); + } + + public ClassLoader getHandlerClassLoader() { + return this.classLoader; + } + + protected List buildHandlerChain(HandlerChainType hc, + ClassLoader classLoader) { + if (matchServiceName(portInfo, hc.getServiceNamePattern()) + && matchPortName(portInfo, hc.getPortNamePattern()) + && matchBinding(portInfo, hc.getProtocolBindings())) { + return super.buildHandlerChain(hc, classLoader); + } else { + return Collections.EMPTY_LIST; + } + } + + private boolean matchServiceName(PortInfo info, String namePattern) { + return match((info == null ? null : info.getServiceName()), namePattern); + } + + private boolean matchPortName(PortInfo info, String namePattern) { + return match((info == null ? null : info.getPortName()), namePattern); + } + + private boolean matchBinding(PortInfo info, List bindings) { + return match((info == null ? null : info.getBindingID()), bindings); + } + + private boolean match(String binding, List bindings) { + if (binding == null) { + return (bindings == null || bindings.isEmpty()); + } else { + return (bindings == null || bindings.isEmpty()) ? true : bindings.contains(binding); + } + } + + /* + * Performs basic localName matching, namespaces are not checked! + */ + private boolean match(QName name, String namePattern) { + if (name == null) { + return (namePattern == null || namePattern.equals("*")); + } else { + if (namePattern == null) { + return true; + } else { + String localNamePattern; + + // get the local name from pattern + int pos = namePattern.indexOf(':'); + localNamePattern = (pos == -1) ? namePattern : namePattern + .substring(pos + 1); + localNamePattern = localNamePattern.trim(); + + if (localNamePattern.equals("*")) { + // matches anything + return true; + } else if (localNamePattern.endsWith("*")) { + // match start + localNamePattern = localNamePattern.substring(0, + localNamePattern.length() - 1); + return name.getLocalPart().startsWith(localNamePattern); + } else { + // match exact + return name.getLocalPart().equals(localNamePattern); + } + } + } + } + +} Added: geronimo/server/trunk/modules/geronimo-cxf/src/test/java/org/apache/geronimo/cxf/CXFHandlerResolverTest.java URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-cxf/src/test/java/org/apache/geronimo/cxf/CXFHandlerResolverTest.java?view=auto&rev=503682 ============================================================================== --- geronimo/server/trunk/modules/geronimo-cxf/src/test/java/org/apache/geronimo/cxf/CXFHandlerResolverTest.java (added) +++ geronimo/server/trunk/modules/geronimo-cxf/src/test/java/org/apache/geronimo/cxf/CXFHandlerResolverTest.java Mon Feb 5 05:58:42 2007 @@ -0,0 +1,205 @@ +/** + * 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; + +import java.io.InputStream; +import java.util.List; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBElement; +import javax.xml.bind.JAXBException; +import javax.xml.bind.Unmarshaller; +import javax.xml.namespace.QName; +import javax.xml.transform.stream.StreamSource; + +import javax.xml.ws.handler.Handler; +import javax.xml.ws.handler.PortInfo; +import org.apache.cxf.jaxws.javaee.HandlerChainsType; + +import org.apache.geronimo.testsupport.TestSupport; + +public class CXFHandlerResolverTest extends TestSupport { + + public void testBasic() throws Exception { + InputStream in = getClass().getResourceAsStream("/handlers.xml"); + assertTrue(in != null); + HandlerChainsType handlerChains = toHandlerChains(in); + assertEquals(3, handlerChains.getHandlerChain().size()); + + CXFHandlerResolver resolver = + new CXFHandlerResolver(getClass().getClassLoader(), getClass(), handlerChains, null); + + List handlers = null; + + handlers = resolver.getHandlerChain(new TestPortInfo(null, null, null)); + assertEquals(3, handlers.size()); + } + + public void testServiceMatching() throws Exception { + InputStream in = getClass().getResourceAsStream("/handlers_service.xml"); + assertTrue(in != null); + HandlerChainsType handlerChains = toHandlerChains(in); + assertEquals(3, handlerChains.getHandlerChain().size()); + + CXFHandlerResolver resolver = + new CXFHandlerResolver(getClass().getClassLoader(), getClass(), handlerChains, null); + + List handlers = null; + + handlers = resolver.getHandlerChain(new TestPortInfo(null, null, null)); + assertEquals(0, handlers.size()); + + QName serviceName1 = new QName("http://foo", "Bar"); + handlers = resolver.getHandlerChain(new TestPortInfo(null, null, serviceName1)); + assertEquals(1, handlers.size()); + + QName serviceName2 = new QName("http://foo", "Foo"); + handlers = resolver.getHandlerChain(new TestPortInfo(null, null, serviceName2)); + assertEquals(2, handlers.size()); + + QName serviceName3 = new QName("http://foo", "FooBar"); + handlers = resolver.getHandlerChain(new TestPortInfo(null, null, serviceName3)); + assertEquals(1, handlers.size()); + + QName serviceName4 = new QName("http://foo", "BarFoo"); + handlers = resolver.getHandlerChain(new TestPortInfo(null, null, serviceName4)); + assertEquals(0, handlers.size()); + } + + public void testBindingMatching() throws Exception { + InputStream in = getClass().getResourceAsStream("/handlers_bindings.xml"); + assertTrue(in != null); + HandlerChainsType handlerChains = toHandlerChains(in); + assertEquals(3, handlerChains.getHandlerChain().size()); + + CXFHandlerResolver resolver = + new CXFHandlerResolver(getClass().getClassLoader(), getClass(), handlerChains, null); + + List handlers = null; + + handlers = resolver.getHandlerChain(new TestPortInfo(null, null, null)); + assertEquals(0, handlers.size()); + + handlers = resolver.getHandlerChain(new TestPortInfo("##FOO_BAR", null, null)); + assertEquals(0, handlers.size()); + + handlers = resolver.getHandlerChain(new TestPortInfo("##SOAP11_HTTP", null, null)); + assertEquals(2, handlers.size()); + + handlers = resolver.getHandlerChain(new TestPortInfo("##SOAP11_HTTP_MTOM", null, null)); + assertEquals(1, handlers.size()); + } + + public void testPortMatching() throws Exception { + InputStream in = getClass().getResourceAsStream("/handlers_port.xml"); + assertTrue(in != null); + HandlerChainsType handlerChains = toHandlerChains(in); + assertEquals(3, handlerChains.getHandlerChain().size()); + + CXFHandlerResolver resolver = + new CXFHandlerResolver(getClass().getClassLoader(), getClass(), handlerChains, null); + + List handlers = null; + + handlers = resolver.getHandlerChain(new TestPortInfo(null, null, null)); + assertEquals(0, handlers.size()); + + QName portName1 = new QName("http://foo", "Bar"); + handlers = resolver.getHandlerChain(new TestPortInfo(null, portName1, null)); + assertEquals(1, handlers.size()); + + QName portName2 = new QName("http://foo", "Foo"); + handlers = resolver.getHandlerChain(new TestPortInfo(null, portName2, null)); + assertEquals(2, handlers.size()); + + QName portName3 = new QName("http://foo", "FooBar"); + handlers = resolver.getHandlerChain(new TestPortInfo(null, portName3, null)); + assertEquals(1, handlers.size()); + + QName portName4 = new QName("http://foo", "BarFoo"); + handlers = resolver.getHandlerChain(new TestPortInfo(null, portName4, null)); + assertEquals(0, handlers.size()); + } + + public void testMixedMatching() throws Exception { + InputStream in = getClass().getResourceAsStream("/handlers_mixed.xml"); + assertTrue(in != null); + HandlerChainsType handlerChains = toHandlerChains(in); + assertEquals(3, handlerChains.getHandlerChain().size()); + + CXFHandlerResolver resolver = + new CXFHandlerResolver(getClass().getClassLoader(), getClass(), handlerChains, null); + + List handlers = null; + + handlers = resolver.getHandlerChain(new TestPortInfo(null, null, null)); + assertEquals(0, handlers.size()); + + QName serviceName1 = new QName("http:/foo", "Bar"); + QName portName1 = new QName("http://foo", "FooBar"); + String binding1 = "##XML_HTTP"; + handlers = resolver.getHandlerChain(new TestPortInfo(binding1, portName1, serviceName1)); + assertEquals(3, handlers.size()); + + String binding2 = "##SOAP11_HTTP"; + handlers = resolver.getHandlerChain(new TestPortInfo(binding2, portName1, serviceName1)); + assertEquals(2, handlers.size()); + + QName serviceName2 = new QName("http://foo", "Baaz"); + QName portName2 = new QName("http://foo", "Baaz"); + handlers = resolver.getHandlerChain(new TestPortInfo(binding1, portName2, serviceName2)); + assertEquals(1, handlers.size()); + } + + private static HandlerChainsType toHandlerChains(InputStream input) + throws JAXBException { + JAXBContext ctx = JAXBContext.newInstance(HandlerChainsType.class); + Unmarshaller unmarshaller = ctx.createUnmarshaller(); + StreamSource in = new StreamSource(input); + JAXBElement handlerElement = unmarshaller.unmarshal(in, + HandlerChainsType.class); + + return (HandlerChainsType) handlerElement.getValue(); + } + + private static class TestPortInfo implements PortInfo { + + private String bindingID; + private QName portName; + private QName serviceName; + + public TestPortInfo(String bindingID, QName portName, QName serviceName) { + this.bindingID = bindingID; + this.portName = portName; + this.serviceName = serviceName; + } + + public String getBindingID() { + return this.bindingID; + } + + public QName getPortName() { + return this.portName; + } + + public QName getServiceName() { + return this.serviceName; + } + + } + +} Added: geronimo/server/trunk/modules/geronimo-cxf/src/test/java/org/apache/geronimo/cxf/TestHandler.java URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-cxf/src/test/java/org/apache/geronimo/cxf/TestHandler.java?view=auto&rev=503682 ============================================================================== --- geronimo/server/trunk/modules/geronimo-cxf/src/test/java/org/apache/geronimo/cxf/TestHandler.java (added) +++ geronimo/server/trunk/modules/geronimo-cxf/src/test/java/org/apache/geronimo/cxf/TestHandler.java Mon Feb 5 05:58:42 2007 @@ -0,0 +1,38 @@ +/** + * 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; + +import javax.xml.ws.handler.Handler; +import javax.xml.ws.handler.MessageContext; + +public class TestHandler implements Handler { + + public void close(MessageContext arg0) { + // TODO Auto-generated method stub + } + + public boolean handleFault(MessageContext arg0) { + // TODO Auto-generated method stub + return false; + } + + public boolean handleMessage(MessageContext arg0) { + // TODO Auto-generated method stub + return false; + } + +} Added: geronimo/server/trunk/modules/geronimo-cxf/src/test/resources/handlers.xml URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-cxf/src/test/resources/handlers.xml?view=auto&rev=503682 ============================================================================== --- geronimo/server/trunk/modules/geronimo-cxf/src/test/resources/handlers.xml (added) +++ geronimo/server/trunk/modules/geronimo-cxf/src/test/resources/handlers.xml Mon Feb 5 05:58:42 2007 @@ -0,0 +1,23 @@ + + + + + GreeterHandler + org.apache.geronimo.cxf.TestHandler + + + + * + + GreeterHandler + org.apache.geronimo.cxf.TestHandler + + + + * + + GreeterHandler + org.apache.geronimo.cxf.TestHandler + + + Added: geronimo/server/trunk/modules/geronimo-cxf/src/test/resources/handlers_bindings.xml URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-cxf/src/test/resources/handlers_bindings.xml?view=auto&rev=503682 ============================================================================== --- geronimo/server/trunk/modules/geronimo-cxf/src/test/resources/handlers_bindings.xml (added) +++ geronimo/server/trunk/modules/geronimo-cxf/src/test/resources/handlers_bindings.xml Mon Feb 5 05:58:42 2007 @@ -0,0 +1,24 @@ + + + + ##XML_HTTP + + GreeterHandler + org.apache.geronimo.cxf.TestHandler + + + + ##SOAP11_HTTP + + GreeterHandler + org.apache.geronimo.cxf.TestHandler + + + + ##SOAP11_HTTP ##SOAP11_HTTP_MTOM + + GreeterHandler + org.apache.geronimo.cxf.TestHandler + + + Added: geronimo/server/trunk/modules/geronimo-cxf/src/test/resources/handlers_mixed.xml URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-cxf/src/test/resources/handlers_mixed.xml?view=auto&rev=503682 ============================================================================== --- geronimo/server/trunk/modules/geronimo-cxf/src/test/resources/handlers_mixed.xml (added) +++ geronimo/server/trunk/modules/geronimo-cxf/src/test/resources/handlers_mixed.xml Mon Feb 5 05:58:42 2007 @@ -0,0 +1,24 @@ + + + + ##XML_HTTP + + GreeterHandler + org.apache.geronimo.cxf.TestHandler + + + + jws:Foo* + + GreeterHandler + org.apache.geronimo.cxf.TestHandler + + + + jws:Bar + + GreeterHandler + org.apache.geronimo.cxf.TestHandler + + + Added: geronimo/server/trunk/modules/geronimo-cxf/src/test/resources/handlers_port.xml URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-cxf/src/test/resources/handlers_port.xml?view=auto&rev=503682 ============================================================================== --- geronimo/server/trunk/modules/geronimo-cxf/src/test/resources/handlers_port.xml (added) +++ geronimo/server/trunk/modules/geronimo-cxf/src/test/resources/handlers_port.xml Mon Feb 5 05:58:42 2007 @@ -0,0 +1,24 @@ + + + + jws:Foo + + GreeterHandler + org.apache.geronimo.cxf.TestHandler + + + + jws:Foo* + + GreeterHandler + org.apache.geronimo.cxf.TestHandler + + + + jws:Bar + + GreeterHandler + org.apache.geronimo.cxf.TestHandler + + + Added: geronimo/server/trunk/modules/geronimo-cxf/src/test/resources/handlers_service.xml URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-cxf/src/test/resources/handlers_service.xml?view=auto&rev=503682 ============================================================================== --- geronimo/server/trunk/modules/geronimo-cxf/src/test/resources/handlers_service.xml (added) +++ geronimo/server/trunk/modules/geronimo-cxf/src/test/resources/handlers_service.xml Mon Feb 5 05:58:42 2007 @@ -0,0 +1,24 @@ + + + + jws:Foo + + GreeterHandler + org.apache.geronimo.cxf.TestHandler + + + + jws:Foo* + + GreeterHandler + org.apache.geronimo.cxf.TestHandler + + + + jws:Bar + + GreeterHandler + org.apache.geronimo.cxf.TestHandler + + + Modified: geronimo/server/trunk/modules/geronimo-jaxws-builder/pom.xml URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-jaxws-builder/pom.xml?view=diff&rev=503682&r1=503681&r2=503682 ============================================================================== --- geronimo/server/trunk/modules/geronimo-jaxws-builder/pom.xml (original) +++ geronimo/server/trunk/modules/geronimo-jaxws-builder/pom.xml Mon Feb 5 05:58:42 2007 @@ -1,43 +1,48 @@ - - - - - - - - 4.0.0 - - - org.apache.geronimo.modules - modules - 2.0-SNAPSHOT - ../pom.xml - - - geronimo-jaxws-builder - Geronimo :: JAXWS :: Builder - - - - org.apache.geronimo.modules - geronimo-jaxws - ${version} - - - - + + + + + + + + 4.0.0 + + + org.apache.geronimo.modules + modules + 2.0-SNAPSHOT + ../pom.xml + + + geronimo-jaxws-builder + Geronimo :: JAXWS :: Builder + + + + org.apache.geronimo.modules + geronimo-jaxws + ${version} + + + org.apache.geronimo.modules + geronimo-naming-builder + ${version} + + + + Modified: geronimo/server/trunk/modules/geronimo-jaxws-builder/src/main/java/org/apache/geronimo/jaxws/builder/JAXWSServiceBuilder.java URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-jaxws-builder/src/main/java/org/apache/geronimo/jaxws/builder/JAXWSServiceBuilder.java?view=diff&rev=503682&r1=503681&r2=503682 ============================================================================== --- geronimo/server/trunk/modules/geronimo-jaxws-builder/src/main/java/org/apache/geronimo/jaxws/builder/JAXWSServiceBuilder.java (original) +++ geronimo/server/trunk/modules/geronimo-jaxws-builder/src/main/java/org/apache/geronimo/jaxws/builder/JAXWSServiceBuilder.java Mon Feb 5 05:58:42 2007 @@ -1,277 +1,281 @@ -/** - * 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 org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.geronimo.common.DeploymentException; -import org.apache.geronimo.deployment.DeploymentContext; -import org.apache.geronimo.deployment.service.EnvironmentBuilder; -import org.apache.geronimo.deployment.util.DeploymentUtil; -import org.apache.geronimo.gbean.AbstractName; -import org.apache.geronimo.gbean.GBeanData; -import org.apache.geronimo.gbean.GBeanInfo; -import org.apache.geronimo.j2ee.deployment.EARContext; -import org.apache.geronimo.j2ee.deployment.Module; -import org.apache.geronimo.j2ee.deployment.WebModule; -import org.apache.geronimo.j2ee.deployment.WebServiceBuilder; -import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory; -import org.apache.geronimo.jaxws.PortInfo; -import org.apache.geronimo.kernel.GBeanAlreadyExistsException; -import org.apache.geronimo.kernel.GBeanNotFoundException; -import org.apache.geronimo.kernel.classloader.JarFileClassLoader; -import org.apache.geronimo.kernel.repository.Environment; -import org.apache.xbean.finder.ClassFinder; - -import javax.jws.WebService; -import javax.xml.ws.WebServiceProvider; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.lang.reflect.Modifier; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.ArrayList; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.jar.JarEntry; -import java.util.jar.JarFile; - -public abstract class JAXWSServiceBuilder implements WebServiceBuilder { - private static final Log LOG = LogFactory.getLog(JAXWSServiceBuilder.class); - protected final Environment defaultEnvironment; - private static final String KEY = JAXWSServiceBuilder.class.getName(); - - public JAXWSServiceBuilder(Environment defaultEnvironment) { - this.defaultEnvironment = defaultEnvironment; - } - - public void findWebServices(JarFile moduleFile, - boolean isEJB, - Map servletLocations, - Environment environment, - Map sharedContext) throws DeploymentException { - Map portMap = null; - String path = isEJB ? "META-INF/webservices.xml" : "WEB-INF/webservices.xml"; - try { - URL wsDDUrl = DeploymentUtil.createJarURL(moduleFile, path); - InputStream in = wsDDUrl.openStream(); - portMap = parseWebServiceDescriptor(in, wsDDUrl, moduleFile, isEJB, servletLocations); - } catch (IOException e) { - // webservices.xml does not exist, search classes for annotations - portMap = discoverWebServices(moduleFile, isEJB, servletLocations); - } - - if (portMap != null) { - EnvironmentBuilder.mergeEnvironments(environment, defaultEnvironment); - sharedContext.put(KEY, portMap); - } - - } - - private Map discoverWebServices(JarFile moduleFile, - boolean isEJB, - Map correctedPortLocations) - throws DeploymentException { - LOG.debug("Discovering web service classes"); - - File tmpDir = null; - List urlList = new ArrayList(); - if (isEJB) { - File jarFile = new File(moduleFile.getName()); - try { - urlList.add(jarFile.toURL()); - } catch (MalformedURLException e) { - // this should not happen - throw new DeploymentException(); - } - } else { - /* - * Can't get ClassLoader to load nested Jar files, so - * unpack the module Jar file and discover all nested Jar files - * within it and the classes/ directory. - */ - try { - tmpDir = DeploymentUtil.createTempDir(); - /* - * This is needed becuase DeploymentUtil.unzipToDirectory() - * always closes the passed JarFile. - */ - JarFile module = new JarFile(moduleFile.getName()); - DeploymentUtil.unzipToDirectory(module, tmpDir); - } catch (IOException e) { - if (tmpDir != null) { - DeploymentUtil.recursiveDelete(tmpDir); - } - throw new DeploymentException("Failed to expand the module archive", e); - } - - // create URL list - Enumeration jarEnum = moduleFile.entries(); - while (jarEnum.hasMoreElements()) { - JarEntry entry = jarEnum.nextElement(); - String name = entry.getName(); - if (name.equals("WEB-INF/classes/")) { - // ensure it is first - File classesDir = new File(tmpDir, "WEB-INF/classes/"); - try { - urlList.add(0, classesDir.toURL()); - } catch (MalformedURLException e) { - // this should not happen, ignore - } - } else if (name.startsWith("WEB-INF/lib/") - && name.endsWith(".jar")) { - File jarFile = new File(tmpDir, name); - try { - urlList.add(jarFile.toURL()); - } catch (MalformedURLException e) { - // this should not happen, ignore - } - } - } - } - - URL[] urls = urlList.toArray(new URL[] {}); - JarFileClassLoader tempClassLoader = new JarFileClassLoader(null, urls, this.getClass().getClassLoader()); - ClassFinder classFinder = new ClassFinder(tempClassLoader, urlList); - - Map map = null; - List classes = null; - - classes = classFinder.findAnnotatedClasses(WebService.class); - map = updatePortMap(classes, map, correctedPortLocations); - classes = classFinder.findAnnotatedClasses(WebServiceProvider.class); - map = updatePortMap(classes, map, correctedPortLocations); - - tempClassLoader.destroy(); - - if (tmpDir != null) { - DeploymentUtil.recursiveDelete(tmpDir); - } - - return map; - } - - private static Map updatePortMap(List classes, - Map map, - Map correctedPortLocations) { - for (Class clazz : classes) { - if (isProperWebService(clazz)) { - LOG.debug("Found web service class: " + clazz.getName()); - if (map == null) { - map = new HashMap(); - } - PortInfo portInfo = new PortInfo(); - String location = (String) correctedPortLocations.get(clazz.getName()); - portInfo.setLocation(location); - map.put(clazz.getName(), portInfo); - } - } - return map; - } - - private static boolean isProperWebService(Class clazz) { - int modifiers = clazz.getModifiers(); - return (Modifier.isPublic(modifiers) && - !Modifier.isFinal(modifiers) && - !Modifier.isAbstract(modifiers)); - } - - protected abstract Map parseWebServiceDescriptor(InputStream in, - URL wsDDUrl, - JarFile moduleFile, - boolean isEJB, - Map correctedPortLocations) - throws DeploymentException; - - public boolean configurePOJO(GBeanData targetGBean, - String servletName, - Module module, - String seiClassName, - DeploymentContext context) - throws DeploymentException { - Map sharedContext = ((WebModule) module).getSharedContext(); - Map portInfoMap = (Map) sharedContext.get(KEY); - if (portInfoMap == null) { - // not ours - return false; - } - PortInfo portInfo = (PortInfo) portInfoMap.get(servletName); - if (portInfo == null) { - // not ours - return false; - } - - Map componentContext = null; - try { - GBeanData moduleGBean = context.getGBeanInstance(context.getModuleName()); - componentContext = (Map)moduleGBean.getAttribute("componentContext"); - } catch (GBeanNotFoundException e) { - LOG.warn("ModuleGBean not found. JNDI resource injection will not work."); - } - - LOG.info("configuring POJO webservice: " + servletName + " sei: " + seiClassName); - - // verify that the class is loadable - ClassLoader classLoader = context.getClassLoader(); - loadSEI(seiClassName, classLoader); - - AbstractName containerFactoryName = context.getNaming().createChildName(targetGBean.getAbstractName(), "cxfWebServiceContainerFactory", NameFactory.GERONIMO_SERVICE); - GBeanData containerFactoryData = new GBeanData(containerFactoryName, getContainerFactoryGBeanInfo()); - containerFactoryData.setAttribute("portInfo", portInfo); - containerFactoryData.setAttribute("endpointClassName", seiClassName); - containerFactoryData.setAttribute("componentContext", componentContext); - try { - context.addGBean(containerFactoryData); - } catch (GBeanAlreadyExistsException e) { - throw new DeploymentException("Could not add web service container factory gbean", e); - } - - targetGBean.setReferencePattern("WebServiceContainerFactory", containerFactoryName); - // our web container does not use that property - targetGBean.setAttribute("pojoClassName", "java.lang.Object"); - - if (context instanceof EARContext) { - containerFactoryData.setReferencePattern("TransactionManager", - ((EARContext)context).getTransactionManagerName()); - } - - return true; - } - - protected abstract GBeanInfo getContainerFactoryGBeanInfo(); - - public boolean configureEJB(GBeanData targetGBean, - String ejbName, - JarFile moduleFile, - Map sharedContext, - ClassLoader classLoader) - throws DeploymentException { - throw new DeploymentException("configureEJB NYI"); - } - - Class loadSEI(String className, ClassLoader loader) throws DeploymentException { - try { - return loader.loadClass(className); - } catch (ClassNotFoundException ex) { - throw new DeploymentException("unable to load Service Endpoint Interface: " + className, ex); - } - } -} +/** + * 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 org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.geronimo.common.DeploymentException; +import org.apache.geronimo.deployment.DeploymentContext; +import org.apache.geronimo.deployment.service.EnvironmentBuilder; +import org.apache.geronimo.deployment.util.DeploymentUtil; +import org.apache.geronimo.gbean.AbstractName; +import org.apache.geronimo.gbean.GBeanData; +import org.apache.geronimo.gbean.GBeanInfo; +import org.apache.geronimo.j2ee.deployment.EARContext; +import org.apache.geronimo.j2ee.deployment.Module; +import org.apache.geronimo.j2ee.deployment.WebModule; +import org.apache.geronimo.j2ee.deployment.WebServiceBuilder; +import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory; +import org.apache.geronimo.jaxws.PortInfo; +import org.apache.geronimo.kernel.GBeanAlreadyExistsException; +import org.apache.geronimo.kernel.GBeanNotFoundException; +import org.apache.geronimo.kernel.classloader.JarFileClassLoader; +import org.apache.geronimo.kernel.repository.Environment; +import org.apache.xbean.finder.ClassFinder; + +import javax.jws.WebService; +import javax.xml.ws.WebServiceProvider; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.lang.reflect.Modifier; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.jar.JarEntry; +import java.util.jar.JarFile; + +public abstract class JAXWSServiceBuilder implements WebServiceBuilder { + private static final Log LOG = LogFactory.getLog(JAXWSServiceBuilder.class); + + protected final Environment defaultEnvironment; + + public JAXWSServiceBuilder(Environment defaultEnvironment) { + this.defaultEnvironment = defaultEnvironment; + } + + protected String getKey() { + return getClass().getName(); + } + + public void findWebServices(JarFile moduleFile, + boolean isEJB, + Map servletLocations, + Environment environment, + Map sharedContext) throws DeploymentException { + Map portMap = null; + String path = isEJB ? "META-INF/webservices.xml" : "WEB-INF/webservices.xml"; + try { + URL wsDDUrl = DeploymentUtil.createJarURL(moduleFile, path); + InputStream in = wsDDUrl.openStream(); + portMap = parseWebServiceDescriptor(in, wsDDUrl, moduleFile, isEJB, servletLocations); + } catch (IOException e) { + // webservices.xml does not exist, search classes for annotations + portMap = discoverWebServices(moduleFile, isEJB, servletLocations); + } + + if (portMap != null) { + EnvironmentBuilder.mergeEnvironments(environment, defaultEnvironment); + sharedContext.put(getKey(), portMap); + } + + } + + private Map discoverWebServices(JarFile moduleFile, + boolean isEJB, + Map correctedPortLocations) + throws DeploymentException { + LOG.debug("Discovering web service classes"); + + File tmpDir = null; + List urlList = new ArrayList(); + if (isEJB) { + File jarFile = new File(moduleFile.getName()); + try { + urlList.add(jarFile.toURL()); + } catch (MalformedURLException e) { + // this should not happen + throw new DeploymentException(); + } + } else { + /* + * Can't get ClassLoader to load nested Jar files, so + * unpack the module Jar file and discover all nested Jar files + * within it and the classes/ directory. + */ + try { + tmpDir = DeploymentUtil.createTempDir(); + /* + * This is needed becuase DeploymentUtil.unzipToDirectory() + * always closes the passed JarFile. + */ + JarFile module = new JarFile(moduleFile.getName()); + DeploymentUtil.unzipToDirectory(module, tmpDir); + } catch (IOException e) { + if (tmpDir != null) { + DeploymentUtil.recursiveDelete(tmpDir); + } + throw new DeploymentException("Failed to expand the module archive", e); + } + + // create URL list + Enumeration jarEnum = moduleFile.entries(); + while (jarEnum.hasMoreElements()) { + JarEntry entry = jarEnum.nextElement(); + String name = entry.getName(); + if (name.equals("WEB-INF/classes/")) { + // ensure it is first + File classesDir = new File(tmpDir, "WEB-INF/classes/"); + try { + urlList.add(0, classesDir.toURL()); + } catch (MalformedURLException e) { + // this should not happen, ignore + } + } else if (name.startsWith("WEB-INF/lib/") + && name.endsWith(".jar")) { + File jarFile = new File(tmpDir, name); + try { + urlList.add(jarFile.toURL()); + } catch (MalformedURLException e) { + // this should not happen, ignore + } + } + } + } + + URL[] urls = urlList.toArray(new URL[] {}); + JarFileClassLoader tempClassLoader = new JarFileClassLoader(null, urls, this.getClass().getClassLoader()); + ClassFinder classFinder = new ClassFinder(tempClassLoader, urlList); + + Map map = null; + List classes = null; + + classes = classFinder.findAnnotatedClasses(WebService.class); + map = updatePortMap(classes, map, correctedPortLocations); + classes = classFinder.findAnnotatedClasses(WebServiceProvider.class); + map = updatePortMap(classes, map, correctedPortLocations); + + tempClassLoader.destroy(); + + if (tmpDir != null) { + DeploymentUtil.recursiveDelete(tmpDir); + } + + return map; + } + + private static Map updatePortMap(List classes, + Map map, + Map correctedPortLocations) { + for (Class clazz : classes) { + if (isProperWebService(clazz)) { + LOG.debug("Found web service class: " + clazz.getName()); + if (map == null) { + map = new HashMap(); + } + PortInfo portInfo = new PortInfo(); + String location = (String) correctedPortLocations.get(clazz.getName()); + portInfo.setLocation(location); + map.put(clazz.getName(), portInfo); + } + } + return map; + } + + private static boolean isProperWebService(Class clazz) { + int modifiers = clazz.getModifiers(); + return (Modifier.isPublic(modifiers) && + !Modifier.isFinal(modifiers) && + !Modifier.isAbstract(modifiers)); + } + + protected abstract Map parseWebServiceDescriptor(InputStream in, + URL wsDDUrl, + JarFile moduleFile, + boolean isEJB, + Map correctedPortLocations) + throws DeploymentException; + + public boolean configurePOJO(GBeanData targetGBean, + String servletName, + Module module, + String seiClassName, + DeploymentContext context) + throws DeploymentException { + Map sharedContext = ((WebModule) module).getSharedContext(); + Map portInfoMap = (Map) sharedContext.get(getKey()); + if (portInfoMap == null) { + // not ours + return false; + } + PortInfo portInfo = (PortInfo) portInfoMap.get(servletName); + if (portInfo == null) { + // not ours + return false; + } + + Map componentContext = null; + try { + GBeanData moduleGBean = context.getGBeanInstance(context.getModuleName()); + componentContext = (Map)moduleGBean.getAttribute("componentContext"); + } catch (GBeanNotFoundException e) { + LOG.warn("ModuleGBean not found. JNDI resource injection will not work."); + } + + LOG.info("configuring POJO webservice: " + servletName + " sei: " + seiClassName); + + // verify that the class is loadable + ClassLoader classLoader = context.getClassLoader(); + loadSEI(seiClassName, classLoader); + + AbstractName containerFactoryName = context.getNaming().createChildName(targetGBean.getAbstractName(), "cxfWebServiceContainerFactory", NameFactory.GERONIMO_SERVICE); + GBeanData containerFactoryData = new GBeanData(containerFactoryName, getContainerFactoryGBeanInfo()); + containerFactoryData.setAttribute("portInfo", portInfo); + containerFactoryData.setAttribute("endpointClassName", seiClassName); + containerFactoryData.setAttribute("componentContext", componentContext); + try { + context.addGBean(containerFactoryData); + } catch (GBeanAlreadyExistsException e) { + throw new DeploymentException("Could not add web service container factory gbean", e); + } + + targetGBean.setReferencePattern("WebServiceContainerFactory", containerFactoryName); + // our web container does not use that property + targetGBean.setAttribute("pojoClassName", "java.lang.Object"); + + if (context instanceof EARContext) { + containerFactoryData.setReferencePattern("TransactionManager", + ((EARContext)context).getTransactionManagerName()); + } + + return true; + } + + protected abstract GBeanInfo getContainerFactoryGBeanInfo(); + + public boolean configureEJB(GBeanData targetGBean, + String ejbName, + JarFile moduleFile, + Map sharedContext, + ClassLoader classLoader) + throws DeploymentException { + throw new DeploymentException("configureEJB NYI"); + } + + Class loadSEI(String className, ClassLoader loader) throws DeploymentException { + try { + return loader.loadClass(className); + } catch (ClassNotFoundException ex) { + throw new DeploymentException("unable to load Service Endpoint Interface: " + className, ex); + } + } +}