cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t..@apache.org
Subject svn commit: r470726 - in /incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap: HeaderUtil.java SoapBindingFactory.java interceptor/SoapInPostInterceptor.java interceptor/SoapOutInterceptor.java model/SoapHeaderInfo.java
Date Fri, 03 Nov 2006 08:53:33 GMT
Author: tli
Date: Fri Nov  3 00:53:32 2006
New Revision: 470726

URL: http://svn.apache.org/viewvc?view=rev&rev=470726
Log:
CXF-109 refactor the soap header processing

Modified:
    incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/HeaderUtil.java
    incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/SoapBindingFactory.java
    incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/SoapInPostInterceptor.java
    incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/SoapOutInterceptor.java
    incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/model/SoapHeaderInfo.java

Modified: incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/HeaderUtil.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/HeaderUtil.java?view=diff&rev=470726&r1=470725&r2=470726
==============================================================================
--- incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/HeaderUtil.java
(original)
+++ incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/HeaderUtil.java
Fri Nov  3 00:53:32 2006
@@ -26,7 +26,6 @@
 import javax.wsdl.extensions.ExtensibilityElement;
 import javax.xml.namespace.QName;
 
-import org.apache.cxf.binding.soap.model.SoapHeaderInfo;
 import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.service.model.BindingMessageInfo;
 import org.apache.cxf.service.model.BindingOperationInfo;
@@ -40,15 +39,6 @@
     private HeaderUtil() {
     }
 
-    public static boolean isHeaderParam(List<SoapHeaderInfo> headers, MessagePartInfo
part) {
-        for (SoapHeaderInfo shi : headers) {
-            if (shi.getPart() == part) {
-                return true;
-            }
-        }
-        return false;
-    }
-    
     private static Set<QName> getHeaderParts(BindingMessageInfo bmi) {
         Object obj = bmi.getProperty(HEADERS_PROPERTY);
         if (obj == null) {

Modified: incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/SoapBindingFactory.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/SoapBindingFactory.java?view=diff&rev=470726&r1=470725&r2=470726
==============================================================================
--- incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/SoapBindingFactory.java
(original)
+++ incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/SoapBindingFactory.java
Fri Nov  3 00:53:32 2006
@@ -251,9 +251,16 @@
                 headerInfo.setUse(header.getUse());
                 MessagePartInfo part = msg.getMessagePart(new QName(msg.getName().getNamespaceURI(),
header
                                 .getPart()));
-                headerInfo.setPart(part);
-                messageParts.remove(part);
-                bmsg.addExtensor(headerInfo);
+                if (part != null) {
+                    for (int i = 0; i < msg.getMessageParts().size(); i++) {
+                        if (msg.getMessagePartByIndex(i) == part) {
+                            headerInfo.setSequence(i);
+                        }
+                    }
+                    headerInfo.setPart(part);
+                    messageParts.remove(part);
+                    bmsg.addExtensor(headerInfo);
+                }
             }
         }
 

Modified: incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/SoapInPostInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/SoapInPostInterceptor.java?view=diff&rev=470726&r1=470725&r2=470726
==============================================================================
--- incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/SoapInPostInterceptor.java
(original)
+++ incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/SoapInPostInterceptor.java
Fri Nov  3 00:53:32 2006
@@ -29,7 +29,6 @@
 import org.w3c.dom.Element;
 import org.w3c.dom.NodeList;
 
-import org.apache.cxf.binding.soap.HeaderUtil;
 import org.apache.cxf.binding.soap.model.SoapHeaderInfo;
 import org.apache.cxf.endpoint.Endpoint;
 import org.apache.cxf.helpers.CastUtils;
