geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject svn commit: r545688 - in /geronimo/server/trunk/modules/geronimo-axis2/src/main/java/org/apache/geronimo/axis2: Axis2RequestResponseTransport.java Axis2WebServiceContainer.java AxisServiceGenerator.java pojo/POJOWebServiceContainer.java
Date Sat, 09 Jun 2007 03:59:37 GMT
Author: gawor
Date: Fri Jun  8 20:59:36 2007
New Revision: 545688

URL: http://svn.apache.org/viewvc?view=rev&rev=545688
Log:
reworked handler processing

Added:
    geronimo/server/trunk/modules/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/Axis2RequestResponseTransport.java
  (with props)
Modified:
    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/AxisServiceGenerator.java
    geronimo/server/trunk/modules/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/pojo/POJOWebServiceContainer.java

Added: geronimo/server/trunk/modules/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/Axis2RequestResponseTransport.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/Axis2RequestResponseTransport.java?view=auto&rev=545688
==============================================================================
--- geronimo/server/trunk/modules/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/Axis2RequestResponseTransport.java
(added)
+++ geronimo/server/trunk/modules/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/Axis2RequestResponseTransport.java
Fri Jun  8 20:59:36 2007
@@ -0,0 +1,87 @@
+/**
+ * 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 java.io.IOException;
+import java.net.HttpURLConnection;
+import java.util.concurrent.CountDownLatch;
+
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.transport.RequestResponseTransport;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.geronimo.webservices.WebServiceContainer.Response;
+
+public class Axis2RequestResponseTransport implements RequestResponseTransport {
+    
+    private static final Log LOG = LogFactory.getLog(Axis2RequestResponseTransport.class);
+    
+    private Response response;
+
+    private CountDownLatch responseReadySignal = new CountDownLatch(1);
+
+    private RequestResponseTransportStatus status = RequestResponseTransportStatus.INITIAL;
+
+    private AxisFault faultToBeThrownOut = null;
+
+    Axis2RequestResponseTransport(Response response) {
+        this.response = response;
+    }
+
+    public void acknowledgeMessage(MessageContext msgContext) throws AxisFault {
+        LOG.debug("acknowledgeMessage");
+        LOG.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 {
+        LOG.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() {
+        LOG.debug("Signalling response available");
+        status = RequestResponseTransportStatus.SIGNALLED;
+        responseReadySignal.countDown();
+    }
+
+    public RequestResponseTransportStatus getStatus() {
+        return status;
+    }
+}

Propchange: geronimo/server/trunk/modules/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/Axis2RequestResponseTransport.java
------------------------------------------------------------------------------
    svn:eol-style = native

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=545688&r1=545687&r2=545688
==============================================================================
--- 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
Fri Jun  8 20:59:36 2007
@@ -17,19 +17,21 @@
 
 package org.apache.geronimo.axis2;
 
-import java.io.IOException;
+import java.io.ByteArrayInputStream;
 import java.io.PrintWriter;
 import java.net.HttpURLConnection;
 import java.net.URL;
-import java.util.concurrent.CountDownLatch;
+import java.util.List;
 
 import javax.naming.Context;
 import javax.servlet.ServletContext;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+import javax.xml.ws.Binding;
+import javax.xml.ws.WebServiceException;
+import javax.xml.ws.handler.Handler;
 
 import org.apache.axiom.om.util.UUIDGenerator;
-import org.apache.axis2.AxisFault;
 import org.apache.axis2.Constants;
 import org.apache.axis2.addressing.AddressingHelper;
 import org.apache.axis2.context.ConfigurationContext;
@@ -41,6 +43,13 @@
 import org.apache.axis2.description.TransportOutDescription;
 import org.apache.axis2.engine.AxisEngine;
 import org.apache.axis2.engine.Handler.InvocationResponse;
+import org.apache.axis2.jaxws.binding.BindingImpl;
+import org.apache.axis2.jaxws.binding.BindingUtils;
+import org.apache.axis2.jaxws.description.EndpointDescription;
+import org.apache.axis2.jaxws.description.impl.DescriptionUtils;
+import org.apache.axis2.jaxws.description.xml.handler.HandlerChainType;
+import org.apache.axis2.jaxws.description.xml.handler.HandlerChainsType;
+import org.apache.axis2.jaxws.description.xml.handler.HandlerType;
 import org.apache.axis2.jaxws.server.JAXWSMessageReceiver;
 import org.apache.axis2.transport.OutTransportInfo;
 import org.apache.axis2.transport.RequestResponseTransport;
@@ -51,10 +60,12 @@
 import org.apache.axis2.util.MessageContextBuilder;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.geronimo.jaxws.JAXWSAnnotationProcessor;
 import org.apache.geronimo.jaxws.JAXWSUtils;
 import org.apache.geronimo.jaxws.JNDIResolver;
 import org.apache.geronimo.jaxws.PortInfo;
 import org.apache.geronimo.jaxws.ServerJNDIResolver;
+import org.apache.geronimo.jaxws.annotations.AnnotationException;
 import org.apache.geronimo.webservices.WebServiceContainer;
 import org.apache.geronimo.webservices.saaj.SAAJUniverse;
 
@@ -69,14 +80,17 @@
     public static final String RESPONSE = Axis2WebServiceContainer.class.getName() + "@Response";
 
     private transient final ClassLoader classLoader;
-    private final String endpointClassName;
+    
+    protected String endpointClassName;
     protected org.apache.geronimo.jaxws.PortInfo portInfo;
     protected ConfigurationContext configurationContext;
     protected JNDIResolver jndiResolver;
     protected Class endpointClass;
-    private AxisService service;
-    private URL configurationBaseUrl;
-    private WSDLQueryHandler wsdlQueryHandler;
+    protected AxisService service;
+    protected URL configurationBaseUrl;
+    protected WSDLQueryHandler wsdlQueryHandler;
+    protected Binding binding;
+    protected JAXWSAnnotationProcessor annotationProcessor;
 
     public Axis2WebServiceContainer(PortInfo portInfo,
                                     String endpointClassName,
@@ -272,61 +286,6 @@
         }
     }
     
-    static class Axis2RequestResponseTransport implements RequestResponseTransport {
-        private Response response;
-
-        private CountDownLatch responseReadySignal = new CountDownLatch(1);
-
-        private RequestResponseTransportStatus status = RequestResponseTransportStatus.INITIAL;
-
-        private AxisFault faultToBeThrownOut = null;
-
-        Axis2RequestResponseTransport(Response response) {
-            this.response = response;
-        }
-
-        public void acknowledgeMessage(MessageContext msgContext) throws AxisFault {
-            LOG.debug("acknowledgeMessage");
-            LOG.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 {
-            LOG.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() {
-            LOG.debug("Signalling response available");
-            status = RequestResponseTransportStatus.SIGNALLED;
-            responseReadySignal.countDown();
-        }
-
-        public RequestResponseTransportStatus getStatus() {
-            return status;
-        }
-    }
-    
     protected void processGETRequest(Request request, Response response, AxisService service,
MessageContext msgContext) throws Exception{        
         if (request.getURI().getQuery() != null &&
             (request.getURI().getQuery().startsWith("wsdl") ||
@@ -363,11 +322,7 @@
         }
     }
     
-    protected void setMsgContextProperties(MessageContext msgContext, AxisService service,
Response response, Request request) {
-        //BindingImpl binding = new BindingImpl("GeronimoBinding");
-        //binding.setHandlerChain(chain);
-        //msgContext.setProperty(JAXWSMessageReceiver.PARAM_BINDING, binding);
-        // deal with POST request
+    protected void setMsgContextProperties(Request request, Response 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,
@@ -385,10 +340,14 @@
 
         ServletContext servletContext =
             (ServletContext)request.getAttribute(WebServiceContainer.SERVLET_CONTEXT);
-        msgContext.setProperty(HTTPConstants.MC_HTTP_SERVLETCONTEXT, servletContext);   
    
+        msgContext.setProperty(HTTPConstants.MC_HTTP_SERVLETCONTEXT, servletContext);   

+        
+        if (this.binding != null) {
+            msgContext.setProperty(JAXWSMessageReceiver.PARAM_BINDING, this.binding);  
+        }
     }
 
-    protected void processPOSTRequest (Request request, Response response, AxisService service,
MessageContext msgContext) throws Exception {
+    protected void processPOSTRequest(Request request, Response 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) {
@@ -398,7 +357,7 @@
         ConfigurationContext configurationContext = msgContext.getConfigurationContext();
         configurationContext.fillServiceContextAndServiceGroupContext(msgContext);
 
-        setMsgContextProperties(msgContext, service, response, request);
+        setMsgContextProperties(request, response, service, msgContext);
 
         HTTPTransportUtils.processHTTPPostRequest(msgContext,
                                                   request.getInputStream(), 
@@ -407,5 +366,74 @@
                                                   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) {
+            this.binding = new BindingImpl("");
+        } else {
+            String xml = this.portInfo.getHandlersAsXML();
+            HandlerChainsType handlerChains = null;
+            if (xml != null) {
+                ByteArrayInputStream in = new ByteArrayInputStream(xml.getBytes("UTF-8"));
+                handlerChains = DescriptionUtils.loadHandlerChains(in);
+                desc.setHandlerChain(handlerChains);
+            }
+            
+            if (LOG.isDebugEnabled()) {
+                logHandlers(desc.getHandlerChain());
+            }
+            
+            this.binding = BindingUtils.createBinding(desc);
+        }
+    }
+
+    private void logHandlers(HandlerChainsType handlerChains) {
+        if (handlerChains == null || handlerChains.getHandlerChain() == null
+            || handlerChains.getHandlerChain().isEmpty()) {
+            LOG.debug("No handlers");
+            return;
+        }
 
+        for (HandlerChainType chains : handlerChains.getHandlerChain()) {
+            LOG.debug("Handler chain: " + chains.getServiceNamePattern() + " " + 
+                      chains.getPortNamePattern() + " " + chains.getProtocolBindings());
+            if (chains.getHandler() != null) {
+                for (HandlerType chain : chains.getHandler()) {                    
+                    LOG.debug("  Handler: " + chain.getHandlerName().getValue() + " " + 
+                              chain.getHandlerClass().getValue());
+                }
+            }
+        }
+    }
+
+    protected void injectHandlers() {
+        List<Handler> handlers = this.binding.getHandlerChain();
+        try {
+            for (Handler handler : handlers) {
+                injectResources(handler);
+            }
+        } catch (AnnotationException e) {
+            throw new WebServiceException("Handler annotation failed", e);
+        }
+    }
+    
+    protected void destroyHandlers() {
+        if (this.annotationProcessor != null) {
+            // call handlers preDestroy
+            List<Handler> handlers = this.binding.getHandlerChain();
+            for (Handler handler : handlers) {
+                this.annotationProcessor.invokePreDestroy(handler);
+            }
+        }
+    }
+    
+    protected 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/AxisServiceGenerator.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/AxisServiceGenerator.java?view=diff&rev=545688&r1=545687&r2=545688
==============================================================================
--- geronimo/server/trunk/modules/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/AxisServiceGenerator.java
(original)
+++ geronimo/server/trunk/modules/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/AxisServiceGenerator.java
Fri Jun  8 20:59:36 2007
@@ -303,5 +303,10 @@
         }
         return wsdlURL;
     }
-          
+    
+    public static EndpointDescription getEndpointDescription(AxisService service) {
+        Parameter param = service.getParameter(EndpointDescription.AXIS_SERVICE_PARAMETER);
+        return (param == null) ? null : (EndpointDescription) param.getValue();
+    }
+         
 }

Modified: geronimo/server/trunk/modules/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/pojo/POJOWebServiceContainer.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/pojo/POJOWebServiceContainer.java?view=diff&rev=545688&r1=545687&r2=545688
==============================================================================
--- geronimo/server/trunk/modules/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/pojo/POJOWebServiceContainer.java
(original)
+++ geronimo/server/trunk/modules/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/pojo/POJOWebServiceContainer.java
Fri Jun  8 20:59:36 2007
@@ -18,32 +18,25 @@
 package org.apache.geronimo.axis2.pojo;
 
 import java.net.URL;
-import java.util.List;
 
 import javax.naming.Context;
 import javax.xml.ws.WebServiceException;
-import javax.xml.ws.handler.Handler;
 
 import org.apache.axis2.context.ConfigurationContext;
 import org.apache.axis2.context.MessageContext;
 import org.apache.axis2.context.ServiceContext;
 import org.apache.axis2.description.AxisService;
-import org.apache.axis2.jaxws.binding.BindingImpl;
 import org.apache.axis2.jaxws.registry.FactoryRegistry;
-import org.apache.axis2.jaxws.server.JAXWSMessageReceiver;
 import org.apache.axis2.jaxws.server.endpoint.lifecycle.factory.EndpointLifecycleManagerFactory;
 import org.apache.axis2.transport.http.HTTPConstants;
 import org.apache.axis2.transport.http.HTTPTransportUtils;
 import org.apache.axis2.util.JavaUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.geronimo.axis2.Axis2HandlerResolver;
 import org.apache.geronimo.axis2.Axis2WebServiceContainer;
 import org.apache.geronimo.jaxws.JAXWSAnnotationProcessor;
 import org.apache.geronimo.jaxws.PortInfo;
 import org.apache.geronimo.jaxws.annotations.AnnotationException;
-import org.apache.geronimo.xbeans.javaee.HandlerChainsDocument;
-import org.apache.geronimo.xbeans.javaee.HandlerChainsType;
 
 // FIXME: improve handler support, handler injection, thread-safetly for handlers
 
@@ -54,10 +47,9 @@
 
     private static final Log LOG = LogFactory.getLog(POJOWebServiceContainer.class);
     
-    private JAXWSAnnotationProcessor annotationProcessor;
     private Object endpointInstance;
-    private List<Handler> chain;
     private String contextRoot = null;
+
     
     public POJOWebServiceContainer(PortInfo portInfo,
                                    String endpointClassName,
@@ -81,6 +73,14 @@
         this.annotationProcessor = 
             new JAXWSAnnotationProcessor(this.jndiResolver, new POJOWebServiceContext());
 
+        // configure and inject handlers
+        try {
+            configureHandlers();
+            injectHandlers();
+        } catch (Exception e) {
+            throw new WebServiceException("Error configuring handlers", e);
+        }
+        
         // inject resources into service
         try {
             injectResources(this.endpointInstance);
@@ -100,12 +100,11 @@
         ConfigurationContext configurationContext = msgContext.getConfigurationContext();
         configurationContext.fillServiceContextAndServiceGroupContext(msgContext);
         
-        setMsgContextProperties(msgContext, service, response, request);
+        setMsgContextProperties(request, response, service, msgContext);
 
         ServiceContext serviceContext = msgContext.getServiceContext();
         serviceContext.setProperty(ServiceContext.SERVICE_OBJECT, this.endpointInstance);
-        
-        initHandlers();
+
         try {
             HTTPTransportUtils.processHTTPPostRequest(msgContext,
                                                       request.getInputStream(),
@@ -113,62 +112,13 @@
                                                       contentType,
                                                       soapAction,
                                                       request.getURI().getPath());
-        } finally {            
-            stopHandlers();
-            
+        } finally {                        
             // de-associate JAX-WS MessageContext with the thread
             // (association happens in POJOEndpointLifecycleManager.createService() call)
             POJOWebServiceContext.clear();
         } 
     }
     
-    @Override
-    protected void setMsgContextProperties(MessageContext msgContext, AxisService service,
Response response, Request request) {
-        BindingImpl binding = new BindingImpl("GeronimoBinding");
-        binding.setHandlerChain(chain);
-        msgContext.setProperty(JAXWSMessageReceiver.PARAM_BINDING, binding);
-        
-        super.setMsgContextProperties(msgContext, service, response, request);
-    }
-        
-    protected void initHandlers() {
-        // configure and inject handlers
-        try {
-            configureHandlers();
-        } catch (Exception e) {
-            throw new WebServiceException("Error configuring handlers", e);
-        }
-    }
-
-    /*
-     * Gets the right handlers for the port/service/bindings and
-     * performs injection.
-     */
-    protected void configureHandlers() throws Exception {
-        String xml = this.portInfo.getHandlersAsXML();
-        HandlerChainsType handlerChains = xml == null ? null : HandlerChainsDocument.Factory.parse(xml).getHandlerChains();
-        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 stopHandlers() {
-        // call handlers preDestroy
-        for (Handler handler : chain) {
-            this.annotationProcessor.invokePreDestroy(handler);
-        }
-    }
-
-    private void injectResources(Object instance) throws AnnotationException {
-        this.annotationProcessor.processAnnotations(instance);
-        this.annotationProcessor.invokePostConstruct(instance);
-    }
-    
     protected void initContextRoot(Request request) {
         if (contextRoot == null || "".equals(contextRoot)) {
             String[] parts = JavaUtils.split(request.getContextPath(), '/');
@@ -191,6 +141,9 @@
     
     @Override
     public void destroy() {
+        // call handler preDestroy
+        destroyHandlers();
+        
         // call service preDestroy
         if (this.endpointInstance != null) {
             this.annotationProcessor.invokePreDestroy(this.endpointInstance);



Mime
View raw message