You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ode.apache.org by mi...@apache.org on 2008/07/23 01:55:48 UTC

svn commit: r678951 - in /ode/branches/APACHE_ODE_1.X: axis2-war/src/test/resources/TestHttpBindingExt_GET/ axis2/src/main/java/org/apache/ode/axis2/httpbinding/ axis2/src/main/java/org/apache/ode/axis2/util/

Author: midon
Date: Tue Jul 22 16:55:47 2008
New Revision: 678951

URL: http://svn.apache.org/viewvc?rev=678951&view=rev
Log:
ODE-344: support simple types and elements of simple types for headers and query string

Modified:
    ode/branches/APACHE_ODE_1.X/axis2-war/src/test/resources/TestHttpBindingExt_GET/http-binding-ext-GET.bpel
    ode/branches/APACHE_ODE_1.X/axis2/src/main/java/org/apache/ode/axis2/httpbinding/HttpMethodConverter.java
    ode/branches/APACHE_ODE_1.X/axis2/src/main/java/org/apache/ode/axis2/util/URLEncodedTransformer.java
    ode/branches/APACHE_ODE_1.X/axis2/src/main/java/org/apache/ode/axis2/util/UrlReplacementTransformer.java

Modified: ode/branches/APACHE_ODE_1.X/axis2-war/src/test/resources/TestHttpBindingExt_GET/http-binding-ext-GET.bpel
URL: http://svn.apache.org/viewvc/ode/branches/APACHE_ODE_1.X/axis2-war/src/test/resources/TestHttpBindingExt_GET/http-binding-ext-GET.bpel?rev=678951&r1=678950&r2=678951&view=diff
==============================================================================
--- ode/branches/APACHE_ODE_1.X/axis2-war/src/test/resources/TestHttpBindingExt_GET/http-binding-ext-GET.bpel (original)
+++ ode/branches/APACHE_ODE_1.X/axis2-war/src/test/resources/TestHttpBindingExt_GET/http-binding-ext-GET.bpel Tue Jul 22 16:55:47 2008
@@ -46,6 +46,7 @@
         <variable name="articleMsg" messageType="dummy:ArticleMessage"/>
         <variable name="generatedTimestamp" type="xsd:string"/>
         <variable name="articleId" type="xsd:string"/>
+        <variable name="tmpVar" type="xsd:string"/>
         <variable name="statusLine" type="xsd:anyType"/>
     </variables>
 
@@ -104,18 +105,25 @@
             </else>
         </if>
 
-<!--        <if>
-            <condition>fn:contains($articleMsg.from,'alexis@test.com')</condition>
+        <assign>
+            <copy>
+                <from variable="articleMsg" header="From"/>
+                <to variable="tmpVar"/>
+            </copy>
+        </assign>
+        <if>
+            <condition>compare($tmpVar, 'alexis@test.com') = 0</condition>
             <empty/>
             <else>
                 <assign>
                     <copy>
-                        <from>'Wrong From Header received. Check if the request header was properly set.'</from>
+                        <from>concat('Wrong From Header received. Check if the request header was properly set. Received value is: ', $tmpVar)
+                        </from>
                         <to>$outputVar.TestPart</to>
                     </copy>
                 </assign>
             </else>
-        </if>-->
+        </if>
         <if>
             <condition>$articleMsg.article/dummy:id = $articleId</condition>
             <empty/>

Modified: ode/branches/APACHE_ODE_1.X/axis2/src/main/java/org/apache/ode/axis2/httpbinding/HttpMethodConverter.java
URL: http://svn.apache.org/viewvc/ode/branches/APACHE_ODE_1.X/axis2/src/main/java/org/apache/ode/axis2/httpbinding/HttpMethodConverter.java?rev=678951&r1=678950&r2=678951&view=diff
==============================================================================
--- ode/branches/APACHE_ODE_1.X/axis2/src/main/java/org/apache/ode/axis2/httpbinding/HttpMethodConverter.java (original)
+++ ode/branches/APACHE_ODE_1.X/axis2/src/main/java/org/apache/ode/axis2/httpbinding/HttpMethodConverter.java Tue Jul 22 16:55:47 2008
@@ -262,22 +262,34 @@
             String partName = binding.getAttribute("part");
             String value = binding.getAttribute("value");
 
