servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ff...@apache.org
Subject svn commit: r660430 - in /servicemix/smx3/trunk/deployables: bindingcomponents/servicemix-cxf-bc/src/main/java/org/apache/servicemix/cxfbc/ bindingcomponents/servicemix-cxf-bc/src/test/java/org/apache/servicemix/cxfbc/ serviceengines/servicemix-cxf-se/...
Date Tue, 27 May 2008 08:50:32 GMT
Author: ffang
Date: Tue May 27 01:50:31 2008
New Revision: 660430

URL: http://svn.apache.org/viewvc?rev=660430&view=rev
Log:
[SM-1372]support exception check for cxf bc provider outgoing chain

Modified:
    servicemix/smx3/trunk/deployables/bindingcomponents/servicemix-cxf-bc/src/main/java/org/apache/servicemix/cxfbc/CxfBcProvider.java
    servicemix/smx3/trunk/deployables/bindingcomponents/servicemix-cxf-bc/src/test/java/org/apache/servicemix/cxfbc/CxfBcProviderTest.java
    servicemix/smx3/trunk/deployables/bindingcomponents/servicemix-cxf-bc/src/test/java/org/apache/servicemix/cxfbc/GreeterImplForProvider.java
    servicemix/smx3/trunk/deployables/serviceengines/servicemix-cxf-se/src/main/java/org/apache/servicemix/cxfse/CxfSeProxyFactoryBean.java

Modified: servicemix/smx3/trunk/deployables/bindingcomponents/servicemix-cxf-bc/src/main/java/org/apache/servicemix/cxfbc/CxfBcProvider.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/trunk/deployables/bindingcomponents/servicemix-cxf-bc/src/main/java/org/apache/servicemix/cxfbc/CxfBcProvider.java?rev=660430&r1=660429&r2=660430&view=diff
==============================================================================
--- servicemix/smx3/trunk/deployables/bindingcomponents/servicemix-cxf-bc/src/main/java/org/apache/servicemix/cxfbc/CxfBcProvider.java
(original)
+++ servicemix/smx3/trunk/deployables/bindingcomponents/servicemix-cxf-bc/src/main/java/org/apache/servicemix/cxfbc/CxfBcProvider.java
Tue May 27 01:50:31 2008
@@ -28,6 +28,7 @@
 import javax.jbi.management.DeploymentException;
 import javax.jbi.messaging.ExchangeStatus;
 import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.MessagingException;
 import javax.jbi.messaging.NormalizedMessage;
 import javax.wsdl.WSDLException;
 import javax.wsdl.factory.WSDLFactory;
@@ -36,7 +37,10 @@
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamWriter;
 import javax.xml.transform.Source;
+import javax.xml.transform.dom.DOMSource;
 import javax.xml.transform.stream.StreamSource;
+
+import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
 
@@ -45,6 +49,9 @@
 import org.apache.cxf.Bus;
 import org.apache.cxf.binding.AbstractBindingFactory;
 
+import org.apache.cxf.binding.jbi.JBIConstants;
+import org.apache.cxf.binding.jbi.JBIFault;
+
 import org.apache.cxf.binding.soap.interceptor.SoapActionOutInterceptor;
 import org.apache.cxf.binding.soap.interceptor.SoapOutInterceptor;
 import org.apache.cxf.binding.soap.interceptor.SoapPreProtocolOutInterceptor;
@@ -56,7 +63,6 @@
 import org.apache.cxf.interceptor.Interceptor;
 import org.apache.cxf.interceptor.StaxOutInterceptor;
 
-
 import org.apache.cxf.message.Exchange;
 import org.apache.cxf.message.ExchangeImpl;
 import org.apache.cxf.message.Message;
@@ -77,6 +83,7 @@
 import org.apache.cxf.wsdl11.ServiceWSDLBuilder;
 import org.apache.cxf.wsdl11.WSDLServiceBuilder;
 import org.apache.cxf.wsdl11.WSDLServiceFactory;