@@ -107,36 +106,31 @@
     
     private List<Object> abstractParamsFromHeader(Element headerElement, Endpoint ep,
Message message) {
         List<Object> paramInHeader = new ArrayList<Object>();
-        List<MessagePartInfo> parts = null;
         List<Element> elemInHeader = new ArrayList<Element>();
         for (BindingOperationInfo bop : ep.getEndpointInfo().getBinding().getOperations())
{
-            BindingMessageInfo bmi = null;
-            if (isRequestor(message)) {
-                parts = bop.getOutput().getMessageInfo().getMessageParts();
-                bmi = bop.getOutput();
-            } else {
-                parts = bop.getInput().getMessageInfo().getMessageParts();
-                bmi = bop.getInput();
+            BindingMessageInfo bmi = isRequestor(message) ? bop.getOutput() : bop.getInput();
+            if (bmi == null) {
+                return paramInHeader;
             }
             List<SoapHeaderInfo> headers = bmi.getExtensors(SoapHeaderInfo.class);
-            for (MessagePartInfo mpi : parts) {
-                if (HeaderUtil.isHeaderParam(headers, mpi)) {
-                    NodeList nodeList = headerElement.getChildNodes();
-                    if (nodeList != null) {
-                        for (int i = 0; i < nodeList.getLength(); i++) {
-                            if (nodeList.item(i).getNamespaceURI().equals(
-                                    mpi.getElementQName().getNamespaceURI())
-                                    && nodeList.item(i).getLocalName().equals(
-                                            mpi.getElementQName().getLocalPart())) {
-                                Element param = (Element) nodeList.item(i);
-                                if (!elemInHeader.contains(param)) {
-                                    elemInHeader.add(param);
-                                }
+            if (headers == null) {
+                return paramInHeader;
+            }
+            for (SoapHeaderInfo header : headers) {
+                MessagePartInfo mpi = header.getPart();
+                NodeList nodeList = headerElement.getChildNodes();
+                if (nodeList != null) {
+                    for (int i = 0; i < nodeList.getLength(); i++) {
+                        if (nodeList.item(i).getNamespaceURI().equals(
+                                mpi.getElementQName().getNamespaceURI())
+                                && nodeList.item(i).getLocalName().equals(
+                                        mpi.getElementQName().getLocalPart())) {
+                            Element param = (Element) nodeList.item(i);
+                            if (!elemInHeader.contains(param)) {
+                                elemInHeader.add(param);
                             }
                         }
-
                     }
-
                 }
             }
         }

Modified: incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/SoapOutInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/SoapOutInterceptor.java?view=diff&rev=470726&r1=470725&r2=470726
==============================================================================
--- incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/SoapOutInterceptor.java
(original)
+++ incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/SoapOutInterceptor.java
Fri Nov  3 00:53:32 2006
@@ -29,7 +29,6 @@
 
 import org.w3c.dom.Element;
 
-import org.apache.cxf.binding.soap.HeaderUtil;
 import org.apache.cxf.binding.soap.SoapFault;
 import org.apache.cxf.binding.soap.SoapMessage;
 import org.apache.cxf.binding.soap.SoapVersion;
@@ -109,76 +108,56 @@
     private void handleHeaderPart(boolean preexistingHeaders, SoapMessage message) {
         //add MessagePart to soapHeader if necessary
         Exchange exchange = message.getExchange();
-        BindingOperationInfo operation = (BindingOperationInfo)exchange.get(BindingOperationInfo.class
+        BindingOperationInfo bop = (BindingOperationInfo)exchange.get(BindingOperationInfo.class
                                                                             .getName());
-        if (operation == null) {
+        if (bop == null) {
             return;
         }
-        XMLStreamWriter xtw = message.getContent(XMLStreamWriter.class);
-        
+        XMLStreamWriter xtw = message.getContent(XMLStreamWriter.class);        
         boolean startedHeader = false;
-                 
-        int countParts = 0;
-        List<MessagePartInfo> parts = null;
-        BindingMessageInfo bmi = null;
-        if (!isRequestor(message)) {
-            if (operation.getOperationInfo().hasOutput()) {
-                parts = operation.getOutput().getMessageInfo().getMessageParts();
-                bmi = operation.getOutput();
-            } else {
-                parts = new ArrayList<MessagePartInfo>();
-            }
+        List<MessagePartInfo> parts = new ArrayList<MessagePartInfo>();
+        BindingMessageInfo bmi = isRequestor(message) ? bop.getInput() : bop.getOutput();
+        if (bmi == null) {
+            return;
         } else {
-            if (operation.getOperationInfo().hasInput()) {
-                parts = operation.getInput().getMessageInfo().getMessageParts();
-                bmi = operation.getInput();
-            } else {
-                parts = new ArrayList<MessagePartInfo>();
-            }
-        }
-        countParts = parts.size();
- 
-        if (countParts > 0) {
+            parts = bmi.getMessageParts();
+        } 
+        if (parts.size() > 0) {
             List<?> objs = message.getContent(List.class);
             if (objs == null) {
                 return;
-            }
-            
+            }            
             Object[] args = objs.toArray();
-            Object[] els = parts.toArray();
-            
             SoapVersion soapVersion = message.getVersion();
             List<SoapHeaderInfo> headers = bmi.getExtensors(SoapHeaderInfo.class);
-            for (int idx = 0; idx < countParts; idx++) {
-                Object arg = args[idx];
-                MessagePartInfo part = (MessagePartInfo)els[idx];
-                if (headers == null || !HeaderUtil.isHeaderParam(headers, part)) {
-                    continue;
-                } else {
-                    if (!(startedHeader || preexistingHeaders)) {
-                        try {
-                            xtw.writeStartElement(soapVersion.getPrefix(), 
-                                                  soapVersion.getHeader().getLocalPart(),
-                                                  soapVersion.getNamespace());
-                        } catch (XMLStreamException e) {
-                            throw new SoapFault(
-                                new org.apache.cxf.common.i18n.Message("XML_WRITE_EXC", BUNDLE),

-                                e, soapVersion.getSender());
-                        }
-                        
-                        startedHeader = true;
+            if (headers == null) {
+                return;
+            }
+            for (SoapHeaderInfo header : headers) {
+                Object arg = args[header.getSequence()];
+                if (!(startedHeader || preexistingHeaders)) {
+                    try {
+                        xtw.writeStartElement(soapVersion.getPrefix(), 
+                                              soapVersion.getHeader().getLocalPart(),
+                                              soapVersion.getNamespace());
+                    } catch (XMLStreamException e) {
+                        throw new SoapFault(
+                            new org.apache.cxf.common.i18n.Message("XML_WRITE_EXC", BUNDLE),

+                            e, soapVersion.getSender());
                     }
-                    DataWriter<XMLStreamWriter> dataWriter = getDataWriter(message);
-                    dataWriter.write(arg, part, xtw);
+                    startedHeader = true;
                 }
-                 
+                DataWriter<XMLStreamWriter> dataWriter = getDataWriter(message);
+                dataWriter.write(arg, header.getPart(), xtw);
             }
+
             for (MessagePartInfo part : parts) {
                 if (bmi.getExtensor(SoapBodyInfo.class) != null 
                         && !bmi.getExtensor(SoapBodyInfo.class).getParts().contains(part))
{
                     part.setProperty(MessagePartInfo.KEY_SKIPPED, Boolean.TRUE);
                 }
             }
+            
             if (startedHeader || preexistingHeaders) {
                 try {
                     xtw.writeEndElement();

Modified: incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/model/SoapHeaderInfo.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/model/SoapHeaderInfo.java?view=diff&rev=470726&r1=470725&r2=470726
==============================================================================
--- incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/model/SoapHeaderInfo.java
(original)
+++ incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/model/SoapHeaderInfo.java
Fri Nov  3 00:53:32 2006
@@ -22,8 +22,10 @@
 import org.apache.cxf.service.model.MessagePartInfo;
 
 public class SoapHeaderInfo {
+    
     private MessagePartInfo part;
     private String use;
+    private int sequence;
 
     public MessagePartInfo getPart() {
         return part;
@@ -39,5 +41,13 @@
 
     public void setUse(String use) {
         this.use = use;
+    }
+
+    public int getSequence() {
+        return sequence;
+    }
+
+    public void setSequence(int sequence) {
+        this.sequence = sequence;
     }
 }



Mime
View raw message