geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject svn commit: r506309 - in /geronimo/server/trunk: configs/axis2-deployer/src/plan/ configs/client-deployer/src/plan/ configs/j2ee-deployer/src/plan/ modules/geronimo-axis2-builder/src/main/java/org/apache/geronimo/axis2/builder/ modules/geronimo-axis2/s...
Date Mon, 12 Feb 2007 06:05:08 GMT
Author: dims
Date: Sun Feb 11 22:05:06 2007
New Revision: 506309

URL: http://svn.apache.org/viewvc?view=rev&rev=506309
Log:
Initial port of the serviceref and handler chain support (needs a lot of work/testing!)

Added:
    geronimo/server/trunk/modules/geronimo-axis2-builder/src/main/java/org/apache/geronimo/axis2/builder/Axis2ServiceRefBuilder.java
    geronimo/server/trunk/modules/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/AnnotationHandlerChainBuilder.java
    geronimo/server/trunk/modules/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/Axis2HandlerResolver.java
    geronimo/server/trunk/modules/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/GeronimoHandlerChainBuilder.java
    geronimo/server/trunk/modules/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/client/
    geronimo/server/trunk/modules/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/client/Axis2ServiceReference.java
Modified:
    geronimo/server/trunk/configs/axis2-deployer/src/plan/plan.xml
    geronimo/server/trunk/configs/client-deployer/src/plan/plan.xml
    geronimo/server/trunk/configs/j2ee-deployer/src/plan/plan.xml
    geronimo/server/trunk/modules/geronimo-axis2-builder/src/main/java/org/apache/geronimo/axis2/builder/Axis2Builder.java
    geronimo/server/trunk/modules/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/Axis2WebServiceContainer.java
    geronimo/server/trunk/modules/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/Axis2WebServiceContainerFactoryGBean.java
    geronimo/server/trunk/modules/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/Axis2WebServiceContext.java

Modified: geronimo/server/trunk/configs/axis2-deployer/src/plan/plan.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/configs/axis2-deployer/src/plan/plan.xml?view=diff&rev=506309&r1=506308&r2=506309
==============================================================================
--- geronimo/server/trunk/configs/axis2-deployer/src/plan/plan.xml (original)
+++ geronimo/server/trunk/configs/axis2-deployer/src/plan/plan.xml Sun Feb 11 22:05:06 2007
@@ -18,11 +18,11 @@
 
 <!-- $Rev: 482336 $ $Date: 2006-12-04 15:12:19 -0500 (Mon, 04 Dec 2006) $ -->
 
-<module xmlns="http://geronimo.apache.org/xml/ns/deployment-1.1">
+<module xmlns="http://geronimo.apache.org/xml/ns/deployment-${geronimoSchemaVersion}">
 
     <gbean name="Axis2Builder" class="org.apache.geronimo.axis2.builder.Axis2Builder">
         <xml-attribute name="defaultEnvironment">
-            <environment xmlns="http://geronimo.apache.org/xml/ns/deployment-1.1">
+            <environment xmlns="http://geronimo.apache.org/xml/ns/deployment-${geronimoSchemaVersion}">
                 <dependencies>
                     <dependency>
                         <groupId>org.apache.geronimo.configs</groupId>
@@ -33,5 +33,42 @@
             </environment>
         </xml-attribute>
     </gbean>
+
+    <gbean name="Axis2ServiceRefBuilder" class="org.apache.geronimo.axis2.builder.Axis2ServiceRefBuilder">
+        <attribute name="eeNamespaces">http://java.sun.com/xml/ns/javaee</attribute>
+        <xml-attribute name="defaultEnvironment">
+            <environment xmlns="http://geronimo.apache.org/xml/ns/deployment-${geronimoSchemaVersion}">
+                <dependencies>
+                    <dependency>
+                        <groupId>org.apache.geronimo.configs</groupId>
+                        <artifactId>axis2</artifactId>
+                        <type>car</type>
+                    </dependency>
+                </dependencies>
+            </environment>
+        </xml-attribute>
+        <reference name="Axis2Builder">
+            <name>Axis2Builder</name>
+        </reference>
+    </gbean>
+
+    <gbean name="Axis2ClientServiceRefBuilder" class="org.apache.geronimo.axis2.builder.Axis2ServiceRefBuilder">
+        <attribute name="eeNamespaces">http://java.sun.com/xml/ns/javaee</attribute>
+        <xml-attribute name="defaultEnvironment">
+            <environment xmlns="http://geronimo.apache.org/xml/ns/deployment-${geronimoSchemaVersion}">
+                <dependencies>
+                    <dependency>
+                        <groupId>org.apache.geronimo.modules</groupId>
+                        <artifactId>geronimo-axis2</artifactId>
+                        <type>jar</type>
+                    </dependency>
+                </dependencies>
+            </environment>
+        </xml-attribute>
+        <reference name="Axis2Builder">
+            <name>Axis2Builder</name>
+        </reference>
+    </gbean>
+
 
 </module>

