use of org.apache.axiom.soap.SOAPFactory in project wso2-synapse by wso2.
the class SOAPConversionTest method getSOAP11Envelope.
private SOAPEnvelope getSOAP11Envelope() {
SOAPFactory fac = OMAbstractFactory.getSOAP11Factory();
SOAPEnvelope envelope = fac.getDefaultEnvelope();
envelope.getBody().addChild(createPayload(fac));
populateHeader(envelope, fac);
return envelope;
}
use of org.apache.axiom.soap.SOAPFactory in project wso2-synapse by wso2.
the class FIXUtils method setSOAPEnvelope.
/**
* FIX messages are non-XML. So convert them into XML using the AXIOM API.
* Put the FIX message into an Axis2 MessageContext.The basic format of the
* generated SOAP envelope;
* <p/>
* <soapEnvelope>
* <soapBody>
* <message>
* <header> ....</header>
* <body> .... </body>
* <trailer> .... </trailer>
* </message>
* </soapBody>
* </soapEnvelope>
*
* @param message the FIX message
* @param counter application level sequence number of the message
* @param sessionID the incoming session
* @param msgCtx the Axis2 MessageContext to hold the FIX message
* @throws AxisFault the exception thrown when invalid soap envelopes are set to the msgCtx
*/
public void setSOAPEnvelope(Message message, int counter, String sessionID, MessageContext msgCtx) throws AxisFault {
if (log.isDebugEnabled()) {
log.debug("Creating SOAP envelope for FIX message...");
}
SOAPFactory soapFactory = new SOAP11Factory();
OMElement msg = soapFactory.createOMElement(FIXConstants.FIX_MESSAGE, null);
msg.addAttribute(soapFactory.createOMAttribute(FIXConstants.FIX_MESSAGE_INCOMING_SESSION, null, sessionID));
msg.addAttribute(soapFactory.createOMAttribute(FIXConstants.FIX_MESSAGE_COUNTER, null, String.valueOf(counter)));
OMElement header = soapFactory.createOMElement(FIXConstants.FIX_HEADER, null);
OMElement body = soapFactory.createOMElement(FIXConstants.FIX_BODY, null);
OMElement trailer = soapFactory.createOMElement(FIXConstants.FIX_TRAILER, null);
// process FIX header
Iterator<Field<?>> iter = message.getHeader().iterator();
if (iter != null) {
while (iter.hasNext()) {
Field<?> field = iter.next();
OMElement msgField = soapFactory.createOMElement(FIXConstants.FIX_FIELD, null);
msgField.addAttribute(soapFactory.createOMAttribute(FIXConstants.FIX_FIELD_ID, null, String.valueOf(field.getTag())));
Object value = field.getObject();
if (value instanceof byte[]) {
DataSource dataSource = new ByteArrayDataSource((byte[]) value);
DataHandler dataHandler = new DataHandler(dataSource);
String contentID = msgCtx.addAttachment(dataHandler);
OMElement binaryData = soapFactory.createOMElement(FIXConstants.FIX_BINARY_FIELD, null);
String binaryCID = "cid:" + contentID;
binaryData.addAttribute(FIXConstants.FIX_MESSAGE_REFERENCE, binaryCID, null);
msgField.addChild(binaryData);
} else {
createOMText(soapFactory, msgField, value.toString());
}
header.addChild(msgField);
}
}
// process FIX body
convertFIXBodyToXML(message, body, soapFactory, msgCtx);
// process FIX trailer
iter = message.getTrailer().iterator();
if (iter != null) {
while (iter.hasNext()) {
Field<?> field = iter.next();
OMElement msgField = soapFactory.createOMElement(FIXConstants.FIX_FIELD, null);
msgField.addAttribute(soapFactory.createOMAttribute(FIXConstants.FIX_FIELD_ID, null, String.valueOf(field.getTag())));
Object value = field.getObject();
if (value instanceof byte[]) {
DataSource dataSource = new ByteArrayDataSource((byte[]) value);
DataHandler dataHandler = new DataHandler(dataSource);
String contentID = msgCtx.addAttachment(dataHandler);
OMElement binaryData = soapFactory.createOMElement(FIXConstants.FIX_BINARY_FIELD, null);
String binaryCID = "cid:" + contentID;
binaryData.addAttribute(FIXConstants.FIX_MESSAGE_REFERENCE, binaryCID, null);
msgField.addChild(binaryData);
} else {
createOMText(soapFactory, msgField, value.toString());
}
trailer.addChild(msgField);
}
}
msg.addChild(header);
msg.addChild(body);
msg.addChild(trailer);
SOAPEnvelope envelope = soapFactory.getDefaultEnvelope();
envelope.getBody().addChild(msg);
msgCtx.setEnvelope(envelope);
}
use of org.apache.axiom.soap.SOAPFactory in project wso2-synapse by wso2.
the class VFSTransportSenderTest method populateMessageContext.
/**
* Function to populate message context
* @param messageContext message context
* @throws AxisFault
*/
private void populateMessageContext(MessageContext messageContext) throws AxisFault {
SOAPFactory fac = OMAbstractFactory.getSOAP11Factory();
SOAPEnvelope env = fac.getDefaultEnvelope();
OMElement payload = fac.createOMElement(BaseConstants.DEFAULT_TEXT_WRAPPER);
env.getBody().addChild(payload);
messageContext.setEnvelope(env);
AxisService axisService = new AxisService();
messageContext.setAxisService(axisService);
}
use of org.apache.axiom.soap.SOAPFactory in project wso2-synapse by wso2.
the class MessageHelper method cloneSOAPFault.
/**
* Clones the SOAPFault, fault cloning is not the same as cloning the OMElement because if the
* Fault is accessed through the SOAPEnvelope.getBody().getFault() method it will lead to a
* class cast because the cloned element is just an OMElement but not a Fault.
*
* @param fault that needs to be cloned
* @return the cloned fault
*/
public static SOAPFault cloneSOAPFault(SOAPFault fault) {
SOAPFactory fac;
int soapVersion;
final int SOAP_11 = 1;
final int SOAP_12 = 2;
if (SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(fault.getNamespace().getNamespaceURI())) {
fac = OMAbstractFactory.getSOAP11Factory();
soapVersion = SOAP_11;
} else {
fac = OMAbstractFactory.getSOAP12Factory();
soapVersion = SOAP_12;
}
SOAPFault newFault = fac.createSOAPFault();
SOAPFaultCode code = fac.createSOAPFaultCode();
SOAPFaultReason reason = fac.createSOAPFaultReason();
switch(soapVersion) {
case SOAP_11:
code.setText(fault.getCode().getTextAsQName());
reason.setText(fault.getReason().getText());
break;
case SOAP_12:
SOAPFaultValue value = fac.createSOAPFaultValue(code);
value.setText(fault.getCode().getTextAsQName());
for (Object obj : fault.getReason().getAllSoapTexts()) {
SOAPFaultText text = fac.createSOAPFaultText();
text.setText(((SOAPFaultText) obj).getText());
reason.addSOAPText(text);
}
break;
}
newFault.setCode(code);
newFault.setReason(reason);
if (fault.getNode() != null) {
SOAPFaultNode soapfaultNode = fac.createSOAPFaultNode();
soapfaultNode.setNodeValue(fault.getNode().getNodeValue());
newFault.setNode(soapfaultNode);
}
if (fault.getRole() != null) {
SOAPFaultRole soapFaultRole = fac.createSOAPFaultRole();
soapFaultRole.setRoleValue(fault.getRole().getRoleValue());
newFault.setRole(soapFaultRole);
}
if (fault.getDetail() != null) {
SOAPFaultDetail soapFaultDetail = fac.createSOAPFaultDetail();
for (Iterator itr = fault.getDetail().getAllDetailEntries(); itr.hasNext(); ) {
Object element = itr.next();
if (element instanceof OMElement) {
soapFaultDetail.addDetailEntry(((OMElement) element).cloneOMElement());
}
}
newFault.setDetail(soapFaultDetail);
}
return newFault;
}
use of org.apache.axiom.soap.SOAPFactory in project wso2-synapse by wso2.
the class MessageHelper method cloneArrayList.
/*
* This method will deep clone array list by creating a new ArrayList and cloning and adding each element in it
* */
public static ArrayList<Object> cloneArrayList(ArrayList<Object> arrayList) {
ArrayList<Object> newArrayList = null;
if (arrayList != null) {
newArrayList = new ArrayList<Object>();
for (Object obj : arrayList) {
if (obj instanceof SOAPHeaderBlock) {
SOAPFactory fac = (SOAPFactory) ((SOAPHeaderBlock) obj).getOMFactory();
obj = ((SOAPHeaderBlock) obj).cloneOMElement();
try {
obj = ElementHelper.toSOAPHeaderBlock((OMElement) obj, fac);
} catch (Exception e) {
handleException(e);
}
} else if (obj instanceof SOAPEnvelope) {
SOAPEnvelope enve = (SOAPEnvelope) obj;
obj = MessageHelper.cloneSOAPEnvelope(enve);
} else if (obj instanceof OMElement) {
obj = ((OMElement) obj).cloneOMElement();
} else {
if (log.isDebugEnabled()) {
log.error("Array List deep clone not implemented for Class type : " + obj.getClass().getName());
}
}
newArrayList.add(obj);
}
}
return newArrayList;
}
Aggregations