cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ff...@apache.org
Subject svn commit: r713664 - in /cxf/branches/2.0.x-fixes/rt/bindings/jbi/src/main/java/org/apache/cxf/binding/jbi/interceptor: JBIWrapperInInterceptor.java JBIWrapperOutInterceptor.java
Date Thu, 13 Nov 2008 06:54:35 GMT
Author: ffang
Date: Wed Nov 12 22:54:34 2008
New Revision: 713664

URL: http://svn.apache.org/viewvc?rev=713664&view=rev
Log:
[CXF-1910]JBI binding should honor aegis databinding

Modified:
    cxf/branches/2.0.x-fixes/rt/bindings/jbi/src/main/java/org/apache/cxf/binding/jbi/interceptor/JBIWrapperInInterceptor.java
    cxf/branches/2.0.x-fixes/rt/bindings/jbi/src/main/java/org/apache/cxf/binding/jbi/interceptor/JBIWrapperOutInterceptor.java

Modified: cxf/branches/2.0.x-fixes/rt/bindings/jbi/src/main/java/org/apache/cxf/binding/jbi/interceptor/JBIWrapperInInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.0.x-fixes/rt/bindings/jbi/src/main/java/org/apache/cxf/binding/jbi/interceptor/JBIWrapperInInterceptor.java?rev=713664&r1=713663&r2=713664&view=diff
==============================================================================
--- cxf/branches/2.0.x-fixes/rt/bindings/jbi/src/main/java/org/apache/cxf/binding/jbi/interceptor/JBIWrapperInInterceptor.java
(original)
+++ cxf/branches/2.0.x-fixes/rt/bindings/jbi/src/main/java/org/apache/cxf/binding/jbi/interceptor/JBIWrapperInInterceptor.java
Wed Nov 12 22:54:34 2008
@@ -18,7 +18,8 @@
  */
 package org.apache.cxf.binding.jbi.interceptor;
 
-import java.util.ArrayList;
+import java.net.URI;
+import java.net.URISyntaxException;
 import java.util.List;
 import java.util.ResourceBundle;
 import java.util.logging.Logger;
@@ -38,18 +39,22 @@
 import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.message.Exchange;
 import org.apache.cxf.message.Message;
+import org.apache.cxf.message.MessageContentsList;
 import org.apache.cxf.phase.Phase;
 import org.apache.cxf.service.model.BindingInfo;
-import org.apache.cxf.service.model.BindingMessageInfo;
 import org.apache.cxf.service.model.BindingOperationInfo;
+import org.apache.cxf.service.model.EndpointInfo;
 import org.apache.cxf.service.model.MessageInfo;
 import org.apache.cxf.service.model.MessagePartInfo;
+import org.apache.cxf.service.model.OperationInfo;
+import org.apache.cxf.service.model.ServiceInfo;
 import org.apache.cxf.staxutils.DepthXMLStreamReader;
 import org.apache.cxf.staxutils.StaxUtils;
 
 public class JBIWrapperInInterceptor extends AbstractInDatabindingInterceptor {
 
-    private static final Logger LOG = LogUtils.getL7dLogger(JBIWrapperInInterceptor.class);
+    private static final Logger LOG = LogUtils
+            .getL7dLogger(JBIWrapperInInterceptor.class);
 
     private static final ResourceBundle BUNDLE = LOG.getResourceBundle();
 
@@ -70,11 +75,13 @@
         BindingInfo binding = ep.getEndpointInfo().getBinding();
         if (!(binding instanceof JBIBindingInfo)) {
             throw new IllegalStateException(
-                  new org.apache.cxf.common.i18n.Message("NEED_JBIBINDING", BUNDLE).toString());
+                    new org.apache.cxf.common.i18n.Message("NEED_JBIBINDING",
+                            BUNDLE).toString());
         }
 
         if (!StaxUtils.toNextElement(reader)) {
-            throw new Fault(new org.apache.cxf.common.i18n.Message("NO_OPERATION_ELEMENT",
BUNDLE));
+            throw new Fault(new org.apache.cxf.common.i18n.Message(
+                    "NO_OPERATION_ELEMENT", BUNDLE));
         }
 
         Exchange ex = message.getExchange();