Modified: geronimo/server/trunk/configs/client-deployer/src/plan/plan.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/configs/client-deployer/src/plan/plan.xml?view=diff&rev=506309&r1=506308&r2=506309
==============================================================================
--- geronimo/server/trunk/configs/client-deployer/src/plan/plan.xml (original)
+++ geronimo/server/trunk/configs/client-deployer/src/plan/plan.xml Sun Feb 11 22:05:06 2007
@@ -103,11 +103,9 @@
             <pattern>
                 <name>CXFClientServiceRefBuilder</name>
             </pattern>
-<!--
             <pattern>
                 <name>Axis2ClientServiceRefBuilder</name>
             </pattern>
--->
         </references>
     </gbean>
 

Modified: geronimo/server/trunk/configs/j2ee-deployer/src/plan/plan.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/configs/j2ee-deployer/src/plan/plan.xml?view=diff&rev=506309&r1=506308&r2=506309
==============================================================================
--- geronimo/server/trunk/configs/j2ee-deployer/src/plan/plan.xml (original)
+++ geronimo/server/trunk/configs/j2ee-deployer/src/plan/plan.xml Sun Feb 11 22:05:06 2007
@@ -155,11 +155,9 @@
             <pattern>
                 <name>CXFServiceRefBuilder</name>
             </pattern>
-<!--
             <pattern>
                 <name>Axis2ServiceRefBuilder</name>
             </pattern>
--->
         </references>
     </gbean>
 

Modified: geronimo/server/trunk/modules/geronimo-axis2-builder/src/main/java/org/apache/geronimo/axis2/builder/Axis2Builder.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-axis2-builder/src/main/java/org/apache/geronimo/axis2/builder/Axis2Builder.java?view=diff&rev=506309&r1=506308&r2=506309
==============================================================================
--- geronimo/server/trunk/modules/geronimo-axis2-builder/src/main/java/org/apache/geronimo/axis2/builder/Axis2Builder.java
(original)
+++ geronimo/server/trunk/modules/geronimo-axis2-builder/src/main/java/org/apache/geronimo/axis2/builder/Axis2Builder.java
Sun Feb 11 22:05:06 2007
@@ -25,6 +25,7 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.geronimo.axis2.Axis2WebServiceContainerFactoryGBean;
+import org.apache.geronimo.axis2.client.Axis2ServiceReference;
 import org.apache.geronimo.common.DeploymentException;
 import org.apache.geronimo.deployment.DeploymentContext;
 import org.apache.geronimo.gbean.AbstractName;
@@ -36,25 +37,29 @@
 import org.apache.geronimo.j2ee.deployment.WebServiceBuilder;
 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
 import org.apache.geronimo.jaxws.PortInfo;
+import org.apache.geronimo.jaxws.builder.EndpointInfoBuilder;
 import org.apache.geronimo.jaxws.builder.JAXWSServiceBuilder;
+import org.apache.geronimo.jaxws.client.EndpointInfo;
 import org.apache.geronimo.kernel.GBeanNotFoundException;
 import org.apache.geronimo.kernel.repository.Environment;
+import org.apache.geronimo.xbeans.geronimo.naming.GerServiceRefType;
+import org.apache.geronimo.xbeans.javaee.ServiceRefHandlerChainsType;
 
 import javax.wsdl.Definition;
 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 java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.StringWriter;
+import java.net.URI;
 import java.net.URL;
-import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
-import java.util.List;
 import java.util.Map;
 import java.util.jar.JarFile;
 
@@ -217,6 +222,48 @@
         return org.apache.axis2.jaxws.spi.Provider.class.getName();
     }
 
+    public Object createService(Class serviceInterface,
+                                Class serviceReference,
+                                URI wsdlURI,
+                                QName serviceQName,
+                                Map<Class, String> portComponentRefMap,
+                                ServiceRefHandlerChainsType handlerChains,
+                                GerServiceRefType serviceRefType,
+                                Module module,
+                                ClassLoader cl) throws DeploymentException {
+        EndpointInfoBuilder builder = new EndpointInfoBuilder(serviceInterface,
+                serviceRefType, portComponentRefMap, module.getModuleFile(),
+                wsdlURI, serviceQName);
+        builder.build();
+
+        wsdlURI = builder.getWsdlURI();
+        serviceQName = builder.getServiceQName();
+        Map<Object, EndpointInfo> seiInfoMap = builder.getEndpointInfo();
+
+        String handlerChainsXML = null;
+        try {
+            handlerChainsXML = getHanderChainAsString(handlerChains);
+        } catch (IOException e) {
+            // this should not happen
+            log.warn("Failed to serialize handler chains", e);
+        }
+
+        String serviceReferenceName = (serviceReference == null) ? null : serviceReference.getName();
+        return new Axis2ServiceReference(serviceInterface.getName(), serviceReferenceName,
 wsdlURI,
+                serviceQName, module.getModuleName(), handlerChainsXML, seiInfoMap);
+    }
+
+    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();
@@ -225,11 +272,6 @@
             }
         }
         return in;
