tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject svn commit: r591858 [8/13] - in /openejb/trunk/openejb3: ./ assembly/openejb-tomcat/ assembly/openejb-tomcat/src/main/java/org/apache/openejb/tomcat/ container/openejb-core/ container/openejb-core/src/main/java/org/apache/openejb/ container/openejb-cor...
Date Sun, 04 Nov 2007 22:42:06 GMT
Added: openejb/trunk/openejb3/server/openejb-axis2/pom.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/server/openejb-axis2/pom.xml?rev=591858&view=auto
==============================================================================
--- openejb/trunk/openejb3/server/openejb-axis2/pom.xml (added)
+++ openejb/trunk/openejb3/server/openejb-axis2/pom.xml Sun Nov  4 14:41:49 2007
@@ -0,0 +1,145 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    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.
+-->
+
+<!-- $Rev: 579722 $ $Date: 2007-09-26 10:25:44 -0700 (Wed, 26 Sep 2007) $ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <parent>
+    <artifactId>server</artifactId>
+    <groupId>org.apache.openejb</groupId>
+    <version>3.0.0-SNAPSHOT</version>
+  </parent>
+  <modelVersion>4.0.0</modelVersion>
+  <artifactId>openejb-axis2</artifactId>
+  <packaging>jar</packaging>
+  <name>OpenEJB :: Server :: Axis2</name>
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.openejb</groupId>
+      <artifactId>openejb-webservices</artifactId>
+      <version>${version}</version>
+    </dependency>
+
+    <!-- maven is dropping this dep for some strange reason, so include it explicitly -->
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <scope>test</scope>
+    </dependency>
+
+    <dependency>
+      <groupId>org.apache.axis2</groupId>
+      <artifactId>axis2-jaxws</artifactId>
+      <version>1.3</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.axis2</groupId>
+      <artifactId>axis2-java2wsdl</artifactId>
+      <version>1.3</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.axis2</groupId>
+      <artifactId>axis2-kernel</artifactId>
+      <version>1.3</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.axis2</groupId>
+      <artifactId>axis2-adb</artifactId>
+      <version>1.3</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.axis2</groupId>
+      <artifactId>axis2-metadata</artifactId>
+      <version>1.3</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.ws.commons.axiom</groupId>
+      <artifactId>axiom-api</artifactId>
+      <version>1.2.5</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.ws.commons.axiom</groupId>
+      <artifactId>axiom-impl</artifactId>
+      <version>1.2.5</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.ws.commons.schema</groupId>
+      <artifactId>XmlSchema</artifactId>
+      <version>1.3.1</version>
+    </dependency>
+    <dependency>
+        <groupId>org.apache.neethi</groupId>
+        <artifactId>neethi</artifactId>
+        <version>2.0</version>
+        <exclusions>
+            <exclusion>
+                <groupId>org.apache.ws.commons.axiom</groupId>
+                <artifactId>axiom-impl</artifactId>
+            </exclusion>
+            <exclusion>
+                <groupId>org.apache.ws.commons.axiom</groupId>
+                <artifactId>axiom-api</artifactId>
+            </exclusion>
+        </exclusions>
+    </dependency>
+    <dependency>
+        <groupId>commons-httpclient</groupId>
+        <artifactId>commons-httpclient</artifactId>
+        <version>3.0.1</version>
+        <exclusions>
+            <exclusion>
+                <groupId>junit</groupId>
+                <artifactId>junit</artifactId>
+            </exclusion>
+        </exclusions>
+    </dependency>
+    <dependency>
+        <groupId>commons-codec</groupId>
+        <artifactId>commons-codec</artifactId>
+        <version>1.3</version>
+        <exclusions>
+            <exclusion>
+                <groupId>junit</groupId>
+                <artifactId>junit</artifactId>
+            </exclusion>
+        </exclusions>
+    </dependency>
+    <dependency>
+        <groupId>org.apache.xmlbeans</groupId>
+        <artifactId>xmlbeans</artifactId>
+        <version>2.3.0</version>
+    </dependency>
+    <dependency>
+        <groupId>jaxen</groupId>
+        <artifactId>jaxen</artifactId>
+        <version>1.1-beta-10</version>
+    </dependency>
+
+    <dependency>
+        <groupId>annogen</groupId>
+        <artifactId>annogen</artifactId>
+        <version>0.1.0</version>
+    </dependency>
+
+
+  </dependencies>
+
+</project>
+

