synapse-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ind...@apache.org
Subject svn commit: r605131 - in /webservices/synapse/trunk/java: modules/extensions/src/main/java/org/apache/synapse/mediators/xquery/ repository/conf/sample/ repository/conf/sample/resources/xquery/ src/site/resources/
Date Tue, 18 Dec 2007 08:20:21 GMT
Author: indika
Date: Tue Dec 18 00:20:16 2007
New Revision: 605131

URL: http://svn.apache.org/viewvc?rev=605131&view=rev
Log:
fix an issue when binding external baic variable whose value is expression 
update a sample to include above functionality and update document

Modified:
    webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/xquery/MediatorCustomVariable.java
    webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/xquery/XQueryMediator.java
    webservices/synapse/trunk/java/repository/conf/sample/resources/xquery/xquery_res.xq
    webservices/synapse/trunk/java/repository/conf/sample/synapse_sample_390.xml
    webservices/synapse/trunk/java/src/site/resources/Synapse_Samples.html

Modified: webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/xquery/MediatorCustomVariable.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/xquery/MediatorCustomVariable.java?rev=605131&r1=605130&r2=605131&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/xquery/MediatorCustomVariable.java
(original)
+++ webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/xquery/MediatorCustomVariable.java
Tue Dec 18 00:20:16 2007
@@ -22,6 +22,9 @@
 import org.apache.synapse.SynapseException;
 import org.apache.synapse.config.Entry;
 import org.apache.axiom.om.xpath.AXIOMXPath;
+import org.apache.axiom.om.OMNode;
+import org.apache.axiom.om.OMText;
+import org.apache.axiom.om.OMElement;
 import org.apache.axiom.soap.SOAP11Constants;
 import org.apache.axiom.soap.SOAP12Constants;
 import org.apache.commons.logging.Log;
@@ -31,6 +34,8 @@
 import javax.xml.namespace.QName;
 import java.util.List;
 
+import net.sf.saxon.javax.xml.xquery.XQItemType;
+
 /**
  * The value of the custom variable will be evaluated dynamically.
  * The value is computed by extracting the data from the XML document which will lookup 
through the
@@ -108,18 +113,32 @@
     }
 
     /**
-     * Return the OMNode to be used for the variable value
+     * Return the object to be used for the variable value
      *
      * @param source The source on which will be evaluated the XPath expression
      * @return Return the OMNode to be used for the variable value
      */
     private Object evaluate(Object source) {
         try {
-            Object o = expression.evaluate(source);
-            if (o instanceof List && !((List) o).isEmpty()) {
-                return ((List) o).get(0);  // Always fetches *only* the first
+            Object result = expression.evaluate(source);
+            if (result instanceof List && !((List) result).isEmpty()) {
+                result = ((List) result).get(0);  // Always fetches *only* the first
+            }
+            if (result instanceof OMNode) {
+                //if the type is not document-node(), then get the text value of the node
+                if (this.getType() != XQItemType.XQITEMKIND_DOCUMENT
+                    && this.getType() != XQItemType.XQITEMKIND_DOCUMENT_ELEMENT
+                    && this.getType() != XQItemType.XQITEMKIND_ELEMENT) {
+                    int nodeType = ((OMNode) result).getType();
+                    if (nodeType == OMNode.TEXT_NODE) {
+                        return ((OMText) result).getText();
+                    } else if (nodeType == OMNode.ELEMENT_NODE) {
+                        return ((OMElement) result).getText();
+                    }
+                }
+                return result;
             } else {
-                return o;
+                return result;
             }
         } catch (JaxenException e) {
             handleException("Error evaluating XPath " + expression + " on message");

Modified: webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/xquery/XQueryMediator.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/xquery/XQueryMediator.java?rev=605131&r1=605130&r2=605131&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/xquery/XQueryMediator.java
(original)
+++ webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/xquery/XQueryMediator.java
Tue Dec 18 00:20:16 2007
@@ -370,7 +370,12 @@
                     case(XQItemType.XQBASETYPE_INTEGER): {
                         int intValue = -1;
                         if (value instanceof String) {
-                            intValue = Integer.parseInt((String) value);
+                            try {
+                                intValue = Integer.parseInt((String) value);
+                            } catch (NumberFormatException e) {
+                                handleException("Incompatible value '" + value + "' " +
+                                    "for the Integer", e);
+                            }
                         } else if (value instanceof Integer) {
                             intValue = ((Integer) value).intValue();
                         } else {
@@ -384,7 +389,11 @@
                     case(XQItemType.XQBASETYPE_INT): {
                         int intValue = -1;
                         if (value instanceof String) {
-                            intValue = Integer.parseInt((String) value);
+                            try {
+                                intValue = Integer.parseInt((String) value);
+                            } catch (NumberFormatException e) {
+                                handleException("Incompatible value '" + value + "' for the
Int", e);
+                            }
                         } else if (value instanceof Integer) {
                             intValue = ((Integer) value).intValue();
                         } else {
@@ -398,7 +407,12 @@
                     case(XQItemType.XQBASETYPE_LONG): {
                         long longValue = -1;
                         if (value instanceof String) {
-                            longValue = Long.parseLong((String) value);
+                            try {
+                                longValue = Long.parseLong((String) value);
+                            } catch (NumberFormatException e) {
+                                handleException("Incompatible value '" + value + "' " +
+                                    "for the long ", e);
+                            }
                         } else if (value instanceof Long) {
                             longValue = ((Long) value).longValue();
                         } else {
@@ -412,7 +426,12 @@
                     case(XQItemType.XQBASETYPE_SHORT): {
                         short shortValue = -1;
                         if (value instanceof String) {
-                            shortValue = Short.parseShort((String) value);
+                            try {
+                                shortValue = Short.parseShort((String) value);
+                            } catch (NumberFormatException e) {
+                                handleException("Incompatible value '" + value + "' " +
+                                    "for the short ", e);
+                            }
                         } else if (value instanceof Short) {
                             shortValue = ((Short) value).shortValue();
                         } else {
@@ -426,7 +445,12 @@
                     case(XQItemType.XQBASETYPE_DOUBLE): {
                         double doubleValue = -1;
                         if (value instanceof String) {
-                            doubleValue = Double.parseDouble((String) value);
+                            try {
+                                doubleValue = Double.parseDouble((String) value);
+                            } catch (NumberFormatException e) {
+                                handleException("Incompatible value '" + value + "' " +
+                                    "for the double ", e);
+                            }
                         } else if (value instanceof Double) {
                             doubleValue = ((Double) value).doubleValue();
                         } else {
@@ -440,7 +464,12 @@
                     case(XQItemType.XQBASETYPE_FLOAT): {
                         float floatValue = -1;
                         if (value instanceof String) {
-                            floatValue = Float.parseFloat((String) value);
+                            try {
+                                floatValue = Float.parseFloat((String) value);
+                            } catch (NumberFormatException e) {
+                                handleException("Incompatible value '" + value + "' " +
+                                    "for the float ", e);
+                            }
                         } else if (value instanceof Float) {
                             floatValue = ((Float) value).floatValue();
                         } else {
@@ -454,7 +483,12 @@
                     case(XQItemType.XQBASETYPE_BYTE): {
                         byte byteValue = -1;
                         if (value instanceof String) {
-                            byteValue = Byte.parseByte((String) value);
+                            try {
+                                byteValue = Byte.parseByte((String) value);
+                            } catch (NumberFormatException e) {
+                                handleException("Incompatible value '" + value + "' " +
+                                    "for the byte ", e);
+                            }
                         } else if (value instanceof Byte) {
                             byteValue = ((Byte) value).byteValue();
                         } else {

Modified: webservices/synapse/trunk/java/repository/conf/sample/resources/xquery/xquery_res.xq
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/repository/conf/sample/resources/xquery/xquery_res.xq?rev=605131&r1=605130&r2=605131&view=diff
==============================================================================
--- webservices/synapse/trunk/java/repository/conf/sample/resources/xquery/xquery_res.xq (original)
+++ webservices/synapse/trunk/java/repository/conf/sample/resources/xquery/xquery_res.xq Tue
Dec 18 00:20:16 2007
@@ -1,8 +1,10 @@
 <x><![CDATA[
   declare namespace m0="http://services.samples/xsd";
   declare variable $payload as document-node() external;
+  declare variable $code as xs:string external;
+  declare variable $price as xs:double external;
   <m:CheckPriceResponse xmlns:m="http://services.samples/xsd">
-  	<m:Code>{$payload//m0:return/m0:symbol/child::text()}</m:Code>
-  	<m:Price>{$payload//m0:return/m0:last/child::text()}</m:Price>
-  </m:CheckPriceResponse>      
+  	<m:Code>{$code}</m:Code>
+  	<m:Price>{$price}</m:Price>
+  </m:CheckPriceResponse>
 ]]></x>

Modified: webservices/synapse/trunk/java/repository/conf/sample/synapse_sample_390.xml
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/repository/conf/sample/synapse_sample_390.xml?rev=605131&r1=605130&r2=605131&view=diff
==============================================================================
--- webservices/synapse/trunk/java/repository/conf/sample/synapse_sample_390.xml (original)
+++ webservices/synapse/trunk/java/repository/conf/sample/synapse_sample_390.xml Tue Dec 18
00:20:16 2007
@@ -17,7 +17,7 @@
   ~  under the License.
   -->
 
-<!-- Introduction to the XQuery mediator -->
+    <!-- Introduction to the XQuery mediator -->
 <definitions xmlns="http://ws.apache.org/ns/synapse">
 
     <!-- the SimpleURLRegistry allows access to a URL based registry (e.g. file:/// or
http://) -->
@@ -44,10 +44,16 @@
             </inSequence>
             <outSequence>
                 <out>
-                     <xquery key="xquery/xquery_res.xq">
+                    <xquery key="xquery/xquery_res.xq">
                         <variable name="payload" type="ELEMENT"/>
+                        <variable name="code" type="STRING"
+                                  expression="self::node()//m0:return/m0:symbol/child::text()"
+                                  xmlns:m0="http://services.samples/xsd"/>
+                        <variable name="price" type="DOUBLE"
+                                  expression="self::node()//m0:return/m0:last/child::text()"
+                                  xmlns:m0="http://services.samples/xsd"/>
                     </xquery>
-                     <send/>
+                    <send/>
                 </out>
             </outSequence>
         </target>

Modified: webservices/synapse/trunk/java/src/site/resources/Synapse_Samples.html
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/src/site/resources/Synapse_Samples.html?rev=605131&r1=605130&r2=605131&view=diff
==============================================================================
--- webservices/synapse/trunk/java/src/site/resources/Synapse_Samples.html (original)
+++ webservices/synapse/trunk/java/src/site/resources/Synapse_Samples.html Tue Dec 18 00:20:16
2007
@@ -4120,7 +4120,8 @@
 
 <h2><a name="Sample390">Sample 390: Introduction to the XQuery
 mediator</a></h2>
-<pre>&lt;definitions xmlns="http://ws.apache.org/ns/synapse"&gt;
+<pre>    &lt;!-- Introduction to the XQuery mediator --&gt;
+&lt;definitions xmlns="http://ws.apache.org/ns/synapse"&gt;
 
     &lt;!-- the SimpleURLRegistry allows access to a URL based registry (e.g. file:///
or http://) --&gt;
     &lt;registry provider="org.apache.synapse.registry.url.SimpleURLRegistry"&gt;
@@ -4146,16 +4147,23 @@
             &lt;/inSequence&gt;
             &lt;outSequence&gt;
                 &lt;out&gt;
-                     &lt;xquery key="xquery/xquery_res.xq"&gt;
+                    &lt;xquery key="xquery/xquery_res.xq"&gt;
                         &lt;variable name="payload" type="ELEMENT"/&gt;
+                        &lt;variable name="code" type="STRING"
+                                  expression="self::node()//m0:return/m0:symbol/child::text()"
+                                  xmlns:m0="http://services.samples/xsd"/&gt;
+                        &lt;variable name="price" type="DOUBLE"
+                                  expression="self::node()//m0:return/m0:last/child::text()"
+                                  xmlns:m0="http://services.samples/xsd"/&gt;
                     &lt;/xquery&gt;
-                     &lt;send/&gt;
+                    &lt;send/&gt;
                 &lt;/out&gt;
             &lt;/outSequence&gt;
         &lt;/target&gt;
-        &lt;publishWSDL uri="file:repository/conf/sample/resources/proxy/sample_proxy_1.wsdl"/&gt;&lt;/proxy&gt;&lt;/definitions&gt;
</pre>
+        &lt;publishWSDL uri="file:repository/conf/sample/resources/proxy/sample_proxy_1.wsdl"/&gt;
+    &lt;/proxy&gt;
 
-<p></p>
+&lt;/definitions&gt;                                  </pre>
 
 <p><b>Objective: Introduction transformation using XQuery mediator</b></p>
 



---------------------------------------------------------------------
To unsubscribe, e-mail: synapse-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: synapse-dev-help@ws.apache.org


Mime
View raw message