public static SynapseXPath getSynapseXPath(OMElement elem, String expression) throws JaxenException { if (expression == null) { handleException("XPath expression cannot be null"); } SynapseXPath xpath = new SynapseXPath(expression); OMElementUtils.addNameSpaces(xpath, elem, log); return xpath; }
public static SynapsePath getSynapsePath(OMElement elem, String expression) throws JaxenException { if (expression == null) { handleException("XPath expression cannot be null"); } SynapseXPath xpath = new SynapseXPath(expression); OMElementUtils.addNameSpaces(xpath, elem, log); return xpath; }
public static SynapseXPath getSynapseXPath(OMElement elem, String expression) throws JaxenException { if (expression == null) { handleException("XPath expression cannot be null"); } SynapseXPath xpath = new SynapseXPath(expression); OMElementUtils.addNameSpaces(xpath, elem, log); return xpath; }
public AggregateMediator() { try { aggregationExpression = new SynapseXPath("s11:Body/child::*[position()=1] | " + "s12:Body/child::*[position()=1]"); aggregationExpression.addNamespace("s11", SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI); aggregationExpression.addNamespace("s12", SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI); } catch (JaxenException e) { if (log.isDebugEnabled()) { handleException("Unable to set the default " + "aggregationExpression for the aggregation", e, null); } } }
public MediatorCustomVariable(QName name) { super(name); // create the default XPath try { this.expression = new SynapseXPath(SourceXPathSupport.DEFAULT_XPATH); this.expression.addNamespace("s11", SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI); this.expression.addNamespace("s12", SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI); } catch (JaxenException e) { handleException("Error creating source XPath expression", e); } }
public MediatorCustomVariable(QName name) { super(name); // create the default XPath try { this.expression = new SynapseXPath(SourceXPathSupport.DEFAULT_XPATH); this.expression.addNamespace("s11", SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI); this.expression.addNamespace("s12", SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI); } catch (JaxenException e) { handleException("Error creating source XPath expression", e); } }
public static SynapseXPath getSynapseXPath(OMElement elem, QName attribName) throws JaxenException { SynapseXPath xpath = null; OMAttribute xpathAttrib = elem.getAttribute(attribName); if (xpathAttrib != null && xpathAttrib.getAttributeValue() != null) { xpath = new SynapseXPath(xpathAttrib.getAttributeValue()); OMElementUtils.addNameSpaces(xpath, elem, log); } else { handleException("Couldn't find the XPath attribute with the QName : " + attribName.toString() + " in the element : " + elem.toString()); } return xpath; }
private SynapseXPath createXPath(String expression) throws JaxenException { SynapseXPath xpath = new SynapseXPath(expression); xpath.addNamespace("m0", "http://services.samples/xsd"); xpath.addNamespace("m1", "http://services.samples/xsd2"); return xpath; }
public void testContentAwareness() throws Exception { assertEquals(false, new SynapseXPath("$trp:xxx" ).isContentAware()); assertEquals(true, new SynapseXPath("/test/cdaea" ).isContentAware()); assertEquals(false, new SynapseXPath("get-property('SYSTEM_TIME')" ).isContentAware()); assertEquals(false, new SynapseXPath("get-property('registry', 'gov:/apimgt/metadata/log')" ).isContentAware()); //test for get-property with ',' with whitespase assertEquals(false, new SynapseXPath("get-property('registry' , 'gov:/apimgt/metadata/log')" ).isContentAware()); assertEquals(false, new SynapseXPath("get-property('transport', 'Content-Type')" ).isContentAware()); assertEquals(false, new SynapseXPath("get-property('system', 'JAVA_HOME')" ).isContentAware()); } }
public void testStandardXPathFunctions() throws Exception { MessageContext ctx = TestUtils.getTestContext("<test>123456</test>"); assertEquals(6, new SynapseXPath("string-length(//test)").numberValueOf(ctx).intValue()); }
public void testAbsoluteXPath() throws Exception { SynapseXPath xpath = new SynapseXPath("//test"); MessageContext ctx = TestUtils.getTestContext("<test>" + message + "</test>"); assertEquals(message, xpath.stringValueOf(ctx)); }
public void testAxis2ContextProperties() throws Exception { Axis2MessageContext synCtx = TestUtils.getAxis2MessageContext("<test/>", null); synCtx.getAxis2MessageContext().setProperty("test", message); synCtx.getAxis2MessageContext().setProperty("test2", "1234"); assertEquals(message, new SynapseXPath("$axis2:test").evaluate(synCtx)); assertEquals(1234, new SynapseXPath("$axis2:test2").numberValueOf(synCtx).intValue()); assertTrue(new SynapseXPath("$axis2:test2 = 1234").booleanValueOf(synCtx)); }
public void testMessageContextGetStringValueBody() throws Exception { SynapseXPath axiomXpath = new SynapseXPath("$body/ns1:a/ns1:c"); axiomXpath.addNamespace("ns1", nsNamespace1); MessageContext synCtx = TestUtils.getTestContext(sampleBody); String result = axiomXpath.stringValueOf(synCtx); assertEquals("second", result); }
public void testContextProperties() throws Exception { SynapseXPath xpath = new SynapseXPath("$ctx:test"); MessageContext synCtx = new TestMessageContext(); synCtx.setProperty("test", message); assertEquals(xpath.evaluate(synCtx), message); }
public void testBodyRelativeXPath() throws Exception { SynapseXPath xpath = new SynapseXPath("$body/test"); MessageContext ctx = TestUtils.getTestContext("<test>" + message + "</test>"); assertEquals(message, xpath.stringValueOf(ctx)); Object node = xpath.selectSingleNode(ctx); assertTrue(node instanceof OMElement); assertEquals(message, ((OMElement)node).getText()); }
public void testMessageContextGetStringValueEnvelope() throws Exception { SynapseXPath axiomXpath = new SynapseXPath("/s11:Envelope/s11:Body/ns1:a/ns1:c"); axiomXpath.addNamespace("s11", nsSoapEnv); axiomXpath.addNamespace("ns1", nsNamespace1); MessageContext synCtx = TestUtils.getTestContext(sampleBody); String result = axiomXpath.stringValueOf(synCtx); assertEquals("second", result); }
public void testContextProperties() throws Exception { SynapseXPath xpath = new SynapseXPath("$ctx:timeout"); AbstractEndpoint endpoint = new AddressEndpoint(); EndpointDefinition definition = new EndpointDefinition(); endpoint.setDefinition(definition); definition.setDynamicTimeoutExpression(xpath); MessageContext synCtx = new TestMessageContext(); synCtx.setProperty("timeout", "90000"); assertEquals(Long.valueOf((String) xpath.evaluate(synCtx)).longValue(), endpoint.getDefinition().evaluateDynamicEndpointTimeout(synCtx)); }
public void testCustomVariables() throws Exception { SynapseXPath xpath = new SynapseXPath("$myvar"); SimpleVariableContext variableContext = new SimpleVariableContext(); variableContext.setVariableValue("myvar", "myvalue"); xpath.setVariableContext(variableContext); assertEquals("myvalue", xpath.evaluate(TestUtils.getTestContext("<test/>"))); }
public void testHeaderRelativeXPath() throws Exception { MessageContext ctx = TestUtils.getTestContext("<test>" + message + "</test>"); OMFactory fac = ctx.getEnvelope().getOMFactory(); OMNamespace ns = fac.createOMNamespace("http://test", "t"); ctx.getEnvelope().getHeader().addHeaderBlock("test", ns).setText(message); ctx.getEnvelope().getHeader().addHeaderBlock("test2", ns); SynapseXPath xpath = new SynapseXPath("$header/t:test"); xpath.addNamespace(ns); assertEquals(message, xpath.stringValueOf(ctx)); xpath = new SynapseXPath("$header/*"); assertEquals(2, xpath.selectNodes(ctx).size()); }
public void testSimpleHeaderXPathSetAndRemove() throws Exception { HeaderMediator headerMediator = new HeaderMediator(); headerMediator.setQName(new QName(SynapseConstants.HEADER_TO)); headerMediator.setExpression(new SynapseXPath("concat('http://','server','/path')")); // invoke transformation, with static enveope MessageContext synCtx = TestUtils.getTestContext("<empty/>"); headerMediator.mediate(synCtx); assertTrue(TEST_HEADER.equals(synCtx.getTo().getAddress())); // set the header mediator as a remove-header headerMediator.setAction(HeaderMediator.ACTION_REMOVE); headerMediator.mediate(synCtx); assertTrue(synCtx.getTo() == null); }