Added: openejb/trunk/openejb3/server/openejb-axis2/src/main/java/org/apache/openejb/server/axis2/Axis2RequestResponseTransport.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/server/openejb-axis2/src/main/java/org/apache/openejb/server/axis2/Axis2RequestResponseTransport.java?rev=591858&view=auto
==============================================================================
--- openejb/trunk/openejb3/server/openejb-axis2/src/main/java/org/apache/openejb/server/axis2/Axis2RequestResponseTransport.java (added)
+++ openejb/trunk/openejb3/server/openejb-axis2/src/main/java/org/apache/openejb/server/axis2/Axis2RequestResponseTransport.java Sun Nov  4 14:41:49 2007
@@ -0,0 +1,95 @@
+/**
+ * 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.openejb.server.axis2;
+
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.transport.RequestResponseTransport;
+import org.apache.openejb.server.httpd.HttpResponse;
+import org.apache.openejb.util.Logger;
+import org.apache.openejb.util.LogCategory;
+
+import java.io.IOException;
+import java.net.HttpURLConnection;
+import java.util.concurrent.CountDownLatch;
+
+public class Axis2RequestResponseTransport implements RequestResponseTransport {
+    private static final Logger logger = Logger.getInstance(LogCategory.AXIS2, Axis2RequestResponseTransport.class);
+
+    private HttpResponse response;
+
+    private CountDownLatch responseReadySignal = new CountDownLatch(1);
+
+    private RequestResponseTransportStatus status = RequestResponseTransportStatus.INITIAL;
+
+    private AxisFault faultToBeThrownOut = null;
+
+    private boolean responseWritten;
+
+    Axis2RequestResponseTransport(HttpResponse response) {
+        this.response = response;
+    }
+
+    public void acknowledgeMessage(MessageContext msgContext) throws AxisFault {
+        logger.debug("acknowledgeMessage");
+        logger.debug("Acking one-way request");
+
+        response.setContentType("text/xml; charset=" + msgContext.getProperty("message.character-set-encoding"));
+
+        response.setStatusCode(HttpURLConnection.HTTP_ACCEPTED);
+        try {
+            response.flushBuffer();
+        } catch (IOException e) {
+            throw new AxisFault("Error sending acknowledgement", e);
+        }
+
+        signalResponseReady();
+    }
+
+    public void awaitResponse() throws InterruptedException, AxisFault {
+        logger.debug("Blocking servlet thread -- awaiting response");
+        status = RequestResponseTransportStatus.WAITING;
+        responseReadySignal.await();
+        if (faultToBeThrownOut != null) {
+            throw faultToBeThrownOut;
+        }
+    }
+
+    public void signalFaultReady(AxisFault fault) {
+        faultToBeThrownOut = fault;
+        signalResponseReady();
+    }
+
+    public void signalResponseReady() {
+        logger.debug("Signalling response available");
+        status = RequestResponseTransportStatus.SIGNALLED;
+        responseReadySignal.countDown();
+    }
+
+    public RequestResponseTransportStatus getStatus() {
+        return status;
+    }
+
+    public boolean isResponseWritten() {
+        return responseWritten;
+    }
+
+    public void setResponseWritten(boolean responseWritten) {
+        this.responseWritten = responseWritten;
+    }
+}

Added: openejb/trunk/openejb3/server/openejb-axis2/src/main/java/org/apache/openejb/server/axis2/Axis2Service.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/server/openejb-axis2/src/main/java/org/apache/openejb/server/axis2/Axis2Service.java?rev=591858&view=auto
==============================================================================
--- openejb/trunk/openejb3/server/openejb-axis2/src/main/java/org/apache/openejb/server/axis2/Axis2Service.java (added)
+++ openejb/trunk/openejb3/server/openejb-axis2/src/main/java/org/apache/openejb/server/axis2/Axis2Service.java Sun Nov  4 14:41:49 2007
@@ -0,0 +1,66 @@
+/**
+ *
+ * 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.openejb.server.axis2;
+
+import org.apache.openejb.DeploymentInfo;
+import org.apache.openejb.core.webservices.PortData;
+import org.apache.openejb.server.httpd.HttpListener;
+import org.apache.openejb.server.axis2.ejb.EjbWsContainer;
+import org.apache.openejb.server.axis2.pojo.PojoWsContainer;
+import org.apache.openejb.server.webservices.WsService;
+
+import javax.naming.Context;
+import java.net.URL;
+import java.util.Map;
+import java.util.TreeMap;
+
+public class Axis2Service extends WsService {
+    private final Map<String, Axis2WsContainer> wsContainers = new TreeMap<String, Axis2WsContainer>();
+
+    public String getName() {
+        return "axis2";
+    }
+
+    protected HttpListener createEjbWsContainer(URL moduleBaseUrl, PortData port, DeploymentInfo deploymentInfo) throws Exception {
+        EjbWsContainer container = new EjbWsContainer(port, deploymentInfo);
+        container.start();
+        wsContainers.put(deploymentInfo.getDeploymentID().toString(), container);
+        return container;
+    }
+
+    protected void destroyEjbWsContainer(String deploymentId) {
+        Axis2WsContainer container = wsContainers.remove(deploymentId);
+        if (container != null) {
+            container.destroy();
+        }
+    }
+
+    protected HttpListener createPojoWsContainer(URL moduleBaseUrl, PortData port, String serviceId, Class target, Context context, String contextRoot) throws Exception {
+        PojoWsContainer container = new PojoWsContainer(port, target, context, contextRoot);
+        container.start();
+        wsContainers.put(serviceId, container);
+        return container;
+    }
+
+    protected void destroyPojoWsContainer(String serviceId) {
+        Axis2WsContainer container = wsContainers.remove(serviceId);
+        if (container != null) {
+            container.destroy();
+        }
+    }
+}

Added: openejb/trunk/openejb3/server/openejb-axis2/src/main/java/org/apache/openejb/server/axis2/Axis2WsContainer.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/server/openejb-axis2/src/main/java/org/apache/openejb/server/axis2/Axis2WsContainer.java?rev=591858&view=auto
==============================================================================
--- openejb/trunk/openejb3/server/openejb-axis2/src/main/java/org/apache/openejb/server/axis2/Axis2WsContainer.java (added)
+++ openejb/trunk/openejb3/server/openejb-axis2/src/main/java/org/apache/openejb/server/axis2/Axis2WsContainer.java Sun Nov  4 14:41:49 2007
@@ -0,0 +1,355 @@
+/**
+ * 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.openejb.server.axis2;
+
+import org.apache.axiom.om.util.UUIDGenerator;
+import org.apache.axis2.Constants;
+import org.apache.axis2.addressing.AddressingHelper;
+import org.apache.axis2.addressing.EndpointReference;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.context.ConfigurationContextFactory;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.context.OperationContext;
+import org.apache.axis2.description.AxisService;
+import org.apache.axis2.description.TransportInDescription;
+import org.apache.axis2.description.TransportOutDescription;
+import org.apache.axis2.engine.AxisEngine;
+import org.apache.axis2.engine.Handler.InvocationResponse;
+import org.apache.axis2.jaxws.description.EndpointDescription;
+import org.apache.axis2.jaxws.description.impl.DescriptionUtils;
+import org.apache.axis2.jaxws.handler.lifecycle.factory.HandlerLifecycleManagerFactory;
+import org.apache.axis2.jaxws.registry.FactoryRegistry;
+import org.apache.axis2.transport.OutTransportInfo;
+import org.apache.axis2.transport.RequestResponseTransport;
+import org.apache.axis2.transport.http.HTTPConstants;
+import org.apache.axis2.transport.http.HTTPTransportReceiver;
+import org.apache.axis2.transport.http.HTTPTransportUtils;
+import org.apache.axis2.transport.http.TransportHeaders;
+import org.apache.axis2.transport.http.util.RESTUtil;
+import org.apache.axis2.util.MessageContextBuilder;
+import org.apache.openejb.core.webservices.HandlerResolverImpl;
+import org.apache.openejb.core.webservices.PortData;
+import org.apache.openejb.server.axis2.client.Axis2Config;
+import org.apache.openejb.server.httpd.HttpRequest;
+import org.apache.openejb.server.httpd.HttpResponse;
+import org.apache.openejb.server.httpd.HttpListener;
+import org.apache.openejb.server.webservices.WsConstants;
+import org.apache.openejb.server.webservices.saaj.SaajUniverse;
+import org.apache.openejb.util.Logger;
+import org.apache.openejb.util.LogCategory;
+
+import javax.naming.Context;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.xml.ws.handler.Handler;
+import java.io.PrintWriter;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.util.List;
+
+public abstract class Axis2WsContainer implements HttpListener {
+    private static final Logger logger = Logger.getInstance(LogCategory.AXIS2, Axis2WsContainer.class);
+
+    public static final String REQUEST = Axis2WsContainer.class.getName() + "@Request";
+    public static final String RESPONSE = Axis2WsContainer.class.getName() + "@Response";
+
+    protected String endpointClassName;
+    protected PortData port;
+    protected ConfigurationContext configurationContext;
+    protected final Class<?> endpointClass;
+    protected AxisService service;
+    protected WsdlQueryHandler wsdlQueryHandler;
+    protected Context context;
+    private HandlerResolverImpl handlerResolver;
+
+    public Axis2WsContainer(PortData port, Class<?> endpointClass, Context context) {
+        this.endpointClass = endpointClass;
+        this.port = port;
+        this.context = context;
+    }
+
+    public void start() throws Exception {
+        Axis2Config.initialize();
+
+        configurationContext = ConfigurationContextFactory.createBasicConfigurationContext("META-INF/openejb-axis2.xml");
+
+        AxisServiceGenerator serviceGen = createServiceGenerator();
+        if (port.getWsdlUrl() != null) {
+            // WSDL file has been provided
+            service = serviceGen.getServiceFromWSDL(port, endpointClass);
+        } else {
+            // No WSDL, let Axis2 handle it.
+            service = serviceGen.getServiceFromClass(endpointClass);
+        }
+
+        service.setScope(Constants.SCOPE_APPLICATION);
+        configurationContext.getAxisConfiguration().addService(service);
+
+        wsdlQueryHandler = new WsdlQueryHandler(service);
+
+        /*
+        * This replaces HandlerLifecycleManagerFactory for all web services.
+        * This should be ok as we do our own handler instance managment and injection.
+        * Also, this does not affect service-ref clients, as we install our own
+        * HandlerResolver.
+        */
+        FactoryRegistry.setFactory(HandlerLifecycleManagerFactory.class, new HandlerLifecycleManagerFactoryImpl());
+    }
+
+    protected AxisServiceGenerator createServiceGenerator() {
+        return new AxisServiceGenerator();
+    }
+
+    public void getWsdl(HttpRequest request, HttpResponse response) throws Exception {
+        doService(request, response);
+    }
+
+    public void onMessage(HttpRequest request, HttpResponse response) throws Exception {
+        SaajUniverse universe = new SaajUniverse();
+        universe.set(SaajUniverse.AXIS2);
+        try {
+            doService(request, response);
+        } finally {
+            universe.unset();
+        }
+    }
+
+    protected void doService(HttpRequest request, HttpResponse response) throws Exception {
+
+        if (logger.isDebugEnabled()) {
+            logger.debug("Target URI: " + request.getURI());
+        }
+
+        MessageContext msgContext = new MessageContext();
+        msgContext.setIncomingTransportName(Constants.TRANSPORT_HTTP);
+        msgContext.setProperty(MessageContext.REMOTE_ADDR, request.getRemoteAddr());
+
+        try {
+            TransportOutDescription transportOut = this.configurationContext.getAxisConfiguration()
+                    .getTransportOut(Constants.TRANSPORT_HTTP);
+            TransportInDescription transportIn = this.configurationContext.getAxisConfiguration()
+                    .getTransportIn(Constants.TRANSPORT_HTTP);
+
+            msgContext.setConfigurationContext(this.configurationContext);
+
+            //TODO: Port this segment for session support.
+//            String sessionKey = (String) this.httpcontext.getAttribute(HTTPConstants.COOKIE_STRING);
+//            if (this.configurationContext.getAxisConfiguration().isManageTransportSession()) {
+//                SessionContext sessionContext = this.sessionManager.getSessionContext(sessionKey);
+//                msgContext.setSessionContext(sessionContext);
+//            }
+            msgContext.setTransportIn(transportIn);
+            msgContext.setTransportOut(transportOut);
+            msgContext.setServiceGroupContextId(UUIDGenerator.getUUID());
+            msgContext.setServerSide(true);
+            msgContext.setAxisService(this.service);
+
+            doService2(request, response, msgContext);
+        } catch (Throwable e) {
+            String msg = "Exception occurred while trying to invoke service method doService()";
+            logger.error(msg, e);
+            try {
+                msgContext.setProperty(MessageContext.TRANSPORT_OUT, response.getOutputStream());
+                msgContext.setProperty(Constants.OUT_TRANSPORT_INFO, new Axis2TransportInfo(response));
+
+                MessageContext faultContext = MessageContextBuilder.createFaultMessageContext(msgContext, e);
+                // If the fault is not going along the back channel we should be 202ing
+                if (AddressingHelper.isFaultRedirected(msgContext)) {
+                    response.setStatusCode(HttpURLConnection.HTTP_ACCEPTED);
+                } else {
+                    response.setStatusCode(HttpURLConnection.HTTP_INTERNAL_ERROR);
+                }
+                AxisEngine.sendFault(faultContext);
+            } catch (Exception ex) {
+                if (AddressingHelper.isFaultRedirected(msgContext)) {
+                    response.setStatusCode(HttpURLConnection.HTTP_ACCEPTED);
+                } else {
+                    response.setStatusCode(HttpURLConnection.HTTP_INTERNAL_ERROR);
+                    response.setHeader(HTTPConstants.HEADER_CONTENT_TYPE, "text/plain");
+                    PrintWriter pw = new PrintWriter(response.getOutputStream());
+                    ex.printStackTrace(pw);
+                    pw.flush();
+                    logger.error(msg, ex);
+                }
+            }
+        }
+
+    }
+
+    protected String getServicePath(String contextRoot) {
+        String location = port.getLocation();
+        if (location != null && location.startsWith(contextRoot)) {
+            return location.substring(contextRoot.length());
+        }
+        return null;
+    }
+
+    public static String trimContext(String contextPath) {
+        if (contextPath != null) {
+            if (contextPath.startsWith("/")) {
+                contextPath = contextPath.substring(1);
+            }
+            if (contextPath.endsWith("/")) {
+                contextPath = contextPath.substring(0, contextPath.length() - 1);
+            }
+        }
+        return contextPath;
+    }
+
+    public void doService2(HttpRequest request, HttpResponse response, MessageContext msgContext) throws Exception {
+
+        if (request.getMethod() == HttpRequest.GET) {
+            processGETRequest(request, response, this.service, msgContext);
+        } else if (request.getMethod() == HttpRequest.POST) {
+            processPOSTRequest(request, response, this.service, msgContext);
+        } else {
+            throw new UnsupportedOperationException("[" + request.getMethod() + " ] method not supported");
+        }
+
+        // Finalize response
+        OperationContext operationContext = msgContext.getOperationContext();
+        Object contextWritten = null;
+        Object isTwoChannel = null;
+        if (operationContext != null) {
+            contextWritten = operationContext.getProperty(Constants.RESPONSE_WRITTEN);
+            isTwoChannel = operationContext.getProperty(Constants.DIFFERENT_EPR);
+        }
+
+        if ((contextWritten != null) && Constants.VALUE_TRUE.equals(contextWritten)) {
+            if ((isTwoChannel != null) && Constants.VALUE_TRUE.equals(isTwoChannel)) {
+                response.setStatusCode(HttpURLConnection.HTTP_ACCEPTED);
+                return;
+            }
+            response.setStatusCode(HttpURLConnection.HTTP_OK);
+        } else {
+            response.setStatusCode(HttpURLConnection.HTTP_ACCEPTED);
+        }
+    }
+
+    public void destroy() {
+    }
+
+    public static class Axis2TransportInfo implements OutTransportInfo {
+        private HttpResponse response;
+
+        public Axis2TransportInfo(HttpResponse response) {
+            this.response = response;
+        }
+
+        public void setContentType(String contentType) {
+            response.setHeader(HTTPConstants.HEADER_CONTENT_TYPE, contentType);
+        }
+    }
+
+    protected void processGETRequest(HttpRequest request, HttpResponse response, AxisService service, MessageContext msgContext) throws Exception {
+        if (request.getURI().getQuery() != null && (request.getURI().getQuery().startsWith("wsdl") || request.getURI().getQuery().startsWith("xsd"))) {
+            // wsdl or xsd request
+
+            if (port.getWsdlUrl() != null) {
+                URL wsdlURL = port.getWsdlUrl();
+                this.wsdlQueryHandler.writeResponse(request.getURI().toString(), wsdlURL.toString(), response.getOutputStream());
+            } else {
+                service.printWSDL(response.getOutputStream());
+            }
+        } else if (AxisServiceGenerator.isSOAP11(service)) {
+            response.setContentType("text/html");
+            PrintWriter pw = new PrintWriter(response.getOutputStream());
+            pw.write("<html><title>Web Service</title><body>");
+            pw.write("Hi, this is '" + service.getName() + "' web service.");
+            pw.write("</body></html>");
+            pw.flush();
+        } else {
+            // REST request
+            setMsgContextProperties(request, response, service, msgContext);
+
+            String contentType = request.getHeader(HTTPConstants.HEADER_CONTENT_TYPE);
+
+            msgContext.setTo(new EndpointReference(request.getURI().toString()));
+
+            msgContext.setProperty(MessageContext.TRANSPORT_OUT, response.getOutputStream());
+            msgContext.setProperty(Constants.OUT_TRANSPORT_INFO, new Axis2TransportInfo(response));
+
+            InvocationResponse processed = RESTUtil.processURLRequest(msgContext, response.getOutputStream(), contentType);
+
+            if (!processed.equals(InvocationResponse.CONTINUE)) {
+                response.setStatusCode(HttpURLConnection.HTTP_OK);
+                String s = HTTPTransportReceiver.getServicesHTML(configurationContext);
+                PrintWriter pw = new PrintWriter(response.getOutputStream());
+                pw.write(s);
+                pw.flush();
+            }
+        }
+    }
+
+    protected void setMsgContextProperties(HttpRequest request, HttpResponse response, AxisService service, MessageContext msgContext) {
+        msgContext.setProperty(MessageContext.TRANSPORT_OUT, response.getOutputStream());
+        msgContext.setProperty(Constants.OUT_TRANSPORT_INFO, new Axis2TransportInfo(response));
+        msgContext.setProperty(RequestResponseTransport.TRANSPORT_CONTROL, new Axis2RequestResponseTransport(response));
+        msgContext.setProperty(Constants.Configuration.TRANSPORT_IN_URL, request.getURI().toString());
+        msgContext.setIncomingTransportName(Constants.TRANSPORT_HTTP);
+
+        HttpServletRequest servletRequest = (HttpServletRequest) request.getAttribute(WsConstants.SERVLET_REQUEST);
+        msgContext.setProperty(HTTPConstants.MC_HTTP_SERVLETREQUEST, servletRequest);
+
+        HttpServletResponse servletResponse = (HttpServletResponse) request.getAttribute(WsConstants.SERVLET_RESPONSE);
+        msgContext.setProperty(HTTPConstants.MC_HTTP_SERVLETRESPONSE, servletResponse);
+
+        ServletContext servletContext = (ServletContext) request.getAttribute(WsConstants.SERVLET_CONTEXT);
+        msgContext.setProperty(HTTPConstants.MC_HTTP_SERVLETCONTEXT, servletContext);
+
+        if (servletRequest != null) {
+            msgContext.setProperty(MessageContext.TRANSPORT_HEADERS, new TransportHeaders(servletRequest));
+        }
+    }
+
+    protected void processPOSTRequest(HttpRequest request, HttpResponse response, AxisService service, MessageContext msgContext) throws Exception {
+        String contentType = request.getHeader(HTTPConstants.HEADER_CONTENT_TYPE);
+        String soapAction = request.getHeader(HTTPConstants.HEADER_SOAP_ACTION);
+        if (soapAction == null) {
+            soapAction = "\"\"";
+        }
+
+        ConfigurationContext configurationContext = msgContext.getConfigurationContext();
+        configurationContext.fillServiceContextAndServiceGroupContext(msgContext);
+
+        setMsgContextProperties(request, response, service, msgContext);
+
+        HTTPTransportUtils.processHTTPPostRequest(msgContext, request.getInputStream(), response.getOutputStream(), contentType, soapAction, request.getURI().getPath());
+    }
+
+    /*
+    * Gets the right handlers for the port/service/bindings and performs injection.
+    */
+    protected void configureHandlers() throws Exception {
+        EndpointDescription desc = AxisServiceGenerator.getEndpointDescription(this.service);
+        if (desc != null) {
+            handlerResolver = new HandlerResolverImpl(port.getHandlerChains(), port.getInjections(), context);
+            List<Handler> handlers = handlerResolver.getHandlerChain(port);
+
+            DescriptionUtils.registerHandlerHeaders(desc.getAxisService(), handlers);
+        }
+    }
+
+    protected void destroyHandlers() {
+        if (this.handlerResolver != null) {
+            handlerResolver.destroyHandlers();
+            handlerResolver = null;
+        }
+    }
+}

