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 void addNamespace(OMNamespace ns) throws JaxenException { addNamespace(ns.getPrefix(), ns.getNamespaceURI()); }
/** * Create an SynapseXPath from an xpath string */ protected SynapseXPath createSynapseXPATH(String xpath, Namespaces nsAnnotation) { Map<String, String> namespaces = getNamespaces(nsAnnotation); try { SynapseXPath axiomXPath = new SynapseXPath(xpath); for (Map.Entry<String, String> entry : namespaces.entrySet()) { axiomXPath.addNamespace(entry.getKey(), entry.getValue()); } return axiomXPath; } catch (JaxenException e) { throw new RuntimeException("Error creating SynapseXPath: " + xpath, e); } }
/** * Create an SynapseXPath from an xpath string */ protected SynapseXPath createSynapseXPATH(String xpath, Namespaces nsAnnotation) { Map<String, String> namespaces = getNamespaces(nsAnnotation); try { SynapseXPath axiomXPath = new SynapseXPath(xpath); for (Map.Entry<String, String> entry : namespaces.entrySet()) { axiomXPath.addNamespace(entry.getKey(), entry.getValue()); } return axiomXPath; } catch (JaxenException e) { throw new RuntimeException("Error creating SynapseXPath: " + xpath, e); } }
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 Object evalutePropertyExpression(MessageContext synCtx) { SynapseXPath expr = null; try { expr = new SynapseXPath(this.keyValue.substring(1, keyValue.length() - 1)); for (OMNamespace aNamespaceList : namespaceList) { expr.addNamespace(aNamespaceList); } String result = expr.stringValueOf(synCtx); SynapseXPath expression = new SynapseXPath(result); for (OMNamespace aNamespaceList : namespaceList) { expression.addNamespace(aNamespaceList); } return expression; } catch (Exception e) { handleException("Can not evaluate escaped expression : " + expr); } return this.expression; }
/** * Retrieving dynamic key * * @return SynapseXpath */ public SynapseXPath getExpression() { if(expression == null && keyValue != null && hasExprTypeKey()){ try { expression = new SynapseXPath (keyValue.substring(1, keyValue.length()-1)); for (OMNamespace aNamespaceList : namespaceList) { expression.addNamespace(aNamespaceList); } } catch (JaxenException e) { expression = null; handleException("Can not evaluate escaped expression.."); } } return expression; }
public void init() { try { //TODO: pick values from the constants topicHeaderName = getPropertyValue("topicHeaderName"); if(topicHeaderName==null){ handleException("Unable to create topic header topic header name is null"); } topicHeaderNS = getPropertyValue("topicHeaderNS"); if(topicHeaderNS==null){ handleException("Unable to create topic header topic header namespace is null"); } topicXPath = new SynapseXPath( "s11:Header/ns:" + topicHeaderName + " | s12:Header/ns:" + topicHeaderName); topicXPath.addNamespace("s11", "http://schemas.xmlsoap.org/soap/envelope/"); topicXPath.addNamespace("s12", "http://www.w3.org/2003/05/soap-envelope"); topicXPath.addNamespace("ns", topicHeaderNS); } catch (JaxenException e) { handleException("Unable to create the topic header XPath", e); } }
public void addNamespace(OMNamespace ns) throws JaxenException { addNamespace(ns.getPrefix(), ns.getNamespaceURI()); domNamespaceMap.addNamespace(ns.getPrefix(), ns.getNamespaceURI()); ParserComponent.addToNameSpaceMap(ns.getPrefix(), ns.getNamespaceURI()); }
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 testN2N() throws Exception { // Creating the Simple Commodity Client System.getProperties().remove(org.apache.axis2.Constants.AXIS2_CONF); ServiceClient businessClient = new ServiceClient(null, null); Options options = new Options(); options.setTo( new EndpointReference("http://127.0.0.1:10100/CommodityQuote")); businessClient.setOptions(options); OMElement response = null; response = businessClient.sendReceive(commodityPayload()); assertNotNull(response); SynapseXPath xPath = new SynapseXPath("//return"); xPath.addNamespace("ns","http://services.samples/xsd"); OMElement returnEle = (OMElement) xPath.selectSingleNode(response); assertNotNull(returnEle); assertEquals(returnEle.getText().trim(),"100"); }
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 testFilterConditionFalseRegex() throws Exception { setFilterConditionPassed(false); // create a new filter mediator FilterMediator filter = new FilterMediator(); // set source xpath condition to //symbol SynapseXPath source = new SynapseXPath("//wsx:symbol"); source.addNamespace("wsx", "http://www.webserviceX.NET/"); filter.setSource(source); // set regex to MSFT Pattern regex = Pattern.compile("MSFT"); filter.setRegex(regex); // set dummy mediator to be called on success filter.addChild(testMediator); // test validate mediator, with static enveope filter.mediate(TestUtils.getTestContext(REQ)); assertTrue(!filterConditionPassed); }
public void testFilterConditionTrueRegex() throws Exception { setFilterConditionPassed(false); // create a new filter mediator FilterMediator filter = new FilterMediator(); // set source xpath condition to //symbol SynapseXPath source = new SynapseXPath("//wsx:symbol"); source.addNamespace("wsx", "http://www.webserviceX.NET/"); filter.setSource(source); // set regex to IBM Pattern regex = Pattern.compile("IBM"); filter.setRegex(regex); // set dummy mediator to be called on success filter.addChild(testMediator); // test validate mediator, with static enveope filter.mediate(TestUtils.getTestContext(REQ)); assertTrue(filterConditionPassed); }
public void testFilterConditionFalseXPath() throws Exception { setFilterConditionPassed(false); // create a new filter mediator FilterMediator filter = new FilterMediator(); // set xpath condition to MSFT SynapseXPath xpath = new SynapseXPath("//*[wsx:symbol='MSFT']"); xpath.addNamespace("wsx", "http://www.webserviceX.NET/"); filter.setXpath(xpath); // set dummy mediator to be called on success filter.addChild(testMediator); // test validate mediator, with static enveope filter.mediate(TestUtils.getTestContext(REQ)); assertTrue(!filterConditionPassed); }
public void testFilterConditionTrueXPath() throws Exception { setFilterConditionPassed(false); // create a new filter mediator FilterMediator filter = new FilterMediator(); // set xpath condition to IBM SynapseXPath xpath = new SynapseXPath("//*[wsx:symbol='IBM']"); xpath.addNamespace("wsx", "http://www.webserviceX.NET/"); filter.setXpath(xpath); // set dummy mediator to be called on success filter.addChild(testMediator); // test validate mediator, with static enveope filter.mediate(TestUtils.getTestContext(REQ)); assertTrue(filterConditionPassed); }
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 testTransformXSLTCustomSource() throws Exception { // create a new XSLT mediator XSLTMediator transformMediator = new XSLTMediator(); // set xpath condition to select source SynapseXPath xpath = new SynapseXPath("//m0:CheckPriceRequest"); xpath.addNamespace("m0", "http://services.samples/xsd"); transformMediator.setSource(xpath); // set XSLT transformation URL setXsltTransformationURL(transformMediator, "xslt-key"); MessageContext synCtx = new TestMessageContextBuilder().setRequireAxis2MessageContext(true).addFileEntry ("xslt-key", "../../repository/conf/sample/resources/transform/transform_unittest.xslt") .setBodyFromString(SOURCE).addTextAroundBody().build(); transformMediator.mediate(synCtx); // validate result assertQuoteElement(synCtx.getEnvelope().getBody().getFirstOMChild().getNextOMSibling()); }