You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@synapse.apache.org by up...@apache.org on 2008/02/28 09:07:49 UTC
svn commit: r631884 - in /synapse/trunk/java/modules/core/src:
main/java/org/apache/synapse/core/axis2/ test/java/org/apache/synapse/core/
test/java/org/apache/synapse/core/axis2/
Author: upul
Date: Thu Feb 28 00:07:48 2008
New Revision: 631884
URL: http://svn.apache.org/viewvc?rev=631884&view=rev
Log:
added ability to specify body relative xpath evaluation for message context getStringValue()
Added:
synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/core/
synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/core/axis2/
synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/core/axis2/Axis2MessageContextTest.java
Modified:
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2MessageContext.java
Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2MessageContext.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2MessageContext.java?rev=631884&r1=631883&r2=631884&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2MessageContext.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2MessageContext.java Thu Feb 28 00:07:48 2008
@@ -431,6 +431,20 @@
* @return a String representation of the result of evaluation
*/
public static String getStringValue(AXIOMXPath xpath, MessageContext synCtx) {
+ // default xpath evaluated against the full envelope
+ return getStringValue(xpath, synCtx, false);
+ }
+
+ /**
+ * Evaluates the given XPath expression against the SOAPEnvelope of the
+ * current message and returns a String representation of the result
+ * @param xpath the expression to evaluate
+ * @param synCtx the source message which holds the SOAP envelope
+ * @param bodyRelative if true evaluate xpath against body content, if false evaluate xpath
+ * against full envelope
+ * @return a String representation of the result of evaluation
+ */
+ public static String getStringValue(AXIOMXPath xpath, MessageContext synCtx, boolean bodyRelative) {
synchronized(xpath) {
@@ -455,7 +469,14 @@
"extension function for XPath : " + xpath, je);
}
try {
- Object result = xpath.evaluate(synCtx.getEnvelope());
+ Object result;
+ if(bodyRelative) {
+ result = xpath.evaluate(synCtx.getEnvelope().getBody());
+
+ } else {
+ result = xpath.evaluate(synCtx.getEnvelope());
+
+ }
if (result == null) {
return null;
}
Added: synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/core/axis2/Axis2MessageContextTest.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/core/axis2/Axis2MessageContextTest.java?rev=631884&view=auto
==============================================================================
--- synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/core/axis2/Axis2MessageContextTest.java (added)
+++ synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/core/axis2/Axis2MessageContextTest.java Thu Feb 28 00:07:48 2008
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.synapse.core.axis2;
+
+import junit.framework.TestCase;
+import org.apache.synapse.MessageContext;
+import org.apache.synapse.core.axis2.Axis2MessageContext;
+import org.apache.synapse.mediators.TestUtils;
+import org.apache.axiom.om.xpath.AXIOMXPath;
+
+public class Axis2MessageContextTest extends TestCase {
+ String nsSoapEnv = "http://schemas.xmlsoap.org/soap/envelope/";
+ String nsNamespace1 = "namespace1";
+ private String sampleBody = "<ns1:a xmlns:ns1='namespace1'>" +
+ "<ns1:b>first</ns1:b>" +
+ "<ns1:c>second</ns1:c>" +
+ "</ns1:a>";
+
+
+ public void testMessageContextGetStringValueBody() throws Exception {
+ AXIOMXPath axiomXpath = new AXIOMXPath("ns1:a/ns1:c");
+ axiomXpath.addNamespace("ns1", nsNamespace1);
+ MessageContext synCtx = TestUtils.getTestContext(sampleBody);
+
+ String result = Axis2MessageContext.getStringValue(axiomXpath, synCtx, true);
+ assertEquals("second", result);
+ }
+
+ public void testMessageContextGetStringValueEnvelope() throws Exception {
+ AXIOMXPath axiomXpath = new AXIOMXPath("/s11:Envelope/s11:Body/ns1:a/ns1:c");
+ axiomXpath.addNamespace("s11", nsSoapEnv);
+ axiomXpath.addNamespace("ns1", nsNamespace1);
+
+ MessageContext synCtx = TestUtils.getTestContext(sampleBody);
+
+ String result = Axis2MessageContext.getStringValue(axiomXpath, synCtx, false);
+ assertEquals("second", result);
+ }
+
+}