@@ -90,53 +97,150 @@
             }
         }
 
-
         // handling xml normal inbound message
         if (!startQName.equals(JBIConstants.JBI_WRAPPER_MESSAGE)) {
             throw new Fault(new org.apache.cxf.common.i18n.Message(
                     "NO_JBI_MESSAGE_ELEMENT", BUNDLE));
         }
-
+        
         try {
+            
             BindingOperationInfo bop = ex.get(BindingOperationInfo.class);
             DataReader<XMLStreamReader> dr = getDataReader(message);
-            List<Object> parameters = new ArrayList<Object>();
+            boolean requestor = isRequestor(message);
+            MessageContentsList parameters = new MessageContentsList();
             reader.next();
-            BindingMessageInfo messageInfo = !isRequestor(message) ? bop.getInput() : bop.getOutput();
-            message.put(MessageInfo.class, messageInfo.getMessageInfo());
-            for (MessagePartInfo part : messageInfo.getMessageParts()) {
-                if (!StaxUtils.skipToStartOfElement(reader)) {
-                    throw new Fault(new org.apache.cxf.common.i18n.Message(
-                            "NOT_ENOUGH_PARTS", BUNDLE));
-                }
-                startQName = reader.getName();
-                if (!startQName.equals(JBIConstants.JBI_WRAPPER_PART)) {
-                    throw new Fault(new org.apache.cxf.common.i18n.Message(
-                            "NO_JBI_PART_ELEMENT", BUNDLE));
+            ServiceInfo si = bop.getBinding().getService();
+            MessageInfo msgInfo = setMessage(message, bop, requestor, si);
+
+            message.put(MessageInfo.class, msgInfo);
+            if (!bop.isUnwrappedCapable()) {
+                for (MessagePartInfo part : msgInfo.getMessageParts()) {
+                    readJBIWrapper(reader);
+                    if (part.isElement()) {
+                        reader.next();
+                        if (!StaxUtils.toNextElement(reader)) {
+                            throw new Fault(
+                                    new org.apache.cxf.common.i18n.Message(
+                                            "EXPECTED_ELEMENT_IN_PART", BUNDLE));
+                        }
+                    }
+                    parameters.put(part, dr.read(part, reader));
+                    // skip end element
+                    if (part.isElement()) {
+                        reader.next();
+                    }
+                }
+                int ev = reader.getEventType();
+                while (ev != XMLStreamConstants.END_ELEMENT
+                        && ev != XMLStreamConstants.START_ELEMENT
+                        && ev != XMLStreamConstants.END_DOCUMENT) {
+                    ev = reader.next();
                 }
-                if (part.isElement()) {
+            } else if (bop.isUnwrappedCapable()
+                    && msgInfo.getMessageParts().get(0).getTypeClass() != null) {
+                readJBIWrapper(reader);
+                if (msgInfo.getMessageParts().get(0).isElement()) {
                     reader.next();
                     if (!StaxUtils.toNextElement(reader)) {
-                        throw new Fault(new org.apache.cxf.common.i18n.Message(
-                                "EXPECTED_ELEMENT_IN_PART", BUNDLE));
+                        throw new Fault(
+                                new org.apache.cxf.common.i18n.Message(
+                                        "EXPECTED_ELEMENT_IN_PART", BUNDLE));
                     }
                 }
-                parameters.add(dr.read(part, reader));
-                // skip end element
-                if (part.isElement()) {
-                    reader.next();
+                Object wrappedObject = dr.read(
+                        msgInfo.getMessageParts().get(0), xsr);
+                parameters.put(msgInfo.getMessageParts().get(0), wrappedObject);
+
+            } else {
+                if (bop.isUnwrappedCapable()) {
+                    bop = bop.getUnwrappedOperation();
+                }
+
+                msgInfo = setMessage(message, bop, requestor, si);
+                message.put(MessageInfo.class, msgInfo);
+                for (MessagePartInfo part : msgInfo.getMessageParts()) {
+                    readJBIWrapper(reader);
+                    if (part.isElement()) {
+                        reader.next();
+                        reader.next();
+                        if (!StaxUtils.toNextElement(reader)) {
+                            throw new Fault(
+                                    new org.apache.cxf.common.i18n.Message(
+                                            "EXPECTED_ELEMENT_IN_PART", BUNDLE));
+                        }
+                    }
+                    parameters.put(part, dr.read(part, reader));
+                    // skip end element
+                    if (part.isElement()) {
+                        reader.next();
+                    }
+                }
+                int ev = reader.getEventType();
+                while (ev != XMLStreamConstants.END_ELEMENT
+                        && ev != XMLStreamConstants.START_ELEMENT
+                        && ev != XMLStreamConstants.END_DOCUMENT) {
+                    ev = reader.next();
                 }
-            }
-            int ev = reader.getEventType();
-            while (ev != XMLStreamConstants.END_ELEMENT 
-                    && ev != XMLStreamConstants.START_ELEMENT
-                    && ev != XMLStreamConstants.END_DOCUMENT) {
-                ev = reader.next();
             }
             message.setContent(List.class, parameters);
         } catch (XMLStreamException e) {
-            throw new Fault(new org.apache.cxf.common.i18n.Message("STAX_READ_EXC", BUNDLE),
e);
+            throw new Fault(new org.apache.cxf.common.i18n.Message(
+                    "STAX_READ_EXC", BUNDLE), e);
         }
+        
     }
 
+    private void readJBIWrapper(DepthXMLStreamReader reader) throws XMLStreamException {
+        QName startQName;
+        if (!StaxUtils.skipToStartOfElement(reader)) {
+            throw new Fault(new org.apache.cxf.common.i18n.Message(
+                    "NOT_ENOUGH_PARTS", BUNDLE));
+        }
+        startQName = reader.getName();
+        if (!startQName.equals(JBIConstants.JBI_WRAPPER_PART)) {
+            throw new Fault(new org.apache.cxf.common.i18n.Message(
+                    "NO_JBI_PART_ELEMENT", BUNDLE));
+        }
+    }
+
+    
+    
+    private MessageInfo setMessage(Message message,
+            BindingOperationInfo operation, boolean requestor, ServiceInfo si) {
+        MessageInfo msgInfo = getMessageInfo(message, operation, requestor);
+        message.put(MessageInfo.class, msgInfo);
+
+        message.getExchange().put(BindingOperationInfo.class, operation);
+        message.getExchange().put(OperationInfo.class,
+                operation.getOperationInfo());
+        message.getExchange()
+                .setOneWay(operation.getOperationInfo().isOneWay());
+
+        // Set standard MessageContext properties required by JAX_WS, but not
+        // specific to JAX_WS.
+        message.put(Message.WSDL_OPERATION, operation.getName());
+
+        QName serviceQName = si.getName();
+        message.put(Message.WSDL_SERVICE, serviceQName);
+
+        QName interfaceQName = si.getInterface().getName();
+        message.put(Message.WSDL_INTERFACE, interfaceQName);
+
+        EndpointInfo endpointInfo = message.getExchange().get(Endpoint.class)
+                .getEndpointInfo();
+        QName portQName = endpointInfo.getName();
+        message.put(Message.WSDL_PORT, portQName);
+
+        String address = endpointInfo.getAddress();
+        URI wsdlDescription = null;
+        try {
+            wsdlDescription = new URI(address + "?wsdl");
+        } catch (URISyntaxException e) {
+            // do nothing
+        }
+        message.put(Message.WSDL_DESCRIPTION, wsdlDescription);
+
+        return msgInfo;
+    }
 }

Modified: cxf/branches/2.0.x-fixes/rt/bindings/jbi/src/main/java/org/apache/cxf/binding/jbi/interceptor/JBIWrapperOutInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.0.x-fixes/rt/bindings/jbi/src/main/java/org/apache/cxf/binding/jbi/interceptor/JBIWrapperOutInterceptor.java?rev=713664&r1=713663&r2=713664&view=diff
==============================================================================
--- cxf/branches/2.0.x-fixes/rt/bindings/jbi/src/main/java/org/apache/cxf/binding/jbi/interceptor/JBIWrapperOutInterceptor.java
(original)
+++ cxf/branches/2.0.x-fixes/rt/bindings/jbi/src/main/java/org/apache/cxf/binding/jbi/interceptor/JBIWrapperOutInterceptor.java
Wed Nov 12 22:54:34 2008
@@ -23,6 +23,7 @@
 import java.util.logging.Logger;
 
 import javax.xml.XMLConstants;
+import javax.xml.namespace.QName;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamWriter;
 
@@ -36,6 +37,7 @@
 import org.apache.cxf.service.Service;
 import org.apache.cxf.service.model.BindingMessageInfo;
 import org.apache.cxf.service.model.BindingOperationInfo;
+import org.apache.cxf.service.model.MessageInfo;
 import org.apache.cxf.service.model.MessagePartInfo;
 
 public class JBIWrapperOutInterceptor extends AbstractOutDatabindingInterceptor {
@@ -62,6 +64,7 @@
             xmlWriter.writeNamespace("jbi", JBIConstants.NS_JBI_WRAPPER);
             setTypeAttr(xmlWriter, message);
             List<MessagePartInfo> parts = null;
+            
             if (!isRequestor(message)) {
                 parts = bop.getOutput().getMessageParts();
             } else {
@@ -79,7 +82,9 @@
                     if (part.getTypeClass() == String.class) {
                         xmlWriter.writeStartElement(JBIConstants.NS_JBI_WRAPPER, 
                                                     JBIConstants.JBI_WRAPPER_PART.getLocalPart());
+                        writeWrapper(message, bop, xmlWriter);
                         xmlWriter.writeCharacters(obj.toString());
+                        writeWrapperEnding(bop, xmlWriter);
                         xmlWriter.writeEndElement();
                     } else {
                         part = new MessagePartInfo(part.getName(), part.getMessageInfo());
@@ -90,16 +95,53 @@
                 } else {
                     xmlWriter.writeStartElement(JBIConstants.NS_JBI_WRAPPER, 
                                                 JBIConstants.JBI_WRAPPER_PART.getLocalPart());
-                    dataWriter.write(obj, part, xmlWriter);                    
+                    writeWrapper(message, bop, xmlWriter);
+                    dataWriter.write(obj, part, xmlWriter);
+                    writeWrapperEnding(bop, xmlWriter);
                     xmlWriter.writeEndElement();
                 }
             }
             xmlWriter.writeEndElement();
+            
         
         } catch (XMLStreamException e) {
             throw new Fault(new org.apache.cxf.common.i18n.Message("STAX_WRITE_EXC", BUNDLE),
e);
         }
     }
+
+    private void writeWrapperEnding(BindingOperationInfo bop, XMLStreamWriter xmlWriter)

+        throws XMLStreamException {
+        if (bop.isUnwrapped()) {
+            xmlWriter.writeEndElement();
+        }
+    }
+
+    private void writeWrapper(Message message, BindingOperationInfo bop, XMLStreamWriter
xmlWriter) {
+        if (bop.isUnwrapped()) {
+            MessageInfo messageInfo;
+            if (isRequestor(message)) {
+                messageInfo = bop.getWrappedOperation().getOperationInfo().getInput();
+            } else {
+                messageInfo = bop.getWrappedOperation().getOperationInfo().getOutput();
+            }
+
+            MessagePartInfo outPart = messageInfo.getMessageParts().get(0);
+            QName name = outPart.getConcreteName();
+
+            try {
+                
+                int x = 1;
+                while (xmlWriter.getNamespaceContext().getNamespaceURI("ns" + x) != null)
{
+                    x++;
+                }
+                xmlWriter.setPrefix("ns" + x, name.getNamespaceURI());
+                xmlWriter.writeStartElement("ns" + x, name.getLocalPart(), name.getNamespaceURI());
+                xmlWriter.writeNamespace("ns" + x, name.getNamespaceURI());
+            } catch (XMLStreamException e) {
+                throw new Fault(new org.apache.cxf.common.i18n.Message("STAX_WRITE_EXC",
BUNDLE), e);
+            }
+        }
+    }
     
     private void setTypeAttr(XMLStreamWriter xmlWriter, Message message) throws XMLStreamException
{
         BindingOperationInfo wsdlOperation = getOperation(message);



Mime
View raw message