cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r514678 - in /incubator/cxf/trunk: rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/ rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/context/ rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/ systests/src/test/java/org/...
Date Mon, 05 Mar 2007 14:39:43 GMT
Author: jliu
Date: Mon Mar  5 06:39:42 2007
New Revision: 514678

URL: http://svn.apache.org/viewvc?view=rev&rev=514678
Log:
CXF-436, calling JAX-WS handlers' @PostConstruct methods per JAX-WS spec

Added:
    incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/context/WebServiceContextResourceResolver.java
      - copied, changed from r512643, incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/context/WebContextResourceResolver.java
Removed:
    incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/context/WebContextResourceResolver.java
Modified:
    incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/EndpointImpl.java
    incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/HandlerResolverImpl.java
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/HandlerInvocationUsingAddNumbersTest.java
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/SmallNumberHandler.java
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/TestHandlerBase.java

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/EndpointImpl.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/EndpointImpl.java?view=diff&rev=514678&r1=514677&r2=514678
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/EndpointImpl.java
(original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/EndpointImpl.java
Mon Mar  5 06:39:42 2007
@@ -39,7 +39,7 @@
 import org.apache.cxf.configuration.Configurer;
 import org.apache.cxf.endpoint.Server;
 import org.apache.cxf.endpoint.ServerImpl;
-import org.apache.cxf.jaxws.context.WebContextResourceResolver;
+import org.apache.cxf.jaxws.context.WebServiceContextResourceResolver;
 import org.apache.cxf.jaxws.handler.AnnotationHandlerChainBuilder;
 import org.apache.cxf.jaxws.support.JaxWsEndpointImpl;
 import org.apache.cxf.jaxws.support.JaxWsImplementorInfo;
@@ -192,7 +192,7 @@
             ResourceManager resourceManager = bus.getExtension(ResourceManager.class);
             List<ResourceResolver> resolvers = resourceManager.getResourceResolvers();
             resourceManager = new DefaultResourceManager(resolvers); 
-            resourceManager.addResourceResolver(new WebContextResourceResolver());
+            resourceManager.addResourceResolver(new WebServiceContextResourceResolver());
             ResourceInjector injector = new ResourceInjector(resourceManager);
             injector.inject(instance);
         }
@@ -242,7 +242,7 @@
         if (doInit) {
             try {
                 injectResources(implementor);
-                configureHandlers();
+                buildHandlerChain();
             } catch (Exception ex) {
                 if (ex instanceof WebServiceException) { 
                     throw (WebServiceException)ex; 
@@ -257,18 +257,18 @@
      * Obtain handler chain from annotations.
      *
      */
-    private void configureHandlers() {
+    private void buildHandlerChain() {
         LOG.fine("loading handler chain for endpoint");
         AnnotationHandlerChainBuilder builder = new AnnotationHandlerChainBuilder();
 
-        List<Handler> chain = null;
-
-        if (null == chain || chain.size() == 0) {
-            chain = builder.buildHandlerChainFromClass(implementor.getClass());
+        List<Handler> chain = builder.buildHandlerChainFromClass(implementor.getClass());
+        for (Handler h : chain) {
+            injectResources(h);
         }
+        
         getBinding().setHandlerChain(chain);
     }
-
+    
     public EndpointReference getEndpointReference(Element... referenceParameters) {
         // TODO
         throw new UnsupportedOperationException();

Copied: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/context/WebServiceContextResourceResolver.java
(from r512643, incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/context/WebContextResourceResolver.java)
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/context/WebServiceContextResourceResolver.java?view=diff&rev=514678&p1=incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/context/WebContextResourceResolver.java&r1=512643&p2=incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/context/WebServiceContextResourceResolver.java&r2=514678
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/context/WebContextResourceResolver.java
(original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/context/WebServiceContextResourceResolver.java
Mon Mar  5 06:39:42 2007
@@ -26,7 +26,7 @@
 import org.apache.cxf.resource.ResourceResolver;
 
 
-public class WebContextResourceResolver implements ResourceResolver {
+public class WebServiceContextResourceResolver implements ResourceResolver {
 
     public final InputStream getAsStream(final String string) {
         return null;

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/HandlerResolverImpl.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/HandlerResolverImpl.java?view=diff&rev=514678&r1=514677&r2=514678
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/HandlerResolverImpl.java
(original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/HandlerResolverImpl.java
Mon Mar  5 06:39:42 2007
@@ -30,15 +30,21 @@
 import javax.xml.ws.handler.PortInfo;
 
 import org.apache.cxf.Bus;
+import org.apache.cxf.common.injection.ResourceInjector;
+import org.apache.cxf.resource.DefaultResourceManager;
+import org.apache.cxf.resource.ResourceManager;
+import org.apache.cxf.resource.ResourceResolver;
 
 public class HandlerResolverImpl implements HandlerResolver {
     private final Map<PortInfo, List<Handler>> handlerMap = new HashMap<PortInfo,
List<Handler>>();
     
     //private QName service;   
     private Class<?> annotationClass;
+    private Bus bus;
 
     public HandlerResolverImpl(Bus bus, QName serviceName, Class<?> clazz) {
         //this.service = pService;
+        this.bus = bus;
         this.annotationClass = clazz;
     }
 
@@ -65,6 +71,11 @@
         if (annotationClass != null) {
             chain.addAll(getHandlersFromAnnotation(annotationClass));            
         }
+        
+        for (Handler h : chain) {
+            configHandler(h);
+        }       
+        
         return chain;
     }
 
@@ -80,5 +91,24 @@
         List<Handler> chain = builder.buildHandlerChainFromClass(clazz);
         
         return chain;
+    }
+    
+    /**
+     * JAX-WS section 9.3.1: The runtime MUST then carry out any injections
+     * requested by the handler, typically via the javax .annotation.Resource
+     * annotation. After all the injections have been carried out, including in
+     * the case where no injections were requested, the runtime MUST invoke the
+     * method carrying a javax.annotation .PostConstruct annotation, if present.
+     */
+    private void configHandler(Handler handler) {
+        if (handler != null) {
+            ResourceManager resourceManager = bus.getExtension(ResourceManager.class);
+            List<ResourceResolver> resolvers = resourceManager.getResourceResolvers();
+            resourceManager = new DefaultResourceManager(resolvers);
+//            resourceManager.addResourceResolver(new WebContextEntriesResourceResolver());
+            ResourceInjector injector = new ResourceInjector(resourceManager);
+            injector.inject(handler);
+        }
+
     }
 }

Modified: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/HandlerInvocationUsingAddNumbersTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/HandlerInvocationUsingAddNumbersTest.java?view=diff&rev=514678&r1=514677&r2=514678
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/HandlerInvocationUsingAddNumbersTest.java
(original)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/HandlerInvocationUsingAddNumbersTest.java
Mon Mar  5 06:39:42 2007
@@ -108,6 +108,18 @@
         assertEquals(200, value.getReturn());
     }
     
+    public void testHandlerPostConstruct() throws Exception {
+        URL wsdl = getClass().getResource("/wsdl/addNumbers.wsdl");
+
+        AddNumbersServiceWithAnnotation service = new AddNumbersServiceWithAnnotation(wsdl,
serviceName);
+        AddNumbers port = (AddNumbers)service.getPort(portName, AddNumbers.class);
+
+        List<Handler> handlerChain = ((BindingProvider)port).getBinding().getHandlerChain();
+        SmallNumberHandler h = (SmallNumberHandler)handlerChain.get(0);
+        
+        assertTrue(h.isPostConstructInvoked());      
+    }  
+    
     private void addHandlersProgrammatically(BindingProvider bp, Handler...handlers) {
         List<Handler> handlerChain = bp.getBinding().getHandlerChain();
         assertNotNull(handlerChain);

Modified: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/SmallNumberHandler.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/SmallNumberHandler.java?view=diff&rev=514678&r1=514677&r2=514678
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/SmallNumberHandler.java
(original)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/SmallNumberHandler.java
Mon Mar  5 06:39:42 2007
@@ -19,6 +19,8 @@
 package org.apache.cxf.systest.handlers;
 
 import java.util.Map;
+
+import javax.annotation.PostConstruct;
 import javax.xml.bind.JAXBContext;
 import javax.xml.bind.JAXBException;
 import javax.xml.ws.LogicalMessage;
@@ -34,11 +36,20 @@
 /**
  * handles addition of small numbers.
  */
-public class SmallNumberHandler implements LogicalHandler<LogicalMessageContext> {
-
-
-    // Implementation of javax.xml.ws.handler.Handler
+public class SmallNumberHandler extends TestHandlerBase implements LogicalHandler<LogicalMessageContext>
{
 
+    public SmallNumberHandler() {
+        this(true); 
+    } 
+    
+    public SmallNumberHandler(boolean serverSide) {
+        super(serverSide);
+    }
+    
+    public String getHandlerId() { 
+        return "SmallNumberHandler" + getId();
+    }  
+    
     public final boolean handleMessage(LogicalMessageContext messageContext) {
         //System.out.println("LogicalMessageHandler handleMessage called");
 
@@ -106,6 +117,12 @@
         //System.out.println("LogicalHandler close called");
     }
 
+    @PostConstruct
+    public void doPostConstruct() {
+        methodCalled("doPostConstruct");
+        //System.out.println("-----------doPost-------------");
+    }
+    
     private boolean isSmall(int i) {
         return i > 0 && i <= 10;
     }

Modified: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/TestHandlerBase.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/TestHandlerBase.java?view=diff&rev=514678&r1=514677&r2=514678
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/TestHandlerBase.java
(original)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/TestHandlerBase.java
Mon Mar  5 06:39:42 2007
@@ -102,6 +102,10 @@
         return methodCallCount.containsKey("init");
     }
     
+    public boolean isPostConstructInvoked() {
+        return methodCallCount.containsKey("doPostConstruct");
+    }    
+    
     public void setHandleMessageRet(boolean ret) { 
         handleMessageRet = ret; 
     }



Mime
View raw message