public String getEvaluatedExpression(MessageContext synCtx) { return expression.stringValueOf(synCtx); }
public boolean isSatisfied(MessageContext mc) { String evaluatedValue = sourceXpath.stringValueOf(mc); if (evaluatedValue.equals(resultValue)) { return true; } else if (evaluatedValue.startsWith((resultValue + FILTER_SEP).trim())) { return true; } return false; }
public boolean isSatisfied(MessageContext mc) { String evaluatedValue = sourceXpath.stringValueOf(mc); if (evaluatedValue.equals(resultValue)) { return true; } else if (evaluatedValue.startsWith((resultValue + FILTER_SEP).trim())) { return true; } return false; }
/** * Evaluating key based on message context * used when key is a xpath expression * * @param synCtx message context * @return string value of evaluated key */ public String evaluateValue(MessageContext synCtx) { if (keyValue != null) { //if static kry: return static key return keyValue; } else if (expression != null) { //if dynamic key return evaluated value return expression.stringValueOf(synCtx); } else { handleException("Can not evaluate the key: " + "key should be static or dynamic key"); return null; } }
private Object getResultValue(MessageContext synCtx) { if (value != null) { return value; } else if (valueElement != null) { // Need to take a clone of the element, otherwise same reference is shared across all the requests return valueElement.cloneOMElement(); } else { return convertValue(expression.stringValueOf(synCtx), type); } }
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; }
/** * Extracts argument values from the current message context. * @param synCtx Current message under mediation. * @return Extracted argument values. */ private Object[] getArgValues(MessageContext synCtx) { Object[] argValues = new Object[argumentList.size()]; for (int i = 0; i < argumentList.size(); ++i) { Argument arg = argumentList.get(i); if (arg.getValue() != null) { argValues[i] = arg.getValue(); } else if (arg.getExpression() != null) { String value = arg.getExpression().stringValueOf(synCtx); if (value != null) { argValues[i] = value; } else { argValues[i] = ""; } } else { handleException("Unexpected argument type detected in the payloadFactory " + "mediator configuration", synCtx); } } return argValues; }
public Object evalutePropertyExpression(MessageContext synCtx) { //this.keyValue = null; //String evaluatedProperty = this.evaluateValue(synCtx); SynapseXPath _expression = null; try { _expression = new SynapseXPath(this.keyValue.substring(1, keyValue.length() - 1)); for (OMNamespace aNamespaceList : namespaceList) { _expression.addNamespace(aNamespaceList); } String result =_expression.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.."); } return this.expression; }
private void setFaultCode(MessageContext synCtx, SOAPFactory factory, SOAPFault fault, int soapVersion) { QName fault_code = null; if (faultCodeValue == null && faultCodeExpr == null) { handleException("A valid fault code QName value or expression is required", synCtx); } else if (faultCodeValue != null) { fault_code = faultCodeValue; } else { String codeStr = faultCodeExpr.stringValueOf(synCtx); fault_code = new QName(fault.getNamespace().getNamespaceURI(),codeStr); } SOAPFaultCode code = factory.createSOAPFaultCode(); switch (soapVersion) { case SOAP11: code.setText(fault_code); break; case SOAP12: SOAPFaultValue value = factory.createSOAPFaultValue(code); value.setText(fault_code); break; } fault.setCode(code); }
/** * Send by calling to the real endpoint * @param synCtx the message to send */ public void send(MessageContext synCtx) { String key = keyExpression.stringValueOf(synCtx); Endpoint ep = loadAndInitEndpoint(((Axis2MessageContext) synCtx). getAxis2MessageContext().getConfigurationContext(), key); if (ep != null) { ep.send(synCtx); } else { informFailure(synCtx, SynapseConstants.ENDPOINT_IN_DIRECT_NOT_READY, "Couldn't find the endpoint with the key : " + key); } }
private void setFaultCode(MessageContext synCtx, SOAPFactory factory, SOAPFault fault, int soapVersion) { QName fault_code = null; if (faultCodeValue == null && faultCodeExpr == null) { handleException("A valid fault code QName value or expression is required", synCtx); } else if (faultCodeValue != null) { fault_code = faultCodeValue; } else { String codeStr = faultCodeExpr.stringValueOf(synCtx); fault_code = new QName(fault.getNamespace().getNamespaceURI(),codeStr); } SOAPFaultCode code = factory.createSOAPFaultCode(); switch (soapVersion) { case SOAP11: code.setText(fault_code); break; case SOAP12: SOAPFaultValue value = factory.createSOAPFaultValue(code); value.setText(fault_code); break; } fault.setCode(code); }
/** * Send by calling to the real endpoint * * @param synCtx the message to send */ public void sendMessage(MessageContext synCtx) { String key = keyExpression.stringValueOf(synCtx); Endpoint ep = loadAndInitEndpoint(((Axis2MessageContext) synCtx). getAxis2MessageContext().getConfigurationContext(), key); if (ep != null) { ep.send(synCtx); } else { informFailure(synCtx, SynapseConstants.ENDPOINT_IN_DIRECT_NOT_READY, "Couldn't find the endpoint with the key : " + key); } }
public void testStringXPath2() throws Exception { SynapseXPath xpath = SynapseXPath.parseXPathString("$body//{http://somens}test/{http://someother}another"); MessageContext ctx = TestUtils.getTestContext("<m0:test xmlns:m0=\"http://somens\"><m1:another xmlns:m1=\"http://someother\">" + message + "</m1:another></m0:test>"); assertEquals(message, xpath.stringValueOf(ctx)); }
public void testStringXPath() throws Exception { SynapseXPath xpath = SynapseXPath.parseXPathString("$body//{http://somens}test"); MessageContext ctx = TestUtils.getTestContext("<m0:test xmlns:m0=\"http://somens\">" + message + "</m0:test>"); assertEquals(message, xpath.stringValueOf(ctx)); }
public void testAbsoluteXPath() throws Exception { SynapseXPath xpath = new SynapseXPath("//test"); MessageContext ctx = TestUtils.getTestContext("<test>" + message + "</test>"); assertEquals(message, xpath.stringValueOf(ctx)); }
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 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()); }
private void setFaultReason(MessageContext synCtx, SOAPFactory factory, SOAPFault fault, int soapVersion) { String reasonString = null; if (faultReasonValue == null && faultReasonExpr == null) { handleException("A valid fault reason value or expression is required", synCtx); } else if (faultReasonValue != null) { reasonString = faultReasonValue; } else { reasonString = faultReasonExpr.stringValueOf(synCtx); } SOAPFaultReason reason = factory.createSOAPFaultReason(); switch(soapVersion) { case SOAP11: reason.setText(reasonString); break; case SOAP12: SOAPFaultText text = factory.createSOAPFaultText(); text.setText(reasonString); text.setLang("en"); reason.addSOAPText(text); break; } fault.setReason(reason); }
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 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()); }