Added: openejb/trunk/openejb3/server/openejb-axis2/src/main/java/org/apache/openejb/server/axis2/AxisServiceGenerator.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/server/openejb-axis2/src/main/java/org/apache/openejb/server/axis2/AxisServiceGenerator.java?rev=591858&view=auto
==============================================================================
--- openejb/trunk/openejb3/server/openejb-axis2/src/main/java/org/apache/openejb/server/axis2/AxisServiceGenerator.java (added)
+++ openejb/trunk/openejb3/server/openejb-axis2/src/main/java/org/apache/openejb/server/axis2/AxisServiceGenerator.java Sun Nov  4 14:41:49 2007
@@ -0,0 +1,275 @@
+/**
+ * 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.openejb.server.axis2;
+
+import org.apache.axis2.Constants;
+import org.apache.axis2.description.AxisOperation;
+import org.apache.axis2.description.AxisService;
+import org.apache.axis2.description.Parameter;
+import org.apache.axis2.description.java2wsdl.Java2WSDLConstants;
+import org.apache.axis2.engine.MessageReceiver;
+import org.apache.axis2.jaxws.description.DescriptionFactory;
+import org.apache.axis2.jaxws.description.EndpointDescription;
+import org.apache.axis2.jaxws.description.ServiceDescription;
+import org.apache.axis2.jaxws.description.builder.BindingTypeAnnot;
+import org.apache.axis2.jaxws.description.builder.DescriptionBuilderComposite;
+import org.apache.axis2.jaxws.description.builder.MethodDescriptionComposite;
+import org.apache.axis2.jaxws.description.builder.WebServiceAnnot;
+import org.apache.axis2.jaxws.description.builder.WebServiceProviderAnnot;
+import org.apache.axis2.jaxws.description.builder.WsdlComposite;
+import org.apache.axis2.jaxws.description.builder.WsdlGenerator;
+import org.apache.axis2.jaxws.description.builder.converter.JavaClassToDBCConverter;
+import org.apache.axis2.jaxws.server.JAXWSMessageReceiver;
+import org.apache.axis2.wsdl.WSDLUtil;
+import org.apache.openejb.core.webservices.JaxWsUtils;
+import org.apache.openejb.core.webservices.PortData;
+import org.apache.openejb.server.axis2.util.SimpleWsdlLocator;
+import org.apache.ws.commons.schema.utils.NamespaceMap;
+
+import javax.wsdl.Binding;
+import javax.wsdl.Definition;
+import javax.wsdl.Port;
+import javax.wsdl.Service;
+import javax.wsdl.WSDLException;
+import javax.wsdl.extensions.http.HTTPBinding;
+import javax.wsdl.extensions.soap.SOAPBinding;
+import javax.wsdl.extensions.soap12.SOAP12Binding;
+import javax.wsdl.factory.WSDLFactory;
+import javax.wsdl.xml.WSDLReader;
+import javax.xml.namespace.QName;
+import javax.xml.ws.WebServiceException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+
+public class AxisServiceGenerator {
+    private MessageReceiver messageReceiver;
+
+    public AxisServiceGenerator() {
+        this.messageReceiver = new JAXWSMessageReceiver();
+    }
+
+    public void setMessageReceiver(MessageReceiver messageReceiver) {
+        this.messageReceiver = messageReceiver;
+    }
+
+    public AxisService getServiceFromClass(Class endpointClass) throws Exception {
+        ServiceDescription serviceDescription = DescriptionFactory.createServiceDescription(endpointClass);
+        EndpointDescription[] edArray = serviceDescription.getEndpointDescriptions();
+        AxisService service = edArray[0].getAxisService();
+
+        if (service.getNameSpacesMap() == null) {
+            NamespaceMap map = new NamespaceMap();
+            map.put(Java2WSDLConstants.AXIS2_NAMESPACE_PREFIX, Java2WSDLConstants.AXIS2_XSD);
+            map.put(Java2WSDLConstants.DEFAULT_SCHEMA_NAMESPACE_PREFIX, Java2WSDLConstants.URI_2001_SCHEMA_XSD);
+            service.setNameSpacesMap(map);
+        }
+
+        String endpointClassName = endpointClass.getName();
+        ClassLoader classLoader = endpointClass.getClassLoader();
+
+        service.addParameter(new Parameter(Constants.SERVICE_CLASS, endpointClassName));
+        service.setClassLoader(classLoader);
+
+        for (Iterator<AxisOperation> opIterator = service.getOperations(); opIterator.hasNext();) {
+            AxisOperation operation = opIterator.next();
+            operation.setMessageReceiver(this.messageReceiver);
+        }
+
+        Parameter serviceDescriptionParam = new Parameter(EndpointDescription.AXIS_SERVICE_PARAMETER, edArray[0]);
+        service.addParameter(serviceDescriptionParam);
+
+        return service;
+    }
+
+    public AxisService getServiceFromWSDL(PortData portData, Class endpointClass) throws Exception {
+        if (portData.getWsdlUrl() == null) {
+            throw new Exception("WSDL file is required.");
+        }
+
+        String endpointClassName = endpointClass.getName();
+        ClassLoader classLoader = endpointClass.getClassLoader();
+
+        QName serviceQName = portData.getWsdlService();
+        if (serviceQName == null) {
+            serviceQName = JaxWsUtils.getServiceQName(endpointClass);
+        }
+
+        QName portQName = portData.getWsdlPort();
+        if (portQName == null) {
+            portQName = JaxWsUtils.getPortQName(endpointClass);
+        }
+
+        Definition wsdlDefinition = readWSDL(portData.getWsdlUrl());
+
+        Service wsdlService = wsdlDefinition.getService(serviceQName);
+        if (wsdlService == null) {
+            throw new Exception("Service '" + serviceQName + "' not found in WSDL");
+        }
+
+        Port port = wsdlService.getPort(portQName.getLocalPart());
+        if (port == null) {
+            throw new Exception("Port '" + portQName.getLocalPart() + "' not found in WSDL");
+        }
+
+        Binding binding = port.getBinding();
+        List extElements = binding.getExtensibilityElements();
+        Iterator extElementsIterator = extElements.iterator();
+        String bindingS = javax.xml.ws.soap.SOAPBinding.SOAP11HTTP_BINDING; //this is the default.
+        while (extElementsIterator.hasNext()) {
+            Object o = extElementsIterator.next();
+            if (o instanceof SOAPBinding) {
+                SOAPBinding sp = (SOAPBinding) o;
+                if (sp.getElementType().getNamespaceURI().equals("http://schemas.xmlsoap.org/wsdl/soap/")) {
+                    //todo:  how to we tell if it is MTOM or not.
+                    bindingS = javax.xml.ws.soap.SOAPBinding.SOAP11HTTP_BINDING;
+                }
+            } else if (o instanceof SOAP12Binding) {
+                SOAP12Binding sp = (SOAP12Binding) o;
+                if (sp.getElementType().getNamespaceURI().equals("http://schemas.xmlsoap.org/wsdl/soap12/")) {
+                    //todo:  how to we tell if it is MTOM or not.
+                    bindingS = javax.xml.ws.soap.SOAPBinding.SOAP12HTTP_BINDING;
+                }
+            } else if (o instanceof HTTPBinding) {
+                HTTPBinding sp = (HTTPBinding) o;
+                if (sp.getElementType().getNamespaceURI().equals("http://www.w3.org/2004/08/wsdl/http")) {
+                    bindingS = javax.xml.ws.http.HTTPBinding.HTTP_BINDING;
+                }
+            }
+        }
+
+        Class endPointClass = classLoader.loadClass(endpointClassName);
+        JavaClassToDBCConverter converter = new JavaClassToDBCConverter(endPointClass);
+        HashMap<String, DescriptionBuilderComposite> dbcMap = converter.produceDBC();
+
+        DescriptionBuilderComposite dbc = dbcMap.get(endpointClassName);
+        dbc.setClassLoader(classLoader);
+        dbc.setWsdlDefinition(wsdlDefinition);
+        dbc.setClassName(endpointClassName);
+        dbc.setCustomWsdlGenerator(new WSDLGeneratorImpl(wsdlDefinition));
+
+        if (dbc.getWebServiceAnnot() != null) { //information specified in .wsdl should overwrite annotation.
+            WebServiceAnnot serviceAnnot = dbc.getWebServiceAnnot();
+            serviceAnnot.setPortName(portQName.getLocalPart());
+            serviceAnnot.setServiceName(serviceQName.getLocalPart());
+            serviceAnnot.setTargetNamespace(serviceQName.getNamespaceURI());
+            if (dbc.getBindingTypeAnnot() != null && bindingS != null && !bindingS.equals("")) {
+                BindingTypeAnnot bindingAnnot = dbc.getBindingTypeAnnot();
+                bindingAnnot.setValue(bindingS);
+            }
+        } else if (dbc.getWebServiceProviderAnnot() != null) {
+            WebServiceProviderAnnot serviceProviderAnnot = dbc.getWebServiceProviderAnnot();
+            serviceProviderAnnot.setPortName(portQName.getLocalPart());
+            serviceProviderAnnot.setServiceName(serviceQName.getLocalPart());
+            serviceProviderAnnot.setTargetNamespace(serviceQName.getNamespaceURI());
+            if (dbc.getBindingTypeAnnot() != null && bindingS != null && !bindingS.equals("")) {
+                BindingTypeAnnot bindingAnnot = dbc.getBindingTypeAnnot();
+                bindingAnnot.setValue(bindingS);
+            }
+        }
+
+        AxisService service = getService(dbcMap);
+
+        service.setName(serviceQName.getLocalPart());
+        service.setEndpointName(portQName.getLocalPart());
+
+        for (Iterator<AxisOperation> opIterator = service.getOperations(); opIterator.hasNext();) {
+            AxisOperation operation = opIterator.next();
+            operation.setMessageReceiver(this.messageReceiver);
+            String MEP = operation.getMessageExchangePattern();
+            if (!WSDLUtil.isOutputPresentForMEP(MEP)) {
+                List<MethodDescriptionComposite> mdcList = dbc.getMethodDescriptionComposite(operation.getName().toString());
+                for (Iterator<MethodDescriptionComposite> mIterator = mdcList.iterator(); mIterator.hasNext();) {
+                    MethodDescriptionComposite mdc = mIterator.next();
+                    //TODO: JAXWS spec says need to check Holder param exist before taking a method as OneWay
+                    mdc.setOneWayAnnot(true);
+                }
+            }
+        }
+
+        return service;
+    }
+
+    private AxisService getService(HashMap<String, DescriptionBuilderComposite> dbcMap) {
+        return getEndpointDescription(dbcMap).getAxisService();
+    }
+
+    private EndpointDescription getEndpointDescription(HashMap<String, DescriptionBuilderComposite> dbcMap) {
+        List<ServiceDescription> serviceDescList = DescriptionFactory.createServiceDescriptionFromDBCMap(dbcMap);
+        if (serviceDescList == null || serviceDescList.isEmpty()) {
+            throw new RuntimeException("No service");
+        }
+        ServiceDescription serviceDescription = serviceDescList.get(0);
+        EndpointDescription[] edArray = serviceDescription.getEndpointDescriptions();
+        if (edArray == null || edArray.length == 0) {
+            throw new RuntimeException("No endpoint");
+        }
+        return edArray[0];
+    }
+
+    private static class WSDLGeneratorImpl implements WsdlGenerator {
+        private Definition def;
+
+        public WSDLGeneratorImpl(Definition def) {
+            this.def = def;
+        }
+
+        public WsdlComposite generateWsdl(String implClass, String bindingType) throws WebServiceException {
+            // Need WSDL generation code
+            WsdlComposite composite = new WsdlComposite();
+            composite.setWsdlFileName(implClass);
+            HashMap<String, Definition> testMap = new HashMap<String, Definition>();
+            testMap.put(composite.getWsdlFileName(), def);
+            composite.setWsdlDefinition(testMap);
+            return composite;
+        }
+    }
+
+    protected Definition readWSDL(URL wsdlUrl) throws IOException, WSDLException {
+        Definition wsdlDefinition = null;
+        InputStream wsdlStream = null;
+        try {
+            wsdlStream = wsdlUrl.openStream();
+            WSDLFactory factory = WSDLFactory.newInstance();
+            WSDLReader reader = factory.newWSDLReader();
+            reader.setFeature("javax.wsdl.importDocuments", true);
+            reader.setFeature("javax.wsdl.verbose", false);
+            SimpleWsdlLocator wsdlLocator = new SimpleWsdlLocator(wsdlUrl.toString());
+            wsdlDefinition = reader.readWSDL(wsdlLocator);
+        } finally {
+            if (wsdlStream != null) {
+                wsdlStream.close();
+            }
+        }
+        return wsdlDefinition;
+    }
+
+    public static EndpointDescription getEndpointDescription(AxisService service) {
+        Parameter param = service.getParameter(EndpointDescription.AXIS_SERVICE_PARAMETER);
+        return (param == null) ? null : (EndpointDescription) param.getValue();
+    }
+
+    public static boolean isSOAP11(AxisService service) {
+        EndpointDescription desc = AxisServiceGenerator.getEndpointDescription(service);
+        return javax.xml.ws.soap.SOAPBinding.SOAP11HTTP_BINDING.equals(desc.getBindingType()) || javax.xml.ws.soap.SOAPBinding.SOAP11HTTP_MTOM_BINDING.equals(desc.getBindingType());
+    }
+
+}

Added: openejb/trunk/openejb3/server/openejb-axis2/src/main/java/org/apache/openejb/server/axis2/HandlerLifecycleManagerFactoryImpl.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/server/openejb-axis2/src/main/java/org/apache/openejb/server/axis2/HandlerLifecycleManagerFactoryImpl.java?rev=591858&view=auto
==============================================================================
--- openejb/trunk/openejb3/server/openejb-axis2/src/main/java/org/apache/openejb/server/axis2/HandlerLifecycleManagerFactoryImpl.java (added)
+++ openejb/trunk/openejb3/server/openejb-axis2/src/main/java/org/apache/openejb/server/axis2/HandlerLifecycleManagerFactoryImpl.java Sun Nov  4 14:41:49 2007
@@ -0,0 +1,34 @@
+/*
+ * 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.openejb.server.axis2;
+
+import org.apache.axis2.jaxws.handler.lifecycle.factory.HandlerLifecycleManager;
+import org.apache.axis2.jaxws.handler.lifecycle.factory.HandlerLifecycleManagerFactory;
+
+public class HandlerLifecycleManagerFactoryImpl extends HandlerLifecycleManagerFactory {
+    private HandlerLifecycleManagerImpl lifecycleManager;
+
+    public HandlerLifecycleManagerFactoryImpl() {
+        this.lifecycleManager = new HandlerLifecycleManagerImpl();
+    }
+
+    public HandlerLifecycleManager createHandlerLifecycleManager() {
+        return this.lifecycleManager;        
+    }
+}

Added: openejb/trunk/openejb3/server/openejb-axis2/src/main/java/org/apache/openejb/server/axis2/HandlerLifecycleManagerImpl.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/server/openejb-axis2/src/main/java/org/apache/openejb/server/axis2/HandlerLifecycleManagerImpl.java?rev=591858&view=auto
==============================================================================
--- openejb/trunk/openejb3/server/openejb-axis2/src/main/java/org/apache/openejb/server/axis2/HandlerLifecycleManagerImpl.java (added)
+++ openejb/trunk/openejb3/server/openejb-axis2/src/main/java/org/apache/openejb/server/axis2/HandlerLifecycleManagerImpl.java Sun Nov  4 14:41:49 2007
@@ -0,0 +1,46 @@
+/*
+ * 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.openejb.server.axis2;
+
+import org.apache.axis2.jaxws.core.MessageContext;
+import org.apache.axis2.jaxws.handler.lifecycle.factory.HandlerLifecycleManager;
+import org.apache.axis2.jaxws.injection.ResourceInjectionException;
+import org.apache.axis2.jaxws.lifecycle.LifecycleException;
+
+import javax.xml.ws.handler.Handler;
+
+public class HandlerLifecycleManagerImpl implements HandlerLifecycleManager {
+    public Handler createHandlerInstance(MessageContext context, Class handlerClass) throws LifecycleException, ResourceInjectionException {
+        Handler instance = null;
+
+        try {
+            instance = (Handler) handlerClass.newInstance();
+        } catch (Exception e) {
+            throw new LifecycleException("Failed to create handler", e);
+        }
+
+        return instance;
+    }
+
+    public void invokePostConstruct() throws LifecycleException {
+    }
+
+    public void invokePreDestroy() throws LifecycleException {
+    }
+}

Added: openejb/trunk/openejb3/server/openejb-axis2/src/main/java/org/apache/openejb/server/axis2/WsdlQueryHandler.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/server/openejb-axis2/src/main/java/org/apache/openejb/server/axis2/WsdlQueryHandler.java?rev=591858&view=auto
==============================================================================
--- openejb/trunk/openejb3/server/openejb-axis2/src/main/java/org/apache/openejb/server/axis2/WsdlQueryHandler.java (added)
+++ openejb/trunk/openejb3/server/openejb-axis2/src/main/java/org/apache/openejb/server/axis2/WsdlQueryHandler.java Sun Nov  4 14:41:49 2007
@@ -0,0 +1,305 @@
+/**
+ * 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.openejb.server.axis2;
+
+import org.apache.axis2.description.AxisService;
+import org.apache.openejb.util.Logger;
+import org.apache.openejb.util.LogCategory;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+import javax.wsdl.Definition;
+import javax.wsdl.Import;
+import javax.wsdl.Port;
+import javax.wsdl.Service;
+import javax.wsdl.Types;
+import javax.wsdl.extensions.ExtensibilityElement;
+import javax.wsdl.extensions.schema.Schema;
+import javax.wsdl.extensions.schema.SchemaImport;
+import javax.wsdl.extensions.schema.SchemaReference;
+import javax.wsdl.extensions.soap.SOAPAddress;
+import javax.wsdl.extensions.soap12.SOAP12Address;
+import javax.wsdl.factory.WSDLFactory;
+import javax.wsdl.xml.WSDLReader;
+import javax.wsdl.xml.WSDLWriter;
+import javax.xml.namespace.QName;
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Source;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+import java.io.OutputStream;
+import java.net.MalformedURLException;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+public class WsdlQueryHandler {
+    private static final Logger logger = Logger.getInstance(LogCategory.AXIS2, WsdlQueryHandler.class);
+
+    private Map<String, Definition> mp = new ConcurrentHashMap<String, Definition>();
+    private Map<String, SchemaReference> smp = new ConcurrentHashMap<String, SchemaReference>();
+    private AxisService service;
+    
+    public WsdlQueryHandler(AxisService service) {
+        this.service = service;
+    }
+    
+    public void writeResponse(String baseUri, String wsdlUri, OutputStream os) throws Exception {
+        int idx = baseUri.toLowerCase().indexOf("?wsdl");
+        String base = null;
+        String wsdl = "";
+        String xsd = null;
+        if (idx != -1) {
+            base = baseUri.substring(0, baseUri.toLowerCase().indexOf("?wsdl"));
+            wsdl = baseUri.substring(baseUri.toLowerCase().indexOf("?wsdl") + 5);
+            if (wsdl.length() > 0) {
+                wsdl = wsdl.substring(1);
+            }
+        } else {
+            base = baseUri.substring(0, baseUri.toLowerCase().indexOf("?xsd="));
+            xsd = baseUri.substring(baseUri.toLowerCase().indexOf("?xsd=") + 5);
+        }
+
+        if (!mp.containsKey(wsdl)) {
+            WSDLFactory factory = WSDLFactory.newInstance();
+            WSDLReader reader = factory.newWSDLReader();
+            reader.setFeature("javax.wsdl.importDocuments", true);
+            reader.setFeature("javax.wsdl.verbose", false);
+            Definition def = reader.readWSDL(wsdlUri);
+            updateDefinition(def, mp, smp, base);
+            updateServices(this.service.getName(), this.service.getEndpointName(), def, base);
+            mp.put("", def);
+        }
+
+        Element rootElement;
+
+        if (xsd == null) {
+            Definition def = mp.get(wsdl);
+
+            WSDLFactory factory = WSDLFactory.newInstance();
+            WSDLWriter writer = factory.newWSDLWriter();
+
+            rootElement = writer.getDocument(def).getDocumentElement();
+        } else {
+            SchemaReference si = smp.get(xsd);
+            rootElement = si.getReferencedSchema().getElement();
+        }
+
+        NodeList nl = rootElement.getElementsByTagNameNS("http://www.w3.org/2001/XMLSchema",
+                "import");
+        for (int x = 0; x < nl.getLength(); x++) {
+            Element el = (Element) nl.item(x);
+            String sl = el.getAttribute("schemaLocation");
+            if (smp.containsKey(sl)) {
+                el.setAttribute("schemaLocation", base + "?xsd=" + sl);
+            }
+        }
+        nl = rootElement.getElementsByTagNameNS("http://www.w3.org/2001/XMLSchema", "include");
+        for (int x = 0; x < nl.getLength(); x++) {
+            Element el = (Element) nl.item(x);
+            String sl = el.getAttribute("schemaLocation");
+            if (smp.containsKey(sl)) {
+                el.setAttribute("schemaLocation", base + "?xsd=" + sl);
+            }
+        }
+        nl = rootElement.getElementsByTagNameNS("http://schemas.xmlsoap.org/wsdl/", "import");
+        for (int x = 0; x < nl.getLength(); x++) {
+            Element el = (Element) nl.item(x);
+            String sl = el.getAttribute("location");
+            if (mp.containsKey(sl)) {
+                el.setAttribute("location", base + "?wsdl=" + sl);
+            }
+        }
+
+        writeTo(rootElement, os);
+    }
+       
+    protected void updateDefinition(Definition def,
+                                    Map<String, Definition> done,
+                                    Map<String, SchemaReference> doneSchemas,
+                                    String base) {
+        Collection<List> imports = def.getImports().values();
+        for (List lst : imports) {
+            List<Import> impLst = lst;
+            for (Import imp : impLst) {
+                String start = imp.getLocationURI();
+                try {
+                    //check to see if it's aleady in a URL format.  If so, leave it.
+                    new URL(start);
+                } catch (MalformedURLException e) {
+                    done.put(start, imp.getDefinition());
+                    updateDefinition(imp.getDefinition(), done, doneSchemas, base);
+                }
+            }
+        }      
+        
+        
+        /* This doesn't actually work.   Setting setSchemaLocationURI on the import
+        * for some reason doesn't actually result in the new URI being written
+        * */
+        Types types = def.getTypes();
+        if (types != null) {
+            for (ExtensibilityElement el : (List<ExtensibilityElement>)types.getExtensibilityElements()) {
+                if (el instanceof Schema) {
+                    Schema see = (Schema)el;
+                    updateSchemaImports(see, doneSchemas, base);
+                }
+            }
+        }
+    }
+    
+    protected void updateSchemaImports(Schema schema,
+                                       Map<String, SchemaReference> doneSchemas,
+                                       String base) {
+        Collection<List>  imports = schema.getImports().values();
+        for (List lst : imports) {
+            List<SchemaImport> impLst = lst;
+            for (SchemaImport imp : impLst) {
+                String start = imp.getSchemaLocationURI();
+                if (start != null) {
+                    try {
+                        //check to see if it's aleady in a URL format.  If so, leave it.
+                        new URL(start);
+                    } catch (MalformedURLException e) {
+                        if (!doneSchemas.containsKey(start)) {
+                            doneSchemas.put(start, imp);
+                            updateSchemaImports(imp.getReferencedSchema(), doneSchemas, base);
+                        }
+                    }
+                }
+            }
+        }
+        List<SchemaReference> includes = schema.getIncludes();
+        for (SchemaReference included : includes) {
+            String start = included.getSchemaLocationURI();
+            if (start != null) {
+                try {
+                    //check to see if it's aleady in a URL format.  If so, leave it.
+                    new URL(start);
+                } catch (MalformedURLException e) {
+                    if (!doneSchemas.containsKey(start)) {
+                        doneSchemas.put(start, included);
+                        updateSchemaImports(included.getReferencedSchema(), doneSchemas, base);
+                    }
+                }
+            }
+        }
+    }
+    
+    public static void writeTo(Node node, OutputStream os) {
+        writeTo(new DOMSource(node), os);
+    }
+    
+    public static void writeTo(Source src, OutputStream os) {
+        Transformer it;
+        try {
+            it = TransformerFactory.newInstance().newTransformer();
+            it.setOutputProperty(OutputKeys.METHOD, "xml");
+            it.setOutputProperty(OutputKeys.INDENT, "yes");
+            it.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
+            it.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "false");
+            it.setOutputProperty(OutputKeys.ENCODING, "utf-8");
+            it.transform(src, new StreamResult(os));
+        } catch (TransformerException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+    }
+    
+    private void updateServices(String serviceName, String portName, Definition def, String baseUri)
+            throws Exception {
+        boolean updated = false;
+        Map services = def.getServices();
+        if (services != null) {
+            ArrayList<QName> servicesToRemove = new ArrayList<QName>();
+            
+            Iterator serviceIterator = services.entrySet().iterator();
+            while (serviceIterator.hasNext()) {
+                Map.Entry serviceEntry = (Map.Entry) serviceIterator.next();
+                QName currServiceName = (QName) serviceEntry.getKey();
+                if (currServiceName.getLocalPart().equals(serviceName)) {
+                    Service service = (Service) serviceEntry.getValue();
+                    updatePorts(portName, service, baseUri);
+                    updated = true;
+                } else {
+                    servicesToRemove.add(currServiceName);
+                }
+            }
+            
+            for (QName serviceToRemove : servicesToRemove) {
+                def.removeService(serviceToRemove);                
+            }
+        }
+        if (!updated) {
+            logger.warning("WSDL '" + serviceName + "' service not found.");
+        }
+    }
+
+    private void updatePorts(String portName, Service service, String baseUri) throws Exception {
+        boolean updated = false;
+        Map ports = service.getPorts();
+        if (ports != null) {
+            ArrayList<String> portsToRemove = new ArrayList<String>();
+            
+            Iterator portIterator = ports.entrySet().iterator();
+            while (portIterator.hasNext()) {
+                Map.Entry portEntry = (Map.Entry) portIterator.next();
+                String currPortName = (String) portEntry.getKey();
+                if (currPortName.equals(portName)) {
+                    Port port = (Port) portEntry.getValue();
+                    updatePortLocation(port, baseUri);
+                    updated = true;
+                } else {
+                    portsToRemove.add(currPortName);
+                }
+            }
+            
+            for (String portToRemove : portsToRemove) {
+                service.removePort(portToRemove);               
+            }
+        }
+        if (!updated) {
+            logger.warning("WSDL '" + portName + "' port not found.");
+        }
+    }
+
+    private void updatePortLocation(Port port, String baseUri) throws URISyntaxException {
+        List<?> exts = port.getExtensibilityElements();
+        if (exts != null && exts.size() > 0) {
+            ExtensibilityElement el = (ExtensibilityElement) exts.get(0);
+            if (el instanceof SOAP12Address) {
+                SOAP12Address add = (SOAP12Address) el;
+                add.setLocationURI(baseUri);
+            } else if (el instanceof SOAPAddress) {
+                SOAPAddress add = (SOAPAddress) el;
+                add.setLocationURI(baseUri);
+            }
+        }
+    }
+}