+import org.apache.servicemix.JbiConstants;
 import org.apache.servicemix.common.endpoints.ProviderEndpoint;
 import org.apache.servicemix.cxfbc.interceptors.JbiOutInterceptor;
 import org.apache.servicemix.cxfbc.interceptors.JbiOutWsdl1Interceptor;
@@ -84,9 +91,6 @@
 import org.apache.servicemix.soap.util.DomUtil;
 import org.springframework.core.io.Resource;
 
-
-
-
 /**
  * 
  * @author gnodet
@@ -95,8 +99,6 @@
 public class CxfBcProvider extends ProviderEndpoint implements
         CxfBcEndpointWithInterceptor {
 
-        
-    
     List<Interceptor> in = new CopyOnWriteArrayList<Interceptor>();
 
     List<Interceptor> out = new CopyOnWriteArrayList<Interceptor>();
@@ -104,65 +106,65 @@
     List<Interceptor> outFault = new CopyOnWriteArrayList<Interceptor>();
 
     List<Interceptor> inFault = new CopyOnWriteArrayList<Interceptor>();
-    
+
     private Resource wsdl;
-    
+
     private String busCfg;
-    
+
     private Bus bus;
-    
+
     private ConduitInitiator conduitInit;
-    
+
     private URI locationURI;
-    
+
     private EndpointInfo ei;
-    
+
     private Endpoint ep;
 
     private Service cxfService;
-    
+
     private boolean mtomEnabled;
-    
+
     private boolean useJBIWrapper = true;
-    
-    
-    
+
     public void processExchange(MessageExchange exchange) {
-        
+
     }
 
     public void process(MessageExchange exchange) throws Exception {
-        
+
         if (exchange.getStatus() != ExchangeStatus.ACTIVE) {
             return;
         }
         NormalizedMessage nm = exchange.getMessage("in");
-        
-        Conduit conduit = conduitInit.getConduit(ei);               
-        CxfBcProviderMessageObserver obs = new CxfBcProviderMessageObserver(exchange, this);
+
+        Conduit conduit = conduitInit.getConduit(ei);
+        CxfBcProviderMessageObserver obs = new CxfBcProviderMessageObserver(
+                exchange, this);
         conduit.setMessageObserver(obs);
         Message message = ep.getBinding().createMessage();
         message.put(MessageExchange.class, exchange);
         Exchange cxfExchange = new ExchangeImpl();
-        
+
         message.setExchange(cxfExchange);
-        cxfExchange.setOutMessage(message);       
-        
+        cxfExchange.setOutMessage(message);
+
         QName opeName = exchange.getOperation();
         BindingOperationInfo boi = null;
         if (opeName == null) {
-            // if interface only have one operation, may not specify the opeName in MessageExchange
+            // if interface only have one operation, may not specify the opeName
+            // in MessageExchange
             if (ei.getBinding().getOperations().size() == 1) {
                 boi = ei.getBinding().getOperations().iterator().next();
             } else {
-                throw new Fault(
-                            new Exception("Operation not bound on this MessageExchange"));
-                
+                throw new Fault(new Exception(
+                        "Operation not bound on this MessageExchange"));
+
             }
         } else {
-            boi = ei.getBinding().getOperation(exchange.getOperation());   
+            boi = ei.getBinding().getOperation(exchange.getOperation());
         }
-        cxfExchange.setOneWay(boi.getOperationInfo().isOneWay()); 
+        cxfExchange.setOneWay(boi.getOperationInfo().isOneWay());
         cxfExchange.put(BindingOperationInfo.class, boi);
         cxfExchange.put(Endpoint.class, ep);
         cxfExchange.put(Service.class, cxfService);
@@ -173,49 +175,98 @@
             outList.add(new JbiOutInterceptor());
             outList.add(new MtomCheckInterceptor(true));
             outList.add(new AttachmentOutInterceptor());
-            
+
         }
-        
+
         outList.add(new JbiOutInterceptor());
         outList.add(new JbiOutWsdl1Interceptor(isUseJBIWrapper()));
         outList.add(new SoapPreProtocolOutInterceptor());
         outList.add(new SoapOutInterceptor(getBus()));
         outList.add(new SoapActionOutInterceptor());
-        PhaseInterceptorChain outChain = outboundChainCache.get(pm.getOutPhases(), outList);
+        PhaseInterceptorChain outChain = outboundChainCache.get(pm
+                .getOutPhases(), outList);
         outChain.add(getOutInterceptors());
         outChain.add(getOutFaultInterceptors());
         message.setInterceptorChain(outChain);
-        InputStream is = JBIMessageHelper.convertMessageToInputStream(nm.getContent());
-        
+        InputStream is = JBIMessageHelper.convertMessageToInputStream(nm
+                .getContent());
+
         StreamSource source = new StreamSource(is);
         message.setContent(Source.class, source);
-        
+
         message.setContent(InputStream.class, is);
-        
+
         conduit.prepare(message);
         OutputStream os = message.getContent(OutputStream.class);
         XMLStreamWriter writer = message.getContent(XMLStreamWriter.class);
-        
+
         String encoding = getEncoding(message);
-        
+
         try {
-            writer = StaxOutInterceptor.getXMLOutputFactory(message).createXMLStreamWriter(os,
encoding);
+            writer = StaxOutInterceptor.getXMLOutputFactory(message)
+                    .createXMLStreamWriter(os, encoding);
         } catch (XMLStreamException e) {
             //
         }
         message.setContent(XMLStreamWriter.class, writer);
         message.put(org.apache.cxf.message.Message.REQUESTOR_ROLE, true);
-        outChain.doIntercept(message);
-        XMLStreamWriter xtw = message.getContent(XMLStreamWriter.class);
-        if (xtw != null) {
-            xtw.writeEndDocument();
-            xtw.close();
+        try {
+            outChain.doIntercept(message);
+            //Check to see if there is a Fault from the outgoing chain
+            Exception ex = message.getContent(Exception.class);
+            if (ex != null) {
+                throw ex;
+            }
+            ex = message.getExchange().get(Exception.class);
+            if (ex != null) {
+                throw ex;
+            }
+            
+            XMLStreamWriter xtw = message.getContent(XMLStreamWriter.class);
+            if (xtw != null) {
+                xtw.writeEndDocument();
+                xtw.close();
+            }
+
+            os.flush();
+            is.close();
+            os.close();
+        } catch (Exception e) {
+            faultProcess(exchange, message, e);
         }
 
-        os.flush();
-        is.close();
-        os.close();
+    }
+
+    private void faultProcess(MessageExchange exchange, Message message, Exception e) throws
MessagingException {
+        javax.jbi.messaging.Fault fault = exchange.createFault();
+        if (e.getCause() != null) {
+            handleJBIFault(message, e.getCause().getMessage());
+        } else {
+            handleJBIFault(message, e.getMessage());
+        }
+        fault.setContent(message.getContent(Source.class));
+        exchange.setFault(fault);
+        boolean txSync = exchange.getStatus() == ExchangeStatus.ACTIVE
+                && exchange.isTransacted()
+                && Boolean.TRUE.equals(exchange
+                        .getProperty(JbiConstants.SEND_SYNC));
+        if (txSync) {
+            getContext().getDeliveryChannel().sendSync(exchange);
+        } else {
+            getContext().getDeliveryChannel().send(exchange);
+        }
+    }
 
+   
+    private void handleJBIFault(Message message, String detail) {
+        Document doc = DomUtil.createDocument();
+        Element jbiFault = DomUtil.createElement(doc, new QName(
+                JBIConstants.NS_JBI_BINDING, JBIFault.JBI_FAULT_ROOT));
+        Node jbiFaultDetail = DomUtil.createElement(jbiFault, new QName("", JBIFault.JBI_FAULT_DETAIL));
+        jbiFaultDetail.setTextContent(detail);
+        jbiFault.appendChild(jbiFaultDetail);
+        message.setContent(Source.class, new DOMSource(doc));
+        message.put("jbiFault", true);
     }
     
     public List<Interceptor> getOutFaultInterceptors() {
@@ -257,7 +308,7 @@
     public Resource getWsdl() {
         return wsdl;
     }
-    
+
     @Override
     public void validate() throws DeploymentException {
         try {
@@ -273,8 +324,7 @@
                     // use wsdl manager to parse wsdl or get cached definition
                     definition = getBus().getExtension(WSDLManager.class)
                             .getDefinition(wsdl.getURL());
-                    
-                    
+
                 } catch (WSDLException ex) {
                     // 
                 }
@@ -283,60 +333,70 @@
                 cxfService = factory.create();
                 ei = cxfService.getServiceInfos().iterator().next()
                         .getEndpoints().iterator().next();
-                          
+
                 for (ServiceInfo serviceInfo : cxfService.getServiceInfos()) {
                     if (serviceInfo.getName().equals(service)
-                        && getEndpoint() != null 
-                        && serviceInfo.getEndpoint(new QName(
-                                serviceInfo.getName().getNamespaceURI(), getEndpoint()))
!= null) {
-                        ei = serviceInfo.getEndpoint(new QName(
-                                    serviceInfo.getName().getNamespaceURI(), getEndpoint()));
-                 
+                            && getEndpoint() != null
+                            && serviceInfo
+                                    .getEndpoint(new QName(serviceInfo
+                                            .getName().getNamespaceURI(),
+                                            getEndpoint())) != null) {
+                        ei = serviceInfo.getEndpoint(new QName(serviceInfo
+                                .getName().getNamespaceURI(), getEndpoint()));
+
                     }
                 }
-                //transform import xsd to inline xsd
-                ServiceWSDLBuilder swBuilder = new ServiceWSDLBuilder(getBus(), cxfService.getServiceInfos());
+                // transform import xsd to inline xsd
+                ServiceWSDLBuilder swBuilder = new ServiceWSDLBuilder(getBus(),
+                        cxfService.getServiceInfos());
                 ServiceInfo serInfo = new ServiceInfo();
-                                                 
+
                 Map<String, Element> schemaList = new HashMap<String, Element>();
                 SchemaUtil schemaUtil = new SchemaUtil(bus, schemaList);
                 schemaUtil.getSchemas(definition, serInfo);
-                
+
                 serInfo = ei.getService();
                 for (String key : schemaList.keySet()) {
                     Element ele = schemaList.get(key);
                     for (SchemaInfo sInfo : serInfo.getSchemas()) {
                         Node nl = sInfo.getElement().getElementsByTagNameNS(
-                                  "http://www.w3.org/2001/XMLSchema", "import").item(0);
-                        if (sInfo.getNamespaceURI() == null //it's import schema 
-                            && nl != null 
-                            && ((Element)nl).getAttribute("namespace")
-                                .equals(ele.getAttribute("targetNamespace"))) {
-                            
+                                "http://www.w3.org/2001/XMLSchema", "import")
+                                .item(0);
+                        if (sInfo.getNamespaceURI() == null // it's import
+                                                            // schema
+                                && nl != null
+                                && ((Element) nl)
+                                        .getAttribute("namespace")
+                                        .equals(
+                                                ele
+                                                        .getAttribute("targetNamespace")))
{
+
                             sInfo.setElement(ele);
                         }
                     }
                 }
                 serInfo.setProperty(WSDLServiceBuilder.WSDL_DEFINITION, null);
-                description = WSDLFactory.newInstance().newWSDLWriter().getDocument(swBuilder.build());
-                               
+                description = WSDLFactory.newInstance().newWSDLWriter()
+                        .getDocument(swBuilder.build());
 
                 if (endpoint == null) {
                     endpoint = ei.getName().getLocalPart();
                 }
                 ei.getBinding().setProperty(
-                        AbstractBindingFactory.DATABINDING_DISABLED, Boolean.TRUE);
-                
-                
+                        AbstractBindingFactory.DATABINDING_DISABLED,
+                        Boolean.TRUE);
+
                 ep = new EndpointImpl(getBus(), cxfService, ei);
-                
-                //init transport
+
+                // init transport
                 if (locationURI != null) {
                     ei.setAddress(locationURI.toString());
                 }
-                
-                ConduitInitiatorManager conduitMgr = getBus().getExtension(ConduitInitiatorManager.class);
-                conduitInit = conduitMgr.getConduitInitiator(ei.getTransportId());
+
+                ConduitInitiatorManager conduitMgr = getBus().getExtension(
+                        ConduitInitiatorManager.class);
+                conduitInit = conduitMgr.getConduitInitiator(ei
+                        .getTransportId());
                 super.validate();
             }
         } catch (DeploymentException e) {
@@ -349,9 +409,9 @@
     @Override
     public void start() throws Exception {
         super.start();
-        
+
     }
-    
+
     protected Bus getBus() {
         if (getBusCfg() != null) {
             if (bus == null) {
@@ -363,7 +423,7 @@
             return ((CxfBcComponent) getServiceUnit().getComponent()).getBus();
         }
     }
-    
+
     public void setBusCfg(String busCfg) {
         this.busCfg = busCfg;
     }
@@ -379,26 +439,26 @@
     public URI getLocationURI() {
         return locationURI;
     }
-    
+
     private String getEncoding(Message message) {
         Exchange ex = message.getExchange();
-        String encoding = (String)message.get(Message.ENCODING);
+        String encoding = (String) message.get(Message.ENCODING);
         if (encoding == null && ex.getInMessage() != null) {
             encoding = (String) ex.getInMessage().get(Message.ENCODING);
             message.put(Message.ENCODING, encoding);
         }
-        
+
         if (encoding == null) {
             encoding = "UTF-8";
             message.put(Message.ENCODING, encoding);
         }
         return encoding;
     }
-    
+
     Endpoint getCxfEndpoint() {
         return this.ep;
     }
-    
+
     EndpointInfo getEndpointInfo() {
         return this.ei;
     }

Modified: servicemix/smx3/trunk/deployables/bindingcomponents/servicemix-cxf-bc/src/test/java/org/apache/servicemix/cxfbc/CxfBcProviderTest.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/trunk/deployables/bindingcomponents/servicemix-cxf-bc/src/test/java/org/apache/servicemix/cxfbc/CxfBcProviderTest.java?rev=660430&r1=660429&r2=660430&view=diff
==============================================================================
--- servicemix/smx3/trunk/deployables/bindingcomponents/servicemix-cxf-bc/src/test/java/org/apache/servicemix/cxfbc/CxfBcProviderTest.java
(original)
+++ servicemix/smx3/trunk/deployables/bindingcomponents/servicemix-cxf-bc/src/test/java/org/apache/servicemix/cxfbc/CxfBcProviderTest.java
Tue May 27 01:50:31 2008
@@ -52,6 +52,8 @@
     private InOut io;
     private CxfSeComponent component;
     
+    
+    
     protected void setUp() throws Exception {
         super.setUp();
         
@@ -63,6 +65,32 @@
         component.getServiceUnitManager().start("proxy");
     }
     
+    protected void tearDown() throws Exception {
+        component.getServiceUnitManager().stop("proxy");
+        component.getServiceUnitManager().shutDown("proxy");
+        component.getServiceUnitManager().undeploy("proxy", getServiceUnitPath("provider"));
+    }
+    
+    public void testExternalServerNotExist() throws Exception {
+        client = new DefaultServiceMixClient(jbi);
+        io = client.createInOutExchange();
+        io.setService(new QName("http://apache.org/hello_world_soap_http", "SOAPServiceProvider"));
+        io.setInterfaceName(new QName("http://apache.org/hello_world_soap_http", "Greeter"));
+        io.setOperation(new QName("http://apache.org/hello_world_soap_http", "greetMe"));
+        //send message to proxy
+        io.getInMessage().setContent(new StringSource(
+                "<message xmlns='http://java.sun.com/xml/ns/jbi/wsdl-11-wrapper'>"
+              + "<part> "
+              + "<greetMe xmlns='http://apache.org/hello_world_soap_http/types'><requestType>"
+              + "ffang with no server"
+              + "</requestType></greetMe>"
+              + "</part> "
+              + "</message>"));
+        client.sendSync(io);
+        assertTrue(new SourceTransformer().contentToString(
+                io.getOutMessage()).indexOf("server is stop") >= 0);
+        
+    }
     
     public void testProvider() throws Exception {
         LOG.info("test provider");
@@ -116,6 +144,7 @@
         assertTrue(new SourceTransformer().contentToString(
                 io.getOutMessage()).indexOf("Hello exception test Negative number cant be
added!") >= 0);
         
+        
         //test onway
         factory = new JaxWsServerFactoryBean();
         factory.setServiceClass(Greeter.class);

Modified: servicemix/smx3/trunk/deployables/bindingcomponents/servicemix-cxf-bc/src/test/java/org/apache/servicemix/cxfbc/GreeterImplForProvider.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/trunk/deployables/bindingcomponents/servicemix-cxf-bc/src/test/java/org/apache/servicemix/cxfbc/GreeterImplForProvider.java?rev=660430&r1=660429&r2=660430&view=diff
==============================================================================
--- servicemix/smx3/trunk/deployables/bindingcomponents/servicemix-cxf-bc/src/test/java/org/apache/servicemix/cxfbc/GreeterImplForProvider.java
(original)
+++ servicemix/smx3/trunk/deployables/bindingcomponents/servicemix-cxf-bc/src/test/java/org/apache/servicemix/cxfbc/GreeterImplForProvider.java
Tue May 27 01:50:31 2008
@@ -88,6 +88,9 @@
                 for (int i = 0; i < clients.length; i++) {
                     ret += i * 2 + " ";
                 }
+            } else if ("ffang with no server".equals(me)) {
+                //should catch exception since external server is stop
+                getCalculator().add(1, 2);
             }
                         
         } catch (AddNumbersFault e) {
@@ -97,6 +100,8 @@
             ret = ret + e.getFaultInfo().getId();
         } catch (InterruptedException e) {
             //
+        } catch (Exception e) {
+            ret = ret + "server is stop";
         }
         return "Hello " + me  + " " + ret;
     }

Modified: servicemix/smx3/trunk/deployables/serviceengines/servicemix-cxf-se/src/main/java/org/apache/servicemix/cxfse/CxfSeProxyFactoryBean.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/trunk/deployables/serviceengines/servicemix-cxf-se/src/main/java/org/apache/servicemix/cxfse/CxfSeProxyFactoryBean.java?rev=660430&r1=660429&r2=660430&view=diff
==============================================================================
--- servicemix/smx3/trunk/deployables/serviceengines/servicemix-cxf-se/src/main/java/org/apache/servicemix/cxfse/CxfSeProxyFactoryBean.java
(original)
+++ servicemix/smx3/trunk/deployables/serviceengines/servicemix-cxf-se/src/main/java/org/apache/servicemix/cxfse/CxfSeProxyFactoryBean.java
Tue May 27 01:50:31 2008
@@ -78,6 +78,9 @@
     private Object createProxy() throws Exception {
         JaxWsProxyFactoryBean cf = new JaxWsProxyFactoryBean();
         cf.setServiceName(getService());
+        if (getEndpoint() != null) {
+            cf.setEndpointName(new QName(getService().getNamespaceURI(), getEndpoint()));
+        }
         cf.setServiceClass(type);
         cf.setAddress("jbi://" + new IdGenerator().generateSanitizedId());
         if (isUseJBIWrapper()) {



Mime
View raw message