-	}
-
-
-    private List<Handler> buildHandlerChain(org.apache.geronimo.jaxws.PortInfo portInfo)
{
-        return new ArrayList<Handler>();
     }
 
     private void processURLPattern(String contextRoot, org.apache.geronimo.jaxws.PortInfo
portInfo) throws DeploymentException {
@@ -272,5 +314,4 @@
     public static GBeanInfo getGBeanInfo() {
         return GBEAN_INFO;
     }
-
 }

Added: geronimo/server/trunk/modules/geronimo-axis2-builder/src/main/java/org/apache/geronimo/axis2/builder/Axis2ServiceRefBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-axis2-builder/src/main/java/org/apache/geronimo/axis2/builder/Axis2ServiceRefBuilder.java?view=auto&rev=506309
==============================================================================
--- geronimo/server/trunk/modules/geronimo-axis2-builder/src/main/java/org/apache/geronimo/axis2/builder/Axis2ServiceRefBuilder.java
(added)
+++ geronimo/server/trunk/modules/geronimo-axis2-builder/src/main/java/org/apache/geronimo/axis2/builder/Axis2ServiceRefBuilder.java
Sun Feb 11 22:05:06 2007
@@ -0,0 +1,59 @@
+package org.apache.geronimo.axis2.builder;
+
+import org.apache.geronimo.jaxws.builder.JAXWSServiceRefBuilder;
+import org.apache.geronimo.kernel.repository.Environment;
+import org.apache.geronimo.xbeans.javaee.ServiceRefType;
+import org.apache.geronimo.xbeans.geronimo.naming.GerServiceRefType;
+import org.apache.geronimo.j2ee.deployment.Module;
+import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
+import org.apache.geronimo.common.DeploymentException;
+import org.apache.geronimo.gbean.GBeanInfo;
+import org.apache.geronimo.gbean.GBeanInfoBuilder;
+import org.apache.geronimo.naming.deployment.ServiceRefBuilder;
+
+import javax.xml.namespace.QName;
+import java.net.URI;
+import java.util.Map;
+
+public class Axis2ServiceRefBuilder extends JAXWSServiceRefBuilder {
+
+    private final Axis2Builder axis2Builder;
+
+    public Axis2ServiceRefBuilder(Environment defaultEnvironment,
+                                String[] eeNamespaces,
+                                Axis2Builder axis2Builder) {
+        super(defaultEnvironment, eeNamespaces);
+        this.axis2Builder = axis2Builder;
+    }
+
+    public Object createService(ServiceRefType serviceRef, GerServiceRefType gerServiceRef,
+                                Module module, ClassLoader cl, Class serviceInterfaceClass,
+                                QName serviceQName, URI wsdlURI, Class serviceReferenceType,
+                                Map<Class, String> portComponentRefMap) throws DeploymentException
{
+        return this.axis2Builder.createService(serviceInterfaceClass, serviceReferenceType,
wsdlURI,
+                                             serviceQName, portComponentRefMap, serviceRef.getHandlerChains(),
+                                             gerServiceRef, module, cl);
+    }
+
+    public static final GBeanInfo GBEAN_INFO;
+
+    static {
+        GBeanInfoBuilder infoBuilder = GBeanInfoBuilder.createStatic(
+                Axis2ServiceRefBuilder.class, NameFactory.MODULE_BUILDER);
+        infoBuilder.addInterface(ServiceRefBuilder.class);
+        infoBuilder.addAttribute("defaultEnvironment", Environment.class, true,
+                true);
+        infoBuilder.addAttribute("eeNamespaces", String[].class, true, true);
+        infoBuilder.addReference("Axis2Builder", Axis2Builder.class,
+                NameFactory.MODULE_BUILDER);
+
+        infoBuilder.setConstructor(new String[] { "defaultEnvironment",
+                "eeNamespaces", "Axis2Builder" });
+
+        GBEAN_INFO = infoBuilder.getBeanInfo();
+    }
+
+    public static GBeanInfo getGBeanInfo() {
+        return Axis2ServiceRefBuilder.GBEAN_INFO;
+    }
+}