Added: openejb/trunk/openejb3/server/openejb-axis2/src/main/java/org/apache/openejb/server/axis2/client/Axis2ClientConfigurationFactory.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/server/openejb-axis2/src/main/java/org/apache/openejb/server/axis2/client/Axis2ClientConfigurationFactory.java?rev=591858&view=auto
==============================================================================
--- openejb/trunk/openejb3/server/openejb-axis2/src/main/java/org/apache/openejb/server/axis2/client/Axis2ClientConfigurationFactory.java (added)
+++ openejb/trunk/openejb3/server/openejb-axis2/src/main/java/org/apache/openejb/server/axis2/client/Axis2ClientConfigurationFactory.java Sun Nov  4 14:41:49 2007
@@ -0,0 +1,106 @@
+/**
+ * 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.openejb.server.axis2.client;
+
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.context.ConfigurationContextFactory;
+import org.apache.axis2.jaxws.ClientConfigurationFactory;
+import org.apache.axis2.jaxws.util.ClassLoaderUtils;
+import org.apache.axis2.jaxws.util.Constants;
+import org.apache.openejb.util.Logger;
+import org.apache.openejb.util.LogCategory;
+
+import java.util.Hashtable;
+import java.util.Map;
+
+public class Axis2ClientConfigurationFactory extends ClientConfigurationFactory {
+    private static final Logger logger = Logger.getInstance(LogCategory.AXIS2, Axis2ClientConfigurationFactory.class);
+
+    private Map<ClassLoader, ConfigurationContext> contextCache = new Hashtable<ClassLoader, ConfigurationContext>();
+
+    private boolean reuseConfigurationContext;
+
+    public Axis2ClientConfigurationFactory(boolean reuse) {
+        this.reuseConfigurationContext = reuse;
+    }
+
+    public ConfigurationContext getClientConfigurationContext() {
+        ClassLoader cl = ClassLoaderUtils.getContextClassLoader();
+        if (cl == null) {
+            if (this.reuseConfigurationContext) {
+                cl = ClientConfigurationFactory.class.getClassLoader();
+            } else {
+                return createConfigurationContext();
+            }
+        }
+
+        synchronized (cl) {
+            return getConfigurationContext(cl);
+        }
+    }
+
+    private ConfigurationContext getConfigurationContext(ClassLoader cl) {
+        ConfigurationContext context = this.contextCache.get(cl);
+        if (context == null) {
+            context = createConfigurationContext();
+            this.contextCache.put(cl, context);
+            if (logger.isDebugEnabled()) {
+                logger.debug("Created new configuration context " + context + "  for " + cl);
+            }
+        } else {
+            if (logger.isDebugEnabled()) {
+                logger.debug("Configuration context " + context + " reused for " + cl);
+            }
+        }
+        return context;
+    }
+
+    private ConfigurationContext removeConfigurationContext(ClassLoader cl) {
+        return this.contextCache.remove(cl);
+    }
+
+    public void clearCache() {
+        this.contextCache.clear();
+    }
+
+    public ConfigurationContext clearCache(ClassLoader cl) {
+        ConfigurationContext context = null;
+        if (cl != null) {
+            synchronized (cl) {
+                context = removeConfigurationContext(cl);
+            }
+
+            if (logger.isDebugEnabled()) {
+                logger.debug("Removed configuration context " + context + " for " + cl);
+            }
+        }
+
+        return context;
+    }
+
+    private ConfigurationContext createConfigurationContext() {
+        String repoPath = System.getProperty(Constants.AXIS2_REPO_PATH);
+        String axisConfigPath = System.getProperty(Constants.AXIS2_CONFIG_PATH);
+        try {
+            return ConfigurationContextFactory.createConfigurationContextFromFileSystem(repoPath, axisConfigPath);
+        } catch (AxisFault e) {
+            throw new RuntimeException(e.getMessage(), e);
+        }
+    }
+
+}

Added: openejb/trunk/openejb3/server/openejb-axis2/src/main/java/org/apache/openejb/server/axis2/client/Axis2Config.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/server/openejb-axis2/src/main/java/org/apache/openejb/server/axis2/client/Axis2Config.java?rev=591858&view=auto
==============================================================================
--- openejb/trunk/openejb3/server/openejb-axis2/src/main/java/org/apache/openejb/server/axis2/client/Axis2Config.java (added)
+++ openejb/trunk/openejb3/server/openejb-axis2/src/main/java/org/apache/openejb/server/axis2/client/Axis2Config.java Sun Nov  4 14:41:49 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.openejb.server.axis2.client;
+
+import org.apache.axis2.jaxws.ClientConfigurationFactory;
+import org.apache.axis2.jaxws.description.impl.DescriptionFactoryImpl;
+import org.apache.axis2.metadata.registry.MetadataFactoryRegistry;
+
+public class Axis2Config {
+    public synchronized static void initialize() {
+        ClientConfigurationFactory factory = (ClientConfigurationFactory) MetadataFactoryRegistry.getFactory(ClientConfigurationFactory.class);
+        if (factory instanceof Axis2ClientConfigurationFactory) {
+            return;
+        }
+
+        factory = new Axis2ClientConfigurationFactory(false);
+        MetadataFactoryRegistry.setFactory(ClientConfigurationFactory.class, factory);
+
+        // ensure that the factory was installed at the right time
+        if (factory != DescriptionFactoryImpl.getClientConfigurationFactory()) {
+            throw new RuntimeException("Client configuration factory was registered too late");
+        }
+    }
+}

Added: openejb/trunk/openejb3/server/openejb-axis2/src/main/java/org/apache/openejb/server/axis2/ejb/EjbEndpointController.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/server/openejb-axis2/src/main/java/org/apache/openejb/server/axis2/ejb/EjbEndpointController.java?rev=591858&view=auto
==============================================================================
--- openejb/trunk/openejb3/server/openejb-axis2/src/main/java/org/apache/openejb/server/axis2/ejb/EjbEndpointController.java (added)
+++ openejb/trunk/openejb3/server/openejb-axis2/src/main/java/org/apache/openejb/server/axis2/ejb/EjbEndpointController.java Sun Nov  4 14:41:49 2007
@@ -0,0 +1,42 @@
+/*
+ * 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.openejb.server.axis2.ejb;
+
+import javax.interceptor.InvocationContext;
+import javax.xml.ws.Provider;
+
+import org.apache.axis2.jaxws.server.EndpointController;
+import org.apache.axis2.jaxws.server.dispatcher.EndpointDispatcher;
+
+public class EjbEndpointController extends EndpointController {
+    private InvocationContext invContext;
+
+    public EjbEndpointController(InvocationContext invContext) {
+        this.invContext = invContext;
+    }
+    
+    protected EndpointDispatcher getEndpointDispatcher(Class serviceImplClass, Object serviceInstance)
+        throws Exception {    
+        if (Provider.class.isAssignableFrom(serviceImplClass)) {
+            return new EjbProviderDispatcher(serviceImplClass, this.invContext);
+        } else {
+            return new EjbServiceDispatcher(serviceImplClass, this.invContext);
+        }
+    }
+}

Added: openejb/trunk/openejb3/server/openejb-axis2/src/main/java/org/apache/openejb/server/axis2/ejb/EjbInterceptor.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/server/openejb-axis2/src/main/java/org/apache/openejb/server/axis2/ejb/EjbInterceptor.java?rev=591858&view=auto
==============================================================================
--- openejb/trunk/openejb3/server/openejb-axis2/src/main/java/org/apache/openejb/server/axis2/ejb/EjbInterceptor.java (added)
+++ openejb/trunk/openejb3/server/openejb-axis2/src/main/java/org/apache/openejb/server/axis2/ejb/EjbInterceptor.java Sun Nov  4 14:41:49 2007
@@ -0,0 +1,103 @@
+/**
+ * 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.openejb.server.axis2.ejb;
+
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.context.OperationContext;
+import org.apache.axis2.description.AxisOperation;
+import org.apache.axis2.description.WSDL2Constants;
+import org.apache.axis2.engine.AxisEngine;
+import org.apache.axis2.jaxws.core.InvocationContext;
+import org.apache.axis2.jaxws.core.InvocationContextFactory;
+import org.apache.axis2.jaxws.core.MessageContext;
+import org.apache.axis2.jaxws.message.util.MessageUtils;
+import org.apache.axis2.jaxws.server.JAXWSMessageReceiver;
+import org.apache.axis2.wsdl.WSDLConstants.WSDL20_2004_Constants;
+import org.apache.axis2.wsdl.WSDLConstants.WSDL20_2006Constants;
+
+import javax.interceptor.AroundInvoke;
+import javax.xml.ws.Binding;
+
+public class EjbInterceptor {
+    private MessageContext requestMsgCtx;
+
+    public EjbInterceptor(MessageContext requestCtx) {
+        this.requestMsgCtx = requestCtx;
+    }
+
+    @AroundInvoke
+    public Object intercept(javax.interceptor.InvocationContext invContext) throws Exception {
+        AxisOperation operation = this.requestMsgCtx.getAxisMessageContext().getAxisOperation();
+        String mep = operation.getMessageExchangePattern();
+
+        EjbEndpointController controller = new EjbEndpointController(invContext);
+
+        Binding binding = (Binding) this.requestMsgCtx.getAxisMessageContext().getProperty(JAXWSMessageReceiver.PARAM_BINDING);
+        InvocationContext ic = InvocationContextFactory.createInvocationContext(binding);
+        ic.setRequestMessageContext(this.requestMsgCtx);
+
+        controller.invoke(ic);
+
+        MessageContext responseMsgCtx = ic.getResponseMessageContext();
+
+        //If there is a fault it could be Robust In-Only
+        if (!isMepInOnly(mep) || hasFault(responseMsgCtx)) {
+            // If this is a two-way exchange, there should already be a
+            // JAX-WS MessageContext for the response.  We need to pull 
+            // the Message data out of there and set it on the Axis2 
+            // MessageContext.
+            org.apache.axis2.context.MessageContext axisResponseMsgCtx = responseMsgCtx.getAxisMessageContext();
+
+            MessageUtils.putMessageOnMessageContext(responseMsgCtx.getMessage(), axisResponseMsgCtx);
+
+            OperationContext opCtx = axisResponseMsgCtx.getOperationContext();
+            opCtx.addMessageContext(axisResponseMsgCtx);
+
+            // If this is a fault message, we want to throw it as an
+            // exception so that the transport can do the appropriate things
+            if (responseMsgCtx.getMessage().isFault()) {
+                throw new AxisFault("An error was detected during JAXWS processing", axisResponseMsgCtx);
+            } else {
+                //Create the AxisEngine for the reponse and send it.
+                // todo this is wacky
+                new AxisEngine(axisResponseMsgCtx.getConfigurationContext());
+                AxisEngine.send(axisResponseMsgCtx);
+            }
+        }
+
+        // TODO: convert response into object?
+        return null;
+    }
+
+    private boolean hasFault(MessageContext responseMsgCtx) {
+        return responseMsgCtx != null && responseMsgCtx.getMessage() != null && responseMsgCtx.getMessage().isFault();
+    }
+
+    private boolean isMepInOnly(String mep) {
+        boolean inOnly = mep.equals(WSDL20_2004_Constants.MEP_URI_ROBUST_IN_ONLY) || 
+                mep.equals(WSDL20_2004_Constants.MEP_URI_IN_ONLY) ||
+                mep.equals(WSDL2Constants.MEP_URI_IN_ONLY) ||
+                mep.equals(WSDL2Constants.MEP_URI_ROBUST_IN_ONLY) ||
+                mep.equals(WSDL20_2006Constants.MEP_URI_ROBUST_IN_ONLY) ||
+                mep.equals(WSDL20_2006Constants.MEP_URI_IN_ONLY);
+        return inOnly;
+    }
+
+}

Added: openejb/trunk/openejb3/server/openejb-axis2/src/main/java/org/apache/openejb/server/axis2/ejb/EjbMessageReceiver.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/server/openejb-axis2/src/main/java/org/apache/openejb/server/axis2/ejb/EjbMessageReceiver.java?rev=591858&view=auto
==============================================================================
--- openejb/trunk/openejb3/server/openejb-axis2/src/main/java/org/apache/openejb/server/axis2/ejb/EjbMessageReceiver.java (added)
+++ openejb/trunk/openejb3/server/openejb-axis2/src/main/java/org/apache/openejb/server/axis2/ejb/EjbMessageReceiver.java Sun Nov  4 14:41:49 2007
@@ -0,0 +1,180 @@
+/**
+ * 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.openejb.server.axis2.ejb;
+
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.description.AxisService;
+import org.apache.axis2.description.Parameter;
+import org.apache.axis2.engine.MessageReceiver;
+import org.apache.axis2.jaxws.ExceptionFactory;
+import org.apache.axis2.jaxws.core.MessageContext;
+import org.apache.axis2.jaxws.description.EndpointDescription;
+import org.apache.axis2.jaxws.description.EndpointInterfaceDescription;
+import org.apache.axis2.jaxws.description.OperationDescription;
+import org.apache.axis2.jaxws.handler.SoapMessageContext;
+import org.apache.axis2.jaxws.i18n.Messages;
+import org.apache.openejb.ApplicationException;
+import org.apache.openejb.DeploymentInfo;
+import org.apache.openejb.RpcContainer;
+import org.apache.openejb.util.LogCategory;
+import org.apache.openejb.util.Logger;
+
+import javax.xml.ws.Provider;
+import java.lang.reflect.Method;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+
+public class EjbMessageReceiver implements MessageReceiver {
+    private static final Logger logger = Logger.getInstance(LogCategory.AXIS2, EjbMessageReceiver.class);
+
+    private DeploymentInfo deploymentInfo;
+    private Class serviceImplClass;
+    private EjbWsContainer container;
+
+    public EjbMessageReceiver(EjbWsContainer container, Class serviceImplClass, DeploymentInfo deploymentInfo) {
+        this.container = container;
+        this.serviceImplClass = serviceImplClass;
+        this.deploymentInfo = deploymentInfo;
+    }
+
+    public void receive(org.apache.axis2.context.MessageContext axisMsgCtx) throws AxisFault {
+        MessageContext requestMsgCtx = new MessageContext(axisMsgCtx);
+
+        // init some bits
+        requestMsgCtx.setOperationName(requestMsgCtx.getAxisMessageContext().getAxisOperation().getName());
+        requestMsgCtx.setEndpointDescription(getEndpointDescription(requestMsgCtx));
+
+        Method method = null;
+        if (Provider.class.isAssignableFrom(this.serviceImplClass)) {
+            method = getProviderMethod();
+        } else {
+            requestMsgCtx.setOperationDescription(getOperationDescription(requestMsgCtx));
+            method = getServiceMethod(requestMsgCtx);
+        }
+
+        if (logger.isDebugEnabled()) {
+            logger.debug("Invoking '" + method.getName() + "' method.");
+        }
+
+        EjbInterceptor interceptor = new EjbInterceptor(requestMsgCtx);
+
+        SoapMessageContext jaxwsContext = new SoapMessageContext(requestMsgCtx);
+        Object[] arguments = {jaxwsContext, interceptor};
+
+        RpcContainer container = (RpcContainer) this.deploymentInfo.getContainer();
+
+        Class callInterface = this.deploymentInfo.getServiceEndpointInterface();
+
+        method = getMostSpecificMethod(method, callInterface);
+
+        try {
+            Object res = container.invoke(this.deploymentInfo.getDeploymentID(), callInterface, method, arguments, null);
+            // TODO: update response message with new response value?
+        } catch (ApplicationException e) {
+            if (e.getCause() instanceof AxisFault) {
+                throw (AxisFault) e.getCause();
+            } else {
+                throw AxisFault.makeFault(e);
+            }
+        } catch (Exception e) {
+            throw AxisFault.makeFault(e);
+        }
+    }
+
+    private static Method getMostSpecificMethod(Method method, Class<?> targetClass) {
+        if (method != null && targetClass != null) {
+            try {
+                method = targetClass.getMethod(method.getName(), method.getParameterTypes());
+            } catch (NoSuchMethodException ex) {
+                // Perhaps the target class doesn't implement this method:
+                // that's fine, just use the original method
+            }
+        }
+        return method;
+    }
+
+    private Method getServiceMethod(MessageContext mc) {
+        OperationDescription opDesc = mc.getOperationDescription();
+        if (opDesc == null) {
+            throw ExceptionFactory.makeWebServiceException("Operation Description was not set");
+        }
+
+        Method returnMethod = opDesc.getMethodFromServiceImpl(this.serviceImplClass);
+        if (returnMethod == null) {
+            throw ExceptionFactory
+                    .makeWebServiceException(Messages.getMessage("JavaBeanDispatcherErr1"));
+        }
+
+        return returnMethod;
+    }
+
+    private OperationDescription getOperationDescription(MessageContext mc) {
+        EndpointDescription ed = mc.getEndpointDescription();
+        EndpointInterfaceDescription eid = ed.getEndpointInterfaceDescription();
+
+        OperationDescription[] ops = eid.getDispatchableOperation(mc.getOperationName());
+        if (ops == null || ops.length == 0) {
+            throw ExceptionFactory.makeWebServiceException("No operation found.  WSDL Operation name: " + mc.getOperationName());
+        }
+        if (ops.length > 1) {
+            throw ExceptionFactory.makeWebServiceException("More than one operation found. Overloaded WSDL operations are not supported.  WSDL Operation name: " + mc.getOperationName());
+        }
+        OperationDescription op = ops[0];
+        return op;
+    }
+
+    private EndpointDescription getEndpointDescription(MessageContext mc) {
+        AxisService axisSvc = mc.getAxisMessageContext().getAxisService();
+
+        Parameter param = axisSvc.getParameter(EndpointDescription.AXIS_SERVICE_PARAMETER);
+
+        EndpointDescription ed = (EndpointDescription) param.getValue();
+        return ed;
+    }
+
+    private Method getProviderMethod() {
+        try {
+            return this.serviceImplClass.getMethod("invoke", getProviderType());
+        } catch (NoSuchMethodException e) {
+            throw ExceptionFactory.makeWebServiceException("Could not get Provider.invoke() method");
+        }
+    }
+
+    private Class<?> getProviderType() {
+        Class providerType = null;
+
+        Type[] giTypes = this.serviceImplClass.getGenericInterfaces();
+        for (Type giType : giTypes) {
+            ParameterizedType paramType = null;
+            try {
+                paramType = (ParameterizedType) giType;
+            } catch (ClassCastException e) {
+                throw ExceptionFactory.makeWebServiceException("Provider based SEI Class has to implement javax.xml.ws.Provider as javax.xml.ws.Provider<String>, javax.xml.ws.Provider<SOAPMessage>, javax.xml.ws.Provider<Source> or javax.xml.ws.Provider<JAXBContext>");
+            }
+            Class interfaceName = (Class) paramType.getRawType();
+
+            if (interfaceName == javax.xml.ws.Provider.class) {
+                if (paramType.getActualTypeArguments().length > 1) {
+                    throw ExceptionFactory.makeWebServiceException("Provider cannot have more than one Generic Types defined as Per JAX-WS Specification");
+                }
+                providerType = (Class) paramType.getActualTypeArguments()[0];
+            }
+        }
+        return providerType;
+    }
+}

Added: openejb/trunk/openejb3/server/openejb-axis2/src/main/java/org/apache/openejb/server/axis2/ejb/EjbProviderDispatcher.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/server/openejb-axis2/src/main/java/org/apache/openejb/server/axis2/ejb/EjbProviderDispatcher.java?rev=591858&view=auto
==============================================================================
--- openejb/trunk/openejb3/server/openejb-axis2/src/main/java/org/apache/openejb/server/axis2/ejb/EjbProviderDispatcher.java (added)
+++ openejb/trunk/openejb3/server/openejb-axis2/src/main/java/org/apache/openejb/server/axis2/ejb/EjbProviderDispatcher.java Sun Nov  4 14:41:49 2007
@@ -0,0 +1,49 @@
+/*
+ * 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.openejb.server.axis2.ejb;
+
+import org.apache.axis2.jaxws.ExceptionFactory;
+import org.apache.axis2.jaxws.core.MessageContext;
+import org.apache.axis2.jaxws.server.dispatcher.ProviderDispatcher;
+
+import javax.interceptor.InvocationContext;
+import javax.xml.ws.Provider;
+
+public class EjbProviderDispatcher extends ProviderDispatcher {
+    private InvocationContext invContext;
+
+    public EjbProviderDispatcher(Class serviceImplClass, InvocationContext invContext) {
+        super(serviceImplClass, getDummyInstance(serviceImplClass));
+        this.invContext = invContext;
+    }
+
+    //  TODO: change ProviderDispatcher so that instance is not required
+    private static Object getDummyInstance(Class serviceImplClass) {
+        try {
+            return serviceImplClass.newInstance();
+        } catch (Exception e) {
+            throw ExceptionFactory.makeWebServiceException("Failed to create provider instance");
+        }
+    }
+
+    protected Object invokeProvider(MessageContext ctx, Provider provider, Object input) throws Exception {
+        this.invContext.setParameters(new Object[]{input});
+        return this.invContext.proceed();
+    }
+}



Mime
View raw message