+            /* Header binding may use a part or a static value */
             String headerValue;
             if (StringUtils.isNotEmpty(partName)) {
                 // 'part' attribute is used
                 // get the part to be put in the header
                 Part part = inputMessage.getPart(partName);
                 Element partWrapper = partValues.get(part.getName());
-                // if the part has an element name, we must take the first element
-                if (part.getElementName() != null) {
-                    headerValue = DOMUtils.domToString(DOMUtils.getFirstChildElement(partWrapper));
+                if (DOMUtils.isEmptyElement(partWrapper)) {
+                    headerValue = "";
                 } else {
-                    if (DOMUtils.getFirstChildElement(partWrapper) != 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);
+                    /*
+                    The expected part value could be a simple type
+                    or an element of a simple type.
+                    So if a element is there, take its text content
+                    else take the text content of the part element itself
+                    */
+                    Element childElement = DOMUtils.getFirstChildElement(partWrapper);
+                    if (childElement != null) {
+                        if (DOMUtils.getFirstChildElement(childElement) != null) {
+                            String errMsg = "Complex types are not supported. Header Parts must be simple types or elements of a simple type.";
+                            if (log.isErrorEnabled()) log.error(errMsg);
+                            throw new RuntimeException(errMsg);
+                        } else {
+                            headerValue = DOMUtils.getTextContent(childElement);
+                        }
+                    } else {
+                        headerValue = DOMUtils.getTextContent(partWrapper);
                     }
-                    headerValue = DOMUtils.getTextContent(partWrapper);
                 }
             } else if (StringUtils.isNotEmpty(value)) {
                 // 'value' attribute is used, this header is a static value

Modified: ode/branches/APACHE_ODE_1.X/axis2/src/main/java/org/apache/ode/axis2/util/URLEncodedTransformer.java
URL: http://svn.apache.org/viewvc/ode/branches/APACHE_ODE_1.X/axis2/src/main/java/org/apache/ode/axis2/util/URLEncodedTransformer.java?rev=678951&r1=678950&r2=678951&view=diff
==============================================================================
--- ode/branches/APACHE_ODE_1.X/axis2/src/main/java/org/apache/ode/axis2/util/URLEncodedTransformer.java (original)
+++ ode/branches/APACHE_ODE_1.X/axis2/src/main/java/org/apache/ode/axis2/util/URLEncodedTransformer.java Tue Jul 22 16:55:47 2008
@@ -50,11 +50,27 @@
         List<NameValuePair> l = new ArrayList<NameValuePair>(values.size());
         for (Map.Entry<String, Element> e : values.entrySet()) {
             String partName = e.getKey();
-            Element node = e.getValue();
-            String nodeContent = DOMUtils.isEmptyElement(node) ? "" : DOMUtils.getTextContent(node);
+            Element value = e.getValue();
+            String textValue;
+            if (DOMUtils.isEmptyElement(value)) {
+                textValue = "";
+            } else {
+                /*
+                The expected part value could be a simple type
+                or an element of a simple type.
+                So if a element is there, take its text content
+                else take the text content of the part element itself
+                */
+                Element childElement = DOMUtils.getFirstChildElement(value);
+                if (childElement != null) {
+                    textValue = DOMUtils.getTextContent(childElement);
+                } else {
+                    textValue = DOMUtils.getTextContent(value);
+                }
+            }
             // if it is not a simple type, skip it
-            if (nodeContent != null) {
-                l.add(new NameValuePair(e.getKey(), nodeContent));
+            if (textValue != null) {
+                l.add(new NameValuePair(e.getKey(), textValue));
             }
         }
         return EncodingUtil.formUrlEncode(l.toArray(new NameValuePair[0]), "UTF-8");

Modified: ode/branches/APACHE_ODE_1.X/axis2/src/main/java/org/apache/ode/axis2/util/UrlReplacementTransformer.java
URL: http://svn.apache.org/viewvc/ode/branches/APACHE_ODE_1.X/axis2/src/main/java/org/apache/ode/axis2/util/UrlReplacementTransformer.java?rev=678951&r1=678950&r2=678951&view=diff
==============================================================================
--- ode/branches/APACHE_ODE_1.X/axis2/src/main/java/org/apache/ode/axis2/util/UrlReplacementTransformer.java (original)
+++ ode/branches/APACHE_ODE_1.X/axis2/src/main/java/org/apache/ode/axis2/util/UrlReplacementTransformer.java Tue Jul 22 16:55:47 2008
@@ -56,7 +56,8 @@
      * @param baseUri - the base uri template containing part names enclosed within single curly braces
      * @param values  - a map<String, Element>, the key is a part name (without curly braces), the value the replacement value for the part name. If the value is not a simple type, it will be skipped.
      * @return the encoded uri
-     * @throws java.lang.IllegalArgumentException if a replacement value is null in the map or if a part pattern is found more than once
+     * @throws java.lang.IllegalArgumentException
+     *          if a replacement value is null in the map or if a part pattern is found more than once
      */
     public String transform(String baseUri, Map<String, Element> values) {
         // the list containing the final split result
@@ -72,11 +73,26 @@
             String replacementValue;
             {
                 Element value = e.getValue();
-                replacementValue = DOMUtils.isEmptyElement(value) ? "" : DOMUtils.getTextContent(value);
+                if (DOMUtils.isEmptyElement(value)) {
+                    replacementValue = "";
+                } else {
+                    /*
+                    The expected part value could be a simple type
+                    or an element of a simple type.
+                    So if a element is there, take its text content
+                    else take the text content of the part element itself
+                    */
+                    Element childElement = DOMUtils.getFirstChildElement(value);
+                    if (childElement != null) {
+                        replacementValue = DOMUtils.getTextContent(childElement);
+                    } else {
+                        replacementValue = DOMUtils.getTextContent(value);
+                    }
+                }
             }
 
             // if it is not a simple type, skip it
-            if (replacementValue!=null) {
+            if (replacementValue != null) {
                 try {
                     replacementValue = URIUtil.encodeWithinQuery(replacementValue);
                 } catch (URIException urie) {
@@ -86,7 +102,7 @@
 
                 // first, search for parentheses
                 String partPattern = "\\(" + partName + "\\)";
-                if(!replace(result, partPattern, replacementValue)){
+                if (!replace(result, partPattern, replacementValue)) {
                     // if parentheses not found, try braces
                     partPattern = "\\{" + partName + "\\}";
                     replace(result, partPattern, replacementValue);