Added: geronimo/server/trunk/modules/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/AnnotationHandlerChainBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/AnnotationHandlerChainBuilder.java?view=auto&rev=506309
==============================================================================
--- geronimo/server/trunk/modules/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/AnnotationHandlerChainBuilder.java
(added)
+++ geronimo/server/trunk/modules/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/AnnotationHandlerChainBuilder.java
Sun Feb 11 22:05:06 2007
@@ -0,0 +1,196 @@
+/**
+ * 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.axis2;
+
+import org.apache.axis2.jaxws.javaee.HandlerChainType;
+import org.apache.axis2.jaxws.javaee.HandlerChainsType;
+import org.apache.axis2.jaxws.javaee.PortComponentHandlerType;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.jws.HandlerChain;
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBElement;
+import javax.xml.bind.Unmarshaller;
+import javax.xml.ws.WebServiceException;
+import javax.xml.ws.handler.Handler;
+import javax.xml.ws.handler.LogicalHandler;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+
+public class AnnotationHandlerChainBuilder {
+
+    private static final Log log = LogFactory.getLog(AnnotationHandlerChainBuilder.class);
+
+    public AnnotationHandlerChainBuilder() {
+    }
+
+    /**
+     * @param clz
+     * @param existingHandlers
+     * @return
+     */
+    public List<Handler> buildHandlerChainFromClass(Class<?> clz, List<Handler>
existingHandlers) {
+        log.debug("building handler chain");
+        HandlerChainAnnotation hcAnn = findHandlerChainAnnotation(clz);
+        List<Handler> chain = null;
+        if (hcAnn == null) {
+            log.debug("no HandlerChain annotation on " + clz);
+            chain = new ArrayList<Handler>();
+        } else {
+            hcAnn.validate();
+
+            HandlerChainType hc = null;
+            try {
+                JAXBContext jc = JAXBContext
+                        .newInstance(org.apache.axis2.jaxws.javaee.ObjectFactory.class);
+                Unmarshaller u = jc.createUnmarshaller();
+                URL handlerFileURL = clz.getResource(hcAnn.getFileName());
+                JAXBElement<?> o = (JAXBElement<?>) u.unmarshal(handlerFileURL);
+
+                HandlerChainsType handlerChainsType = (HandlerChainsType) o.getValue();
+
+                if (null == handlerChainsType || handlerChainsType.getHandlerChain().size()
== 0) {
+                    throw new WebServiceException("Chain not specified");
+                }
+                //We expect only one HandlerChainType here
+                hc = (HandlerChainType) handlerChainsType.getHandlerChain().iterator().next();
+            } catch (Exception e) {
+                e.printStackTrace();
+                throw new WebServiceException("Chain not specified", e);
+            }
+
+            chain = buildHandlerChain(hc, clz.getClassLoader());
+        }
+        assert chain != null;
+        if (existingHandlers != null) {
+            chain.addAll(existingHandlers);
+        }
+        return sortHandlers(chain);
+    }
+
+    public List<Handler> buildHandlerChainFromClass(Class<?> clz) {
+        return buildHandlerChainFromClass(clz, null);
+    }
+
+    private HandlerChainAnnotation findHandlerChainAnnotation(Class<?> clz) {
+
+        HandlerChain ann = clz.getAnnotation(HandlerChain.class);
+        Class<?> declaringClass = clz;
+
+        if (ann == null) {
+            for (Class<?> iface : clz.getInterfaces()) {
+                if (log.isDebugEnabled()) {
+                    log.debug("checking for HandlerChain annotation on " + iface.getName());
+                }
+                ann = iface.getAnnotation(HandlerChain.class);
+                if (ann != null) {
+                    declaringClass = iface;
+                    break;
+                }
+            }
+        }
+        if (ann != null) {
+            return new HandlerChainAnnotation(ann, declaringClass);
+        } else {
+            return null;
+        }
+    }
+
+    protected List<Handler> buildHandlerChain(HandlerChainType hc, ClassLoader classLoader)
{
+        List<Handler> handlerChain = new ArrayList<Handler>();
+        for (PortComponentHandlerType ht : hc.getHandler()) {
+            try {
+                log.debug("loading handler :" + trimString(ht.getHandlerName().getValue()));
+
+                Class<? extends Handler> handlerClass = Class.forName(
+                        trimString(ht.getHandlerClass()
+                                .getValue()), true, classLoader)
+                        .asSubclass(Handler.class);
+
+                Handler handler = handlerClass.newInstance();
+                log.debug("adding handler to chain: " + handler);
+                handlerChain.add(handler);
+            } catch (Exception e) {
+                throw new WebServiceException("Failed to instantiate handler", e);
+            }
+        }
+        return handlerChain;
+    }
+
+    private String trimString(String str) {
+        return str != null ? str.trim() : null;
+    }
+
+    /**
+     * sorts the handlers into correct order. All of the logical handlers first
+     * followed by the protocol handlers
+     *
+     * @param handlers
+     * @return sorted list of handlers
+     */
+    public List<Handler> sortHandlers(List<Handler> handlers) {
+
+        List<LogicalHandler> logicalHandlers = new ArrayList<LogicalHandler>();
+        List<Handler> protocolHandlers = new ArrayList<Handler>();
+
+        for (Handler handler : handlers) {
+            if (handler instanceof LogicalHandler) {
+                logicalHandlers.add((LogicalHandler) handler);
+            } else {
+                protocolHandlers.add(handler);
+            }
+        }
+
+        List<Handler> sortedHandlers = new ArrayList<Handler>();
+        sortedHandlers.addAll(logicalHandlers);
+        sortedHandlers.addAll(protocolHandlers);
+        return sortedHandlers;
+    }
+
+    private static class HandlerChainAnnotation {
+        private final Class<?> declaringClass;
+        private final HandlerChain ann;
+
+        HandlerChainAnnotation(HandlerChain hc, Class<?> clz) {
+            ann = hc;
+            declaringClass = clz;
+        }
+
+        public Class<?> getDeclaringClass() {
+            return declaringClass;
+        }
+
+        public String getFileName() {
+            return ann.file();
+        }
+
+        public void validate() {
+            if (null == ann.file() || "".equals(ann.file())) {
+                throw new WebServiceException("@HandlerChain annotation does not contain
a file name or url.");
+            }
+        }
+
+        public String toString() {
+            return "[" + declaringClass + "," + ann + "]";
+        }
+    }
+}

