Author: midon
Date: Tue Jul  8 14:30:22 2008
New Revision: 674966

URL: http://svn.apache.org/viewvc?rev=674966&view=rev
Log:
should Parts be element or types? that is the question. Answer in 2 points:
. a part mapped to an HTTP header could be an element or a simple type
. a part mapped to the request body MUST be an element. An exception will be 
thrown if not.

Modified:
    
ode/trunk/axis2/src/main/java/org/apache/ode/axis2/httpbinding/HttpMethodConverter.java

Modified: 
ode/trunk/axis2/src/main/java/org/apache/ode/axis2/httpbinding/HttpMethodConverter.java
URL: 
http://svn.apache.org/viewvc/ode/trunk/axis2/src/main/java/org/apache/ode/axis2/httpbinding/HttpMethodConverter.java?rev=674966&r1=674965&r2=674966&view=diff
==============================================================================
--- 
ode/trunk/axis2/src/main/java/org/apache/ode/axis2/httpbinding/HttpMethodConverter.java
 (original)
+++ 
ode/trunk/axis2/src/main/java/org/apache/ode/axis2/httpbinding/HttpMethodConverter.java
 Tue Jul  8 14:30:22 2008
@@ -181,10 +181,13 @@
                 Element partValue = partValues.get(part.getName());
                 // if the part has an element name, we must take the first 
element
                 if (part.getElementName() != null) {
-                    partValue = DOMUtils.getFirstChildElement(partValue);
+                    String xmlString = 
DOMUtils.domToString(DOMUtils.getFirstChildElement(partValue));
+                    requestEntity = new 
ByteArrayRequestEntity(xmlString.getBytes(), contentType);
+                } else {
+                    String errMsg = "Types are not supported with 'text/xml'. 
Parts must use elements.";
+                    if (log.isErrorEnabled()) log.error(errMsg);
+                    throw new RuntimeException(errMsg);
                 }
-                String xmlString = DOMUtils.domToString(partValue);
-                requestEntity = new 
ByteArrayRequestEntity(xmlString.getBytes(), contentType);
             } else {
                 // should not happen because of HttpBindingValidator, but 
never say never
                 throw new IllegalArgumentException("Unsupported 
content-type!");
@@ -212,7 +215,7 @@
 
     /**
      * Go through the list of [EMAIL PROTECTED] [EMAIL PROTECTED] :header} 
elements included in the input binding. For each of them, set the HTTP Request 
Header with the static value defined by the attribute [EMAIL PROTECTED] [EMAIL 
PROTECTED] :value},
-     *  or the part value mentionned in the attribute [EMAIL PROTECTED] [EMAIL 
PROTECTED] :part}.
+     * or the part value mentionned in the attribute [EMAIL PROTECTED] [EMAIL 
PROTECTED] :part}.
      */
     public void setHttpRequestHeaders(HttpMethod method, Map<String, Element> 
partValues, Message inputMessage, BindingInput bindingInput) {
         Collection<UnknownExtensibilityElement> headerBindings = 
WsdlUtils.getHttpHeaders(bindingInput.getExtensibilityElements());
@@ -224,19 +227,25 @@
 
             String headerValue;
             if (StringUtils.isNotEmpty(partName)) {
-                // get the part to be put in the body
+                // get the part to be put in the header
                 Part part = inputMessage.getPart(partName);
                 Element partValue = partValues.get(part.getName());
                 // if the part has an element name, we must take the first 
element
-                if (part.getElementName() != null) partValue = 
DOMUtils.getFirstChildElement(partValue);
-                headerValue = DOMUtils.domToString(partValue);
+                if (part.getElementName() != null) {
+                    headerValue = 
DOMUtils.domToString(DOMUtils.getFirstChildElement(partValue));
+                } else {
+                    if (DOMUtils.getFirstChildElement(partValue) != null) {
+                        String errMsg = "Complex types are not supported. 
Header Parts must use elements or simple types.";
+                        if (log.isErrorEnabled()) log.error(errMsg);
+                        throw new RuntimeException(errMsg);
+                    }
+                    headerValue = DOMUtils.getTextContent(partValue);
+                }
             } else if (StringUtils.isNotEmpty(value)) {
                 headerValue = value;
             } else {
                 String errMsg = "Invalid binding: missing attribute! Expecting 
" + new QName(Namespaces.ODE_HTTP_EXTENSION_NS, "part") + " or " + new 
QName(Namespaces.ODE_HTTP_EXTENSION_NS, "value");
-                if (log.isErrorEnabled()) {
-                    log.error(errMsg);
-                }
+                if (log.isErrorEnabled()) log.error(errMsg);
                 throw new RuntimeException(errMsg);
             }
             method.setRequestHeader(headerName, 
HttpClientHelper.replaceCRLFwithLWS(headerValue));
@@ -338,7 +347,7 @@
 
             Part part = messageDef.getPart(partName);
             if (StringUtils.isNotEmpty(partName)) {
-                odeMessage.setPart(partName, createPartElement(part, 
method.getRequestHeader(headerName).getValue()));
+                odeMessage.setPart(partName, createPartElement(part, 
method.getResponseHeader(headerName).getValue()));
             } else {
                 String errMsg = "Invalid binding: missing required attribute! 
Part name: " + new QName(Namespaces.ODE_HTTP_EXTENSION_NS, "part");
                 if (log.isErrorEnabled()) log.error(errMsg);


Reply via email to