You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by jl...@apache.org on 2007/06/13 11:53:00 UTC

svn commit: r546794 - in /incubator/cxf/trunk/rt/frontend: jaxws/src/main/java/org/apache/cxf/jaxws/EndpointImpl.java jaxws/src/main/java/org/apache/cxf/jaxws/JaxWsServerFactoryBean.java simple/src/main/java/org/apache/cxf/frontend/ServerFactoryBean.java

Author: jliu
Date: Wed Jun 13 02:52:59 2007
New Revision: 546794

URL: http://svn.apache.org/viewvc?view=rev&rev=546794
Log:
CXF-717: Refactor EndpointImpl and JaxWsServerFactoryBean so that EndpointImpl becomes a pure wrapper on top of JaxWsServerFactoryBean.

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/JaxWsServerFactoryBean.java
    incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/ServerFactoryBean.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=546794&r1=546793&r2=546794
==============================================================================
--- 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 Wed Jun 13 02:52:59 2007
@@ -25,19 +25,14 @@
 import java.util.Map;
 import java.util.concurrent.CopyOnWriteArrayList;
 import java.util.concurrent.Executor;
-import java.util.logging.Logger;
 
 import javax.xml.namespace.QName;
 import javax.xml.transform.Source;
 import javax.xml.ws.Binding;
-import javax.xml.ws.WebServiceException;
 import javax.xml.ws.WebServicePermission;
-import javax.xml.ws.handler.Handler;
 
 import org.apache.cxf.Bus;
 import org.apache.cxf.BusFactory;
-import org.apache.cxf.common.injection.ResourceInjector;
-import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.configuration.Configurable;
 import org.apache.cxf.configuration.Configurer;
 import org.apache.cxf.endpoint.Server;
@@ -45,14 +40,9 @@
 import org.apache.cxf.feature.AbstractFeature;
 import org.apache.cxf.interceptor.Interceptor;
 import org.apache.cxf.interceptor.InterceptorProvider;
-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;
 import org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean;
-import org.apache.cxf.resource.DefaultResourceManager;
-import org.apache.cxf.resource.ResourceManager;
-import org.apache.cxf.resource.ResourceResolver;
 import org.apache.cxf.service.Service;
 
 public class EndpointImpl extends javax.xml.ws.Endpoint 
@@ -65,12 +55,9 @@
     public static final String CHECK_PUBLISH_ENDPOINT_PERMISSON_PROPERTY =
         "org.apache.cxf.jaxws.checkPublishEndpointPermission";
 
-    private static final Logger LOG = LogUtils.getL7dLogger(EndpointImpl.class);
-
     private static final WebServicePermission PUBLISH_PERMISSION =
         new WebServicePermission("publishEndpoint");
     
-    protected boolean doInit;
     private Bus bus;
     private Object implementor;
     private Server server;
@@ -102,8 +89,6 @@
         this.bus = b;
         this.serverFactory = sf;
         this.implementor = implementor;
-        
-        doInit = true;
     }
     
     /**
@@ -120,8 +105,6 @@
         this.bindingUri = bindingUri;
         wsdlLocation = wsdl == null ? null : new String(wsdl);
         serverFactory = new JaxWsServerFactoryBean();
-        
-        doInit = true; 
     }
     
     
@@ -215,27 +198,7 @@
             server.stop();
         }
     }    
-
-    /**
-     * inject resources into servant.  The resources are injected
-     * according to @Resource annotations.  See JSR 250 for more
-     * information.
-     */
-    /**
-     * @param instance
-     */
-    protected void injectResources(Object instance) {
-        if (instance != null) {
-            ResourceManager resourceManager = bus.getExtension(ResourceManager.class);
-            List<ResourceResolver> resolvers = resourceManager.getResourceResolvers();
-            resourceManager = new DefaultResourceManager(resolvers); 
-            resourceManager.addResourceResolver(new WebServiceContextResourceResolver());
-            ResourceInjector injector = new ResourceInjector(resourceManager);
-            injector.inject(instance);
-        }
-    }
-
-    
+   
     public String getBeanName() {
         return endpointName.toString() + ".jaxws-endpoint";
     }
@@ -313,8 +276,6 @@
             
             server = serverFactory.create();
             
-            init();
-            
             org.apache.cxf.endpoint.Endpoint endpoint = getEndpoint();
             if (getInInterceptors() != null) {
                 endpoint.getInInterceptors().addAll(getInInterceptors());
@@ -353,38 +314,6 @@
         if (null != configurer) {
             configurer.configureBean(instance);
         }
-    }
-
-
-    private synchronized void init() {
-        if (doInit) {
-            try {
-                injectResources(implementor);
-                buildHandlerChain();
-            } catch (Exception ex) {
-                if (ex instanceof WebServiceException) { 
-                    throw (WebServiceException)ex; 
-                }
-                throw new WebServiceException("Creation of Endpoint failed", ex);
-            }
-        }
-        doInit = false;
-    }
-    
-    /**
-     * Obtain handler chain from annotations.
-     *
-     */
-    private void buildHandlerChain() {
-        LOG.fine("loading handler chain for endpoint");
-        AnnotationHandlerChainBuilder builder = new AnnotationHandlerChainBuilder();
-
-        List<Handler> chain = builder.buildHandlerChainFromClass(getImplementorClass(), endpointName);
-        for (Handler h : chain) {
-            injectResources(h);
-        }
-        
-        getBinding().setHandlerChain(chain);
     }
     
     protected void checkPublishPermission() {

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JaxWsServerFactoryBean.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JaxWsServerFactoryBean.java?view=diff&rev=546794&r1=546793&r2=546794
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JaxWsServerFactoryBean.java (original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JaxWsServerFactoryBean.java Wed Jun 13 02:52:59 2007
@@ -19,17 +19,30 @@
 package org.apache.cxf.jaxws;
 
 
+
+import java.util.List;
+
 import javax.xml.soap.SOAPMessage;
+import javax.xml.ws.WebServiceException;
+import javax.xml.ws.handler.Handler;
 import javax.xml.ws.soap.SOAPBinding;
 
 import org.apache.cxf.binding.AbstractBindingFactory;
 import org.apache.cxf.binding.soap.Soap12;
 import org.apache.cxf.binding.soap.SoapBindingFactory;
 import org.apache.cxf.binding.soap.model.SoapBindingInfo;
+import org.apache.cxf.common.injection.ResourceInjector;
+import org.apache.cxf.endpoint.Server;
 import org.apache.cxf.frontend.ServerFactoryBean;
 import org.apache.cxf.jaxws.binding.soap.JaxWsSoapBindingConfiguration;
+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;
 import org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean;
+import org.apache.cxf.resource.DefaultResourceManager;
+import org.apache.cxf.resource.ResourceManager;
+import org.apache.cxf.resource.ResourceResolver;
 import org.apache.cxf.service.invoker.Invoker;
 import org.apache.cxf.service.model.BindingInfo;
 
@@ -44,8 +57,11 @@
  * This will start a server for you and register it with the ServerManager. 
  */
 public class JaxWsServerFactoryBean extends ServerFactoryBean {
+    protected boolean doInit;
+    
     public JaxWsServerFactoryBean() {
         this(new JaxWsServiceFactoryBean());
+        doInit = true;
     }
     public JaxWsServerFactoryBean(JaxWsServiceFactoryBean serviceFactory) {
         setServiceFactory(serviceFactory);
@@ -54,6 +70,7 @@
             = new JaxWsSoapBindingConfiguration(serviceFactory);
         
         setBindingConfig(defConfig);
+        doInit = true;
     }
 
     @Override
@@ -121,5 +138,60 @@
         return bindingInfo;
     }
     
+    public Server create() {
+        Server server = super.create();
+        init();
+        return server;
+    }
+    
+    private synchronized void init() {
+        if (doInit) {
+            try {
+                injectResources(getServiceBean());
+                buildHandlerChain();
+            } catch (Exception ex) {
+                if (ex instanceof WebServiceException) { 
+                    throw (WebServiceException)ex; 
+                }
+                throw new WebServiceException("Creation of Endpoint failed", ex);
+            }
+        }
+        doInit = false;
+    }
     
+    
+    /**
+     * Obtain handler chain from annotations.
+     *
+     */
+    private void buildHandlerChain() {
+        AnnotationHandlerChainBuilder builder = new AnnotationHandlerChainBuilder();
+
+        List<Handler> chain = builder.buildHandlerChainFromClass(getServiceBean().getClass(),
+                                                                 getEndpointName());
+        for (Handler h : chain) {
+            injectResources(h);
+        }
+        
+        ((JaxWsEndpointImpl)getServer().getEndpoint()).getJaxwsBinding().setHandlerChain(chain);
+    }
+    
+    /**
+     * inject resources into servant.  The resources are injected
+     * according to @Resource annotations.  See JSR 250 for more
+     * information.
+     */
+    /**
+     * @param instance
+     */
+    protected void injectResources(Object instance) {
+        if (instance != null) {
+            ResourceManager resourceManager = getBus().getExtension(ResourceManager.class);
+            List<ResourceResolver> resolvers = resourceManager.getResourceResolvers();
+            resourceManager = new DefaultResourceManager(resolvers); 
+            resourceManager.addResourceResolver(new WebServiceContextResourceResolver());
+            ResourceInjector injector = new ResourceInjector(resourceManager);
+            injector.inject(instance);
+        }
+    }  
 }

Modified: incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/ServerFactoryBean.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/ServerFactoryBean.java?view=diff&rev=546794&r1=546793&r2=546794
==============================================================================
--- incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/ServerFactoryBean.java (original)
+++ incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/ServerFactoryBean.java Wed Jun 13 02:52:59 2007
@@ -155,6 +155,9 @@
     }
 
     public Object getServiceBean() {
+        if (serviceBean == null) {
+            return getServiceFactory().getServiceClass();
+        }
         return serviceBean;
     }