Added: geronimo/server/trunk/modules/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/Axis2HandlerResolver.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/Axis2HandlerResolver.java?view=auto&rev=506309
==============================================================================
--- geronimo/server/trunk/modules/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/Axis2HandlerResolver.java
(added)
+++ geronimo/server/trunk/modules/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/Axis2HandlerResolver.java
Sun Feb 11 22:05:06 2007
@@ -0,0 +1,64 @@
+package org.apache.geronimo.axis2;
+
+import org.apache.axis2.jaxws.javaee.HandlerChainType;
+import org.apache.axis2.jaxws.javaee.HandlerChainsType;
+import org.apache.geronimo.jaxws.annotations.AnnotationException;
+import org.apache.geronimo.jaxws.annotations.AnnotationProcessor;
+
+import javax.xml.ws.WebServiceException;
+import javax.xml.ws.handler.Handler;
+import javax.xml.ws.handler.HandlerResolver;
+import java.util.ArrayList;
+import java.util.List;
+
+public class Axis2HandlerResolver implements HandlerResolver {
+
+    private HandlerChainsType handlerChains;
+
+    private ClassLoader classLoader;
+
+    private Class serviceClass;
+
+    private AnnotationProcessor annotationProcessor;
+
+    public Axis2HandlerResolver(ClassLoader classLoader,
+                                Class serviceClass,
+                                HandlerChainsType handlerChains,
+                                AnnotationProcessor annotationProcessor) {
+        this.classLoader = classLoader;
+        this.serviceClass = serviceClass;
+        this.handlerChains = handlerChains;
+        this.annotationProcessor = annotationProcessor;
+    }
+
+    public List<Handler> getHandlerChain(javax.xml.ws.handler.PortInfo portInfo) {
+
+        GeronimoHandlerChainBuilder builder =
+                new GeronimoHandlerChainBuilder(this.classLoader, portInfo);
+
+        List<Handler> handlers = null;
+        if (this.handlerChains == null) {
+            handlers = builder.buildHandlerChainFromClass(this.serviceClass);
+        } else {
+            handlers = new ArrayList<Handler>();
+            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-axis2/src/main/java/org/apache/geronimo/axis2/Axis2WebServiceContainer.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/Axis2WebServiceContainer.java?view=diff&rev=506309&r1=506308&r2=506309
==============================================================================
--- geronimo/server/trunk/modules/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/Axis2WebServiceContainer.java
(original)
+++ geronimo/server/trunk/modules/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/Axis2WebServiceContainer.java
Sun Feb 11 22:05:06 2007
@@ -17,30 +17,6 @@
 
 package org.apache.geronimo.axis2;
 
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.io.StringBufferInputStream;
-import java.io.StringReader;
-import java.lang.reflect.Method;
-import java.net.URI;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.CountDownLatch;
-
-import javax.wsdl.Definition;
-import javax.wsdl.Port;
-import javax.wsdl.Service;
-import javax.wsdl.factory.WSDLFactory;
-import javax.wsdl.xml.WSDLWriter;
-import javax.xml.namespace.QName;
-import javax.xml.ws.WebServiceException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import javax.servlet.ServletContext;
-
 import org.apache.axiom.om.OMElement;
 import org.apache.axiom.om.OMNamespace;
 import org.apache.axiom.om.util.UUIDGenerator;
@@ -51,6 +27,8 @@
 import org.apache.axis2.context.ConfigurationContextFactory;
 import org.apache.axis2.context.MessageContext;
 import org.apache.axis2.context.OperationContext;
+import org.apache.axis2.context.ServiceContext;
+import org.apache.axis2.context.ServiceGroupContext;
 import org.apache.axis2.description.AxisMessage;
 import org.apache.axis2.description.AxisOperation;
 import org.apache.axis2.description.AxisService;
@@ -62,6 +40,8 @@
 import org.apache.axis2.description.WSDL20ToAxisServiceBuilder;
 import org.apache.axis2.description.WSDLToAxisServiceBuilder;
 import org.apache.axis2.engine.AxisEngine;
+import org.apache.axis2.engine.DependencyManager;
+import org.apache.axis2.jaxws.binding.BindingImpl;
 import org.apache.axis2.jaxws.description.DescriptionFactory;
 import org.apache.axis2.jaxws.description.EndpointDescription;
 import org.apache.axis2.jaxws.description.ServiceDescription;
@@ -75,6 +55,7 @@
 import org.apache.axis2.jaxws.description.builder.WebServiceAnnot;
 import org.apache.axis2.jaxws.description.builder.WsdlComposite;
 import org.apache.axis2.jaxws.description.builder.WsdlGenerator;
+import org.apache.axis2.jaxws.javaee.HandlerChainsType;
 import org.apache.axis2.jaxws.server.JAXWSMessageReceiver;
 import org.apache.axis2.transport.OutTransportInfo;
 import org.apache.axis2.transport.RequestResponseTransport;
@@ -88,9 +69,38 @@
 import org.apache.axis2.wsdl.WSDLUtil;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.geronimo.jaxws.JAXWSAnnotationProcessor;
+import org.apache.geronimo.jaxws.JNDIResolver;
+import org.apache.geronimo.jaxws.ServerJNDIResolver;
+import org.apache.geronimo.jaxws.annotations.AnnotationException;
 import org.apache.geronimo.webservices.WebServiceContainer;
 import org.apache.ws.commons.schema.XmlSchema;
 
+import javax.naming.Context;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.wsdl.Definition;
+import javax.wsdl.Port;
+import javax.wsdl.Service;
+import javax.wsdl.factory.WSDLFactory;
+import javax.wsdl.xml.WSDLWriter;
+import javax.xml.namespace.QName;
+import javax.xml.ws.WebServiceException;
+import javax.xml.ws.handler.Handler;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.StringBufferInputStream;
+import java.io.StringReader;
+import java.lang.reflect.Method;
+import java.net.URI;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.CountDownLatch;
 
 
 public class Axis2WebServiceContainer implements WebServiceContainer {
@@ -107,16 +117,23 @@
     private String contextRoot = null;
     private Map servicesMap;
     private Definition wsdlDefinition;
-    
-    
-    public Axis2WebServiceContainer(org.apache.geronimo.jaxws.PortInfo portInfo, String endpointClassName,
Definition wsdlDefinition, ClassLoader classLoader) {
+    private JNDIResolver jndiResolver;
+    private JAXWSAnnotationProcessor annotationProcessor;
+    private Object endpointInstance;
+    private List<Handler> chain;
+    private AxisService service;
+
+    public Axis2WebServiceContainer(org.apache.geronimo.jaxws.PortInfo portInfo,
+                                    String endpointClassName,
+                                    Definition wsdlDefinition,
+                                    ClassLoader classLoader,
+                                    Context context,
+                                    URL configurationBaseUrl) {
         this.classLoader = classLoader;
         this.endpointClassName = endpointClassName;
         this.portInfo = portInfo;
         this.wsdlDefinition = wsdlDefinition;
         try {
-            AxisService service = null;
-            
             configurationContext = ConfigurationContextFactory.createDefaultConfigurationContext();
             configurationContext.setServicePath(portInfo.getLocation());
           
@@ -174,7 +191,8 @@
     	 		
            	 	for(Iterator<AxisOperation> opIterator = service.getOperations() ; opIterator.hasNext()
;){
            	 		AxisOperation operation = opIterator.next();
-           	 		operation.setMessageReceiver(JAXWSMessageReceiver.class.newInstance());
+                        JAXWSMessageReceiver receiver = JAXWSMessageReceiver.class.newInstance();
+                        operation.setMessageReceiver(receiver);
            	 		
            	 		for(Method method : classMethods){
            	 			// TODO Is this correct method?
@@ -261,16 +279,17 @@
             	service = AxisService.createService(endpointClassName, configurationContext.getAxisConfiguration(),
JAXWSMessageReceiver.class);
             }
 
+            service.setScope(Constants.SCOPE_APPLICATION);
             configurationContext.getAxisConfiguration().addService(service);
-            
+
         } catch (AxisFault af) {
             throw new RuntimeException(af);
         } catch (Exception e) {
             throw new RuntimeException(e);
         }
+        jndiResolver = new ServerJNDIResolver(context);
     }
 
-    
     public void getWsdl(Request request, Response response) throws Exception {
         doService(request, response);
     }
@@ -511,6 +530,15 @@
             }
 
         } else if (request.getMethod() == Request.POST) {
+            msgContext.setAxisService(service);
+            configurationContext.fillServiceContextAndServiceGroupContext(msgContext);
+            ServiceGroupContext serviceGroupContext = msgContext.getServiceGroupContext();
+            DependencyManager.initService(serviceGroupContext);
+            endpointInstance = msgContext.getServiceContext().getProperty(ServiceContext.SERVICE_OBJECT);
+
+            BindingImpl binding = new BindingImpl("GeronimoBinding");
+            binding.setHandlerChain(chain);
+            msgContext.setProperty(JAXWSMessageReceiver.PARAM_BINDING, binding);
             // deal with POST request
             msgContext.setProperty(MessageContext.TRANSPORT_OUT, response.getOutputStream());
             msgContext.setProperty(Constants.OUT_TRANSPORT_INFO, new Axis2TransportInfo(response));
@@ -533,14 +561,22 @@
             msgContext.setProperty(HTTPConstants.MC_HTTP_SERVLETCONTEXT, servletContext);
             
             String contenttype = request.getHeader(HTTPConstants.HEADER_CONTENT_TYPE);
-            HTTPTransportUtils.processHTTPPostRequest(
-                    msgContext,
-                    request.getInputStream(),
-                    response.getOutputStream(),
-                    contenttype,
-                    soapAction,
-                    path);
 
+            annotationProcessor = new JAXWSAnnotationProcessor(jndiResolver,
+                    new Axis2WebServiceContext(msgContext));
+
+            init();
+            try {
+                HTTPTransportUtils.processHTTPPostRequest(
+                        msgContext,
+                        request.getInputStream(),
+                        response.getOutputStream(),
+                        contenttype,
+                        soapAction,
+                        path);
+            } finally {
+                stop();
+            }
         } else {
             throw new UnsupportedOperationException("[" + request.getMethod() + " ] method
not supported");
         }
@@ -567,7 +603,7 @@
     }
     
     public void destroy() {
-	}
+    }
     
     /**
      * Resolves the Axis Service associated with the endPointClassName
@@ -688,6 +724,54 @@
     		composite.setWsdlDefinition(testMap);
     		return composite;
     	}
+    }
+
+    protected void init() {
+        // configure and inject handlers
+        try {
+            configureHandlers();
+        } catch (Exception e) {
+            throw new WebServiceException("Error configuring handlers", e);
+        }
+
+        // inject resources into service
+        try {
+            injectResources(endpointInstance);
+        } catch (AnnotationException e) {
+            throw new WebServiceException("Service resource injection failed", e);
+        }
+    }
+
+    /*
+     * Gets the right handlers for the port/service/bindings and
+     * performs injection.
+     */
+    protected void configureHandlers() throws Exception {
+        HandlerChainsType handlerChains = this.portInfo.getHandlers(HandlerChainsType.class);
+        Axis2HandlerResolver handlerResolver =
+            new Axis2HandlerResolver(endpointInstance.getClass().getClassLoader(),
+                                   endpointInstance.getClass(),
+                                   handlerChains,
+                                   this.annotationProcessor);
+
+
+        // TODO: pass non-null PortInfo to get the right handlers
+        chain = handlerResolver.getHandlerChain(null);
+    }
+
+    public void stop() {
+        // call handlers preDestroy
+        for (Handler handler : chain) {
+            this.annotationProcessor.invokePreDestroy(handler);
+        }
+
+        // call service preDestroy
+        this.annotationProcessor.invokePreDestroy(endpointInstance);
+    }
+
+    private void injectResources(Object instance) throws AnnotationException {
+        this.annotationProcessor.processAnnotations(instance);
+        this.annotationProcessor.invokePostConstruct(instance);
     }
 
 }

Modified: geronimo/server/trunk/modules/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/Axis2WebServiceContainerFactoryGBean.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/Axis2WebServiceContainerFactoryGBean.java?view=diff&rev=506309&r1=506308&r2=506309
==============================================================================
--- geronimo/server/trunk/modules/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/Axis2WebServiceContainerFactoryGBean.java
(original)
+++ geronimo/server/trunk/modules/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/Axis2WebServiceContainerFactoryGBean.java
Sun Feb 11 22:05:06 2007
@@ -72,10 +72,11 @@
         this.classLoader = classLoader;
         this.endpointClassName = endpointClassName;
         this.wsdlDefinition = wsdlDefinition;
+        this.configurationBaseUrl = configurationBaseUrl;
     }
 
     public WebServiceContainer getWebServiceContainer() {
-        return new Axis2WebServiceContainer(portInfo, endpointClassName, wsdlDefinition,
classLoader);
+        return new Axis2WebServiceContainer(portInfo, endpointClassName, wsdlDefinition,
classLoader, context, configurationBaseUrl);
     }
 
     public static final GBeanInfo GBEAN_INFO;

Modified: geronimo/server/trunk/modules/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/Axis2WebServiceContext.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/Axis2WebServiceContext.java?view=diff&rev=506309&r1=506308&r2=506309
==============================================================================
--- geronimo/server/trunk/modules/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/Axis2WebServiceContext.java
(original)
+++ geronimo/server/trunk/modules/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/Axis2WebServiceContext.java
Sun Feb 11 22:05:06 2007
@@ -1,6 +1,7 @@
 package org.apache.geronimo.axis2;
 
 import org.apache.axis2.transport.http.HTTPConstants;
+import org.apache.axis2.jaxws.handler.LogicalMessageContext;
 
 import javax.xml.ws.WebServiceContext;
 import javax.xml.ws.handler.MessageContext;
@@ -15,8 +16,8 @@
 
     private MessageContext ctx;
 
-    public Axis2WebServiceContext(MessageContext ctx) {
-        this.ctx = ctx;
+    public Axis2WebServiceContext(org.apache.axis2.context.MessageContext ctx) {
+        this.ctx = new LogicalMessageContext(new org.apache.axis2.jaxws.core.MessageContext(ctx));
     }
     
     public final MessageContext getMessageContext() {

Added: geronimo/server/trunk/modules/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/GeronimoHandlerChainBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/GeronimoHandlerChainBuilder.java?view=auto&rev=506309
==============================================================================
--- geronimo/server/trunk/modules/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/GeronimoHandlerChainBuilder.java
(added)
+++ geronimo/server/trunk/modules/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/GeronimoHandlerChainBuilder.java
Sun Feb 11 22:05:06 2007
@@ -0,0 +1,101 @@
+package org.apache.geronimo.axis2;
+
+import org.apache.axis2.jaxws.javaee.HandlerChainType;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.xml.namespace.QName;
+import javax.xml.ws.handler.Handler;
+import javax.xml.ws.handler.PortInfo;
+import java.util.Collections;
+import java.util.List;
+
+public class GeronimoHandlerChainBuilder extends AnnotationHandlerChainBuilder {
+    private static final Log log = LogFactory.getLog(GeronimoHandlerChainBuilder.class);
+
+    private ClassLoader classLoader = null;
+    private javax.xml.ws.handler.PortInfo portInfo;
+
+    public GeronimoHandlerChainBuilder(ClassLoader classloader,
+                                       PortInfo portInfo) {
+        this.classLoader = classloader;
+        this.portInfo = portInfo;
+    }
+
+    public ClassLoader getHandlerClassLoader() {
+        return this.classLoader;
+    }
+
+    protected List<Handler> 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);
+        }
+    }
+
+    public List<Handler> buildHandlerChainFromConfiguration(HandlerChainType hc) {
+        if (null == hc) {
+            return null;
+        }
+        return sortHandlers(buildHandlerChain(hc, getHandlerClassLoader()));
+    }
+
+    /*
+     * 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-axis2/src/main/java/org/apache/geronimo/axis2/client/Axis2ServiceReference.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/client/Axis2ServiceReference.java?view=auto&rev=506309
==============================================================================
--- geronimo/server/trunk/modules/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/client/Axis2ServiceReference.java
(added)
+++ geronimo/server/trunk/modules/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/client/Axis2ServiceReference.java
Sun Feb 11 22:05:06 2007
@@ -0,0 +1,52 @@
+package org.apache.geronimo.axis2.client;
+
+import org.apache.axis2.jaxws.context.WebServiceContextImpl;
+import org.apache.axis2.jaxws.javaee.HandlerChainsType;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.geronimo.axis2.Axis2HandlerResolver;
+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.JAXWSServiceReference;
+
+import javax.xml.bind.JAXBException;
+import javax.xml.namespace.QName;
+import javax.xml.ws.handler.HandlerResolver;
+import java.net.URI;
+import java.util.Map;
+
+public class Axis2ServiceReference extends JAXWSServiceReference {
+
+    private static final Log log = LogFactory.getLog(Axis2ServiceReference.class);
+
+    public Axis2ServiceReference(String serviceClassName,
+                                 String referenceClassName,
+                                 URI wsdlURI,
+                                 QName serviceQName,
+                                 AbstractName name,
+                                 String handlerChainsXML,
+                                 Map<Object, EndpointInfo> seiInfoMap) {
+        super(handlerChainsXML, seiInfoMap, name, serviceQName, wsdlURI, referenceClassName,
serviceClassName);
+    }
+
+    protected 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;
+        }
+    }
+
+    protected HandlerResolver getHandlerResolver(Class serviceClass) {
+        JAXWSAnnotationProcessor annotationProcessor =
+                new JAXWSAnnotationProcessor(new JNDIResolver(), new WebServiceContextImpl());
+        Axis2HandlerResolver handlerResolver =
+                new Axis2HandlerResolver(classLoader, serviceClass, getHandlerChains(), annotationProcessor);
+        return handlerResolver;
+    }
+}



Mime
View raw message