Author: jbonofre
Date: Sat Oct 24 13:55:37 2009
New Revision: 829371

URL: http://svn.apache.org/viewvc?rev=829371&view=rev
Log:
[SMXCOMP-650] Now populate the endpoint descriptor in the validate() in place 
of the start().

Modified:
    
servicemix/components/engines/servicemix-cxf-se/trunk/src/main/java/org/apache/servicemix/cxfse/CxfSeEndpoint.java

Modified: 
servicemix/components/engines/servicemix-cxf-se/trunk/src/main/java/org/apache/servicemix/cxfse/CxfSeEndpoint.java
URL: 
http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-cxf-se/trunk/src/main/java/org/apache/servicemix/cxfse/CxfSeEndpoint.java?rev=829371&r1=829370&r2=829371&view=diff
==============================================================================
--- 
servicemix/components/engines/servicemix-cxf-se/trunk/src/main/java/org/apache/servicemix/cxfse/CxfSeEndpoint.java
 (original)
+++ 
servicemix/components/engines/servicemix-cxf-se/trunk/src/main/java/org/apache/servicemix/cxfse/CxfSeEndpoint.java
 Sat Oct 24 13:55:37 2009
@@ -250,12 +250,18 @@
     @Override
     public void validate() throws DeploymentException {
         if (getPojo() == null) {
-            throw new DeploymentException("pojo must be set");
+            // check if the POJO attribute is given.
+            throw new DeploymentException("pojo attribute is mandatory.");
         }
+        
+        // construct the JBI address
+        String address = "jbi://" + ID_GENERATOR.generateSanitizedId();
+        
+        // construct the CXF server (using JAXB or Aegis)
         if (isUseAegis()) {
             sf = new ServerFactoryBean();
             sf.setServiceBean(getPojo());
-            sf.setAddress("jbi://" + ID_GENERATOR.generateSanitizedId());
+            sf.setAddress(address);
             sf.getServiceFactory().setDataBinding(new AegisDatabinding());
           
             sf.getServiceFactory().setPopulateFromClass(true);
@@ -323,6 +329,42 @@
             }
 
         }
+        
+        // prepare the CXF server in case of JAXB
+        if (!isUseAegis()) {
+            endpoint.publish(address);
+            server = endpoint.getServer();
+        }
+
+        if (getService() == null) {
+            // set the service using CXF endpoint service name
+            setService(server.getEndpoint().getService().getName());
+        }
+
+        if (getEndpoint() == null) {
+            // set the endpoint using the CXF endpoint info
+            setEndpoint(server.getEndpoint().getEndpointInfo()
+                .getName().getLocalPart());
+        }
+        setPojoService(server.getEndpoint().getService().getName());
+        
setPojoEndpoint(server.getEndpoint().getEndpointInfo().getName().getLocalPart());
+        if (!isUseJBIWrapper() && !isUseSOAPEnvelope()) {
+            // cleanup interceptors
+            
removeInterceptor(server.getEndpoint().getBinding().getInInterceptors(), 
"ReadHeadersInterceptor");
+            
removeInterceptor(server.getEndpoint().getBinding().getInFaultInterceptors(), 
"ReadHeadersInterceptor");
+            
removeInterceptor(server.getEndpoint().getBinding().getOutInterceptors(), 
"SoapOutInterceptor");
+            
removeInterceptor(server.getEndpoint().getBinding().getOutFaultInterceptors(), 
"SoapOutInterceptor");
+            
removeInterceptor(server.getEndpoint().getBinding().getOutInterceptors(), 
"StaxOutInterceptor");
+        }
+
+        // publish the WSDL in the endpoint descriptor
+        try {
+            definition = new ServiceWSDLBuilder(getBus(), 
server.getEndpoint().getService().getServiceInfos().iterator().next()).build();
+            description = 
WSDLFactory.newInstance().newWSDLWriter().getDocument(definition);
+        } catch (WSDLException e) {
+            throw new DeploymentException(e);
+        }
+        
         super.validate();
 
     }
@@ -407,52 +449,17 @@
     @Override
     public void start() throws Exception {
         super.start();
-        address = "jbi://" + ID_GENERATOR.generateSanitizedId();
-        try {
-            if (isUseAegis()) {
-                server.start();
-            } else {
-                endpoint.publish(address);
-                server = endpoint.getServer();
-            }
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-
-        if (getService() == null) {
-            setService(server.getEndpoint().getService().getName());
-        }
-        if (getEndpoint() == null) {
-            setEndpoint(server.getEndpoint().getEndpointInfo()
-                .getName().getLocalPart());
-        }
-        setPojoService(server.getEndpoint().getService().getName());
-        setPojoEndpoint(server.getEndpoint().getEndpointInfo()
-                .getName().getLocalPart());
-        if (!isUseJBIWrapper() && !isUseSOAPEnvelope()) {
-            
removeInterceptor(server.getEndpoint().getBinding().getInInterceptors(), 
"ReadHeadersInterceptor");
-            
removeInterceptor(server.getEndpoint().getBinding().getInFaultInterceptors(),
-                              "ReadHeadersInterceptor");
-            
removeInterceptor(server.getEndpoint().getBinding().getOutInterceptors(), 
"SoapOutInterceptor");
-            
removeInterceptor(server.getEndpoint().getBinding().getOutFaultInterceptors(),
-                              "SoapOutInterceptor");
-            
removeInterceptor(server.getEndpoint().getBinding().getOutInterceptors(), 
"StaxOutInterceptor");
-        }
-
-        try {
-            definition = new ServiceWSDLBuilder(getBus(), 
server.getEndpoint().getService().getServiceInfos()
-                .iterator().next()).build();
-            description = 
WSDLFactory.newInstance().newWSDLWriter().getDocument(definition);
-        } catch (WSDLException e) {
-            throw new DeploymentException(e);
+        
+        if (isUseAegis()) {
+            // if aegis databinding is used, start the server
+            server.start();
         }
+        
         ReflectionUtils.doWithFields(getPojo().getClass(), new FieldCallback() 
{
             public void doWith(Field field) throws IllegalArgumentException, 
IllegalAccessException {
                 if (field.getAnnotation(WebServiceRef.class) != null) {
                     ServiceImpl s = new ServiceImpl(getBus(), null, null, 
field.getType());
-                    s
-                        .addPort(new QName("port"), 
JBITransportFactory.TRANSPORT_ID,
-                                 "jbi://" + 
ID_GENERATOR.generateSanitizedId());
+                    s.addPort(new QName("port"), 
JBITransportFactory.TRANSPORT_ID, "jbi://" + 
ID_GENERATOR.generateSanitizedId());
                     Object o = s.getPort(new QName("port"), field.getType());
                     field.setAccessible(true);
                     field.set(getPojo(), o);
@@ -460,6 +467,7 @@
             }
         });
         ReflectionUtils.callLifecycleMethod(getPojo(), PostConstruct.class);
+        // inject the POJO
         injectPojo();
     }
 


Reply via email to