use of org.apache.axiom.soap.SOAPFactory in project wso2-synapse by wso2.
the class BinaryRelayBuilder method processDocument.
public OMElement processDocument(InputStream inputStream, String contentType, MessageContext messageContext) throws AxisFault {
try {
// Fix for https://wso2.org/jira/browse/CARBON-7256
messageContext.setProperty(Constants.Configuration.CONTENT_TYPE, contentType);
// We will create a SOAP message, which holds the input message as a blob
SOAPFactory factory = OMAbstractFactory.getSOAP12Factory();
SOAPEnvelope env = factory.getDefaultEnvelope();
if (inputStream != null) {
OMNamespace ns = factory.createOMNamespace(RelayConstants.BINARY_CONTENT_QNAME.getNamespaceURI(), "ns");
OMElement omEle = factory.createOMElement(RelayConstants.BINARY_CONTENT_QNAME.getLocalPart(), ns);
StreamingOnRequestDataSource ds = new StreamingOnRequestDataSource(inputStream);
DataHandler dataHandler = new DataHandler(ds);
// create an OMText node with the above DataHandler and set optimized to true
OMText textData = factory.createOMText(dataHandler, true);
omEle.addChild(textData);
env.getBody().addChild(omEle);
}
return env;
} catch (SOAPProcessingException e) {
throw AxisFault.makeFault(e);
} catch (OMException e) {
throw AxisFault.makeFault(e);
}
}
use of org.apache.axiom.soap.SOAPFactory in project wso2-synapse by wso2.
the class CalloutMediator 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();
/* Convert only OMElements. Skip SOAPHeaderBlock elements*/
if (!(element instanceof SOAPHeaderBlock)) {
if (element instanceof OMElement) {
newHeaderNodes.add(ElementHelper.toSOAPHeaderBlock((OMElement) element, fac).cloneOMElement());
}
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 CommonScriptMessageContext method addHeader.
/**
* Add a new SOAP header to the message.
*
* @param mustUnderstand the value for the <code>soapenv:mustUnderstand</code> attribute
* @param content the XML for the new header
* @throws ScriptException if an error occurs when converting the XML to OM
*/
@Override
public void addHeader(boolean mustUnderstand, Object content) throws ScriptException {
SOAPEnvelope envelope = mc.getEnvelope();
SOAPFactory factory = (SOAPFactory) envelope.getOMFactory();
SOAPHeader header = envelope.getHeader();
if (header == null) {
header = factory.createSOAPHeader(envelope);
}
OMElement element = xmlHelper.toOMElement(content);
// We can't add the element directly to the SOAPHeader. Instead, we need to copy the
// information over to a SOAPHeaderBlock.
SOAPHeaderBlock headerBlock = header.addHeaderBlock(element.getLocalName(), element.getNamespace());
for (Iterator it = element.getAllAttributes(); it.hasNext(); ) {
headerBlock.addAttribute((OMAttribute) it.next());
}
headerBlock.setMustUnderstand(mustUnderstand);
OMNode child = element.getFirstOMChild();
while (child != null) {
// Get the next child before addChild will detach the node from its original place.
OMNode next = child.getNextOMSibling();
headerBlock.addChild(child);
child = next;
}
}
use of org.apache.axiom.soap.SOAPFactory in project wso2-synapse by wso2.
the class HessianTestHelper method addSoapFaultToMessageContext.
public void addSoapFaultToMessageContext(MessageContext msgContext, String faultCode, String faultReason, String faultDetail) throws AxisFault {
SOAPFactory factory = OMAbstractFactory.getSOAP11Factory();
SOAPEnvelope faultEnvelope = factory.getDefaultFaultEnvelope();
SOAPFault soapFault = faultEnvelope.getBody().getFault();
SOAPFaultCode soapFaultCode = factory.createSOAPFaultCode();
soapFaultCode.setText(faultCode);
soapFault.setCode(soapFaultCode);
SOAPFaultReason soapFaultReason = factory.createSOAPFaultReason();
soapFaultReason.setText(faultReason);
soapFault.setReason(soapFaultReason);
SOAPFaultDetail soapFaultDetail = factory.createSOAPFaultDetail();
soapFaultDetail.setText(faultDetail);
soapFault.setDetail(soapFaultDetail);
msgContext.setEnvelope(faultEnvelope);
}
use of org.apache.axiom.soap.SOAPFactory in project wso2-synapse by wso2.
the class SOAPConversionTest method getSOAP12Envelope.
private SOAPEnvelope getSOAP12Envelope() {
SOAPFactory fac = OMAbstractFactory.getSOAP12Factory();
SOAPEnvelope envelope = fac.getDefaultEnvelope();
envelope.getBody().addChild(createPayload(fac));
populateHeader(envelope, fac);
return envelope;
}
Aggregations