use of org.apache.axiom.soap.SOAPFactory in project wso2-synapse by wso2.
the class SamplingService method setSoapHeaderBlock.
private void setSoapHeaderBlock(MessageContext synCtx) {
// Send the SOAP Header Blocks to support WS-Addressing
if (synCtx.getEnvelope().getHeader() != null) {
Iterator iHeader = synCtx.getEnvelope().getHeader().getChildren();
SOAPFactory fac;
if (SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(synCtx.getEnvelope().getBody().getNamespace().getNamespaceURI())) {
fac = OMAbstractFactory.getSOAP11Factory();
} else {
fac = OMAbstractFactory.getSOAP12Factory();
}
List<OMNode> newHeaderNodes = new ArrayList<OMNode>();
while (iHeader.hasNext()) {
try {
Object element = iHeader.next();
if (!(element instanceof SOAPHeaderBlock)) {
if (element instanceof OMElement) {
newHeaderNodes.add(ElementHelper.toSOAPHeaderBlock((OMElement) element, fac));
}
iHeader.remove();
}
} catch (OMException e) {
log.error("Unable to convert to SoapHeader Block", e);
} catch (Exception e) {
log.error("Unable to convert to SoapHeader Block", e);
}
}
for (OMNode newHeaderNode : newHeaderNodes) {
synCtx.getEnvelope().getHeader().addChild(newHeaderNode);
}
}
}
use of org.apache.axiom.soap.SOAPFactory in project wso2-synapse by wso2.
the class MessageConverter method getSoapEnvelope.
private static SOAPEnvelope getSoapEnvelope(String soapEnvelpe) {
OMElement response;
try {
response = AXIOMUtil.stringToOM(soapEnvelpe);
} catch (Exception e) {
logger.error("Cannot create SOAP Envelop. Error:" + e.getLocalizedMessage(), e);
return null;
}
SOAPFactory soapFactory;
String soapNamespace = response.getNamespace().getNamespaceURI();
if (soapNamespace.equals(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI)) {
soapFactory = OMAbstractFactory.getSOAP12Factory();
} else {
soapFactory = OMAbstractFactory.getSOAP11Factory();
}
SOAPEnvelope soapEnvelope = soapFactory.getDefaultEnvelope();
// Set the headers of the message
if (response.getFirstElement().getLocalName().contains(HEADER_STRING)) {
SOAPHeader header = soapEnvelope.getHeader();
SOAPFactory fac = (SOAPFactory) soapEnvelope.getOMFactory();
Iterator headers = response.getFirstElement().getChildElements();
while (headers.hasNext()) {
OMElement soapHeader = (OMElement) headers.next();
SOAPHeaderBlock hb = header.addHeaderBlock(soapHeader.getLocalName(), fac.createOMNamespace(soapHeader.getNamespace().getNamespaceURI(), soapHeader.getNamespace().getPrefix()));
hb.setText(soapHeader.getText());
// Add the child elements of the header (if any)
Iterator elements = soapHeader.getChildElements();
while (elements.hasNext()) {
hb.addChild((OMNode) elements.next());
}
}
response.getFirstElement().detach();
}
if (response.getFirstElement().getFirstElement() != null) {
soapEnvelope.getBody().addChild(response.getFirstElement().getFirstElement());
}
return soapEnvelope;
}
use of org.apache.axiom.soap.SOAPFactory in project wso2-synapse by wso2.
the class AXIOMUtils method getSOAPEnvFromOM.
/**
* @param omElement OMElement which need to convert to SOAPEnvelope
* @return SOAPEnvelope with contents of passed OMElement
*/
public static SOAPEnvelope getSOAPEnvFromOM(OMElement omElement) {
SOAPFactory soapFactory;
if (omElement.getQName().getNamespaceURI().equals(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI)) {
soapFactory = OMAbstractFactory.getSOAP12Factory();
} else {
soapFactory = OMAbstractFactory.getSOAP11Factory();
}
StAXSOAPModelBuilder builder = new StAXSOAPModelBuilder(omElement.getXMLStreamReader(), soapFactory, omElement.getQName().getNamespaceURI());
return builder.getSOAPEnvelope();
}
use of org.apache.axiom.soap.SOAPFactory in project wso2-synapse by wso2.
the class RelaySecuirtyMessageBuilderDispatchandler method build.
private void build(MessageContext messageContext) {
try {
RelayUtils.buildMessage(messageContext, false);
if (messageContext.getEnvelope().getHeader() == null) {
SOAPFactory fac = messageContext.isSOAP11() ? OMAbstractFactory.getSOAP11Factory() : OMAbstractFactory.getSOAP12Factory();
fac.createSOAPHeader(messageContext.getEnvelope());
}
} catch (Exception e) {
log.error("Error while executing the message at relaySecurity handler", e);
}
}
use of org.apache.axiom.soap.SOAPFactory in project wso2-synapse by wso2.
the class SourceTextRetrieverTest method testSOAPEnvelopeTextRetriever.
public void testSOAPEnvelopeTextRetriever() throws Exception {
SOAPFactory fac = OMAbstractFactory.getSOAP11Factory();
SOAPEnvelope env = fac.getDefaultEnvelope();
OMElement payload = AXIOMUtil.stringToOM(fac, "<getQuote id=\"attr\"><symbol>TEST</symbol><property>1</property>" + "<property>2</property></getQuote>");
env.getBody().addChild(payload);
MessageContext msgCtx = new MessageContext();
msgCtx.setEnvelope(env);
EvaluatorContext context = new EvaluatorContext(null, null);
context.setMessageContext(msgCtx);
SOAPEnvelopeTextRetriever txtRtvr = new SOAPEnvelopeTextRetriever("//symbol");
assertEquals("TEST", txtRtvr.getSourceText(context));
txtRtvr = new SOAPEnvelopeTextRetriever("//getQuote/@id");
assertEquals("attr", txtRtvr.getSourceText(context));
txtRtvr = new SOAPEnvelopeTextRetriever("//property[1]");
assertEquals("1", txtRtvr.getSourceText(context));
txtRtvr = new SOAPEnvelopeTextRetriever("//property[2]");
assertEquals("2", txtRtvr.getSourceText(context));
}
Aggregations