use of org.apache.axiom.soap.SOAPFactory in project wso2-synapse by wso2.
the class MessageHelperTest method testCloneSoapEnvelope.
public void testCloneSoapEnvelope() {
SOAPFactory soapFactory;
SOAPHeaderBlock header;
OMFactory omFactory = OMAbstractFactory.getOMFactory();
// Creating a namespace for the header
OMNamespace ns = omFactory.createOMNamespace("http://ws.apache.org/axis2", "hns");
OMElement childNode = omFactory.createOMElement("Child", ns);
// testing SOAP 1.1
soapFactory = OMAbstractFactory.getSOAP11Factory();
// creating a SOAP header block
header = new SOAP11HeaderBlockImpl("CustomHeader", ns, soapFactory);
performTestForCloneEnvelope(soapFactory, header, childNode);
// testing SOAP 1.1
soapFactory = OMAbstractFactory.getSOAP12Factory();
header = new SOAP12HeaderBlockImpl("CustomHeader", ns, soapFactory);
performTestForCloneEnvelope(soapFactory, header, childNode);
}
use of org.apache.axiom.soap.SOAPFactory in project wso2-synapse by wso2.
the class NashornJavaScriptMessageContext 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
*/
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 FIXMessageBuilder method processDocument.
public OMElement processDocument(InputStream inputStream, String contentType, MessageContext messageContext) throws AxisFault {
Reader reader = null;
StringBuilder messageString = new StringBuilder();
quickfix.Message message = null;
try {
String charSetEncoding = (String) messageContext.getProperty(Constants.Configuration.CHARACTER_SET_ENCODING);
if (charSetEncoding == null) {
charSetEncoding = MessageContext.DEFAULT_CHAR_SET_ENCODING;
}
reader = new InputStreamReader(inputStream, charSetEncoding);
try {
int data = reader.read();
while (data != -1) {
char dataChar = (char) data;
data = reader.read();
messageString.append(dataChar);
}
} catch (Exception e) {
// TODO Auto-generated catch block
log.error("Error In creating FIX SOAP envelope ...", e);
throw new AxisFault(e.getMessage());
}
} catch (Exception e) {
// TODO Auto-generated catch block
log.error("Error In creating FIX SOAP envelope ...", e);
throw new AxisFault(e.getMessage());
}
try {
DefaultDataDictionaryProvider dataDictionary = new DefaultDataDictionaryProvider();
String beginString = MessageUtils.getStringField(messageString.toString(), BeginString.FIELD);
DataDictionary dataDic = dataDictionary.getSessionDataDictionary(beginString);
message = new quickfix.Message(messageString.toString(), null, false);
} catch (InvalidMessage e) {
// TODO Auto-generated catch block
log.error("Error In creating FIX SOAP envelope ...", e);
throw new AxisFault(e.getMessage());
}
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, ""));
msg.addAttribute(soapFactory.createOMAttribute(FIXConstants.FIX_MESSAGE_COUNTER, null, String.valueOf("-1")));
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<quickfix.Field<?>> iter = message.getHeader().iterator();
if (iter != null) {
while (iter.hasNext()) {
quickfix.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 = messageContext.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 {
soapFactory.createOMText(msgField, value.toString(), OMElement.CDATA_SECTION_NODE);
}
header.addChild(msgField);
}
}
// process FIX body
convertFIXBodyToXML(message, body, soapFactory, messageContext);
// process FIX trailer
iter = message.getTrailer().iterator();
if (iter != null) {
while (iter.hasNext()) {
quickfix.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 = messageContext.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 {
soapFactory.createOMText(msgField, value.toString(), OMElement.CDATA_SECTION_NODE);
}
trailer.addChild(msgField);
}
}
msg.addChild(header);
msg.addChild(body);
msg.addChild(trailer);
SOAPEnvelope envelope = soapFactory.getDefaultEnvelope();
envelope.getBody().addChild(msg);
messageContext.setEnvelope(envelope);
return msg;
}
use of org.apache.axiom.soap.SOAPFactory in project wso2-synapse by wso2.
the class StockQuoteSampleClient method buildSoapEnvelope.
private SOAPEnvelope buildSoapEnvelope(String clientID, String value) {
SOAPFactory soapFactory = OMAbstractFactory.getSOAP12Factory();
SOAPEnvelope envelope = soapFactory.createSOAPEnvelope();
SOAPHeader header = soapFactory.createSOAPHeader();
envelope.addChild(header);
OMNamespace synNamespace = soapFactory.createOMNamespace("http://ws.apache.org/ns/synapse", "syn");
OMElement clientIDElement = soapFactory.createOMElement("ClientID", synNamespace);
clientIDElement.setText(clientID);
header.addChild(clientIDElement);
SOAPBody body = soapFactory.createSOAPBody();
envelope.addChild(body);
OMElement valueElement = soapFactory.createOMElement("Value", null);
valueElement.setText(value);
body.addChild(valueElement);
return envelope;
}
use of org.apache.axiom.soap.SOAPFactory in project wso2-synapse by wso2.
the class ServerWorker method processEntityEnclosingRequest.
public void processEntityEnclosingRequest(MessageContext msgContext, boolean injectToAxis2Engine) {
try {
String contentTypeHeader = request.getHeaders().get(HTTP.CONTENT_TYPE);
contentTypeHeader = contentTypeHeader != null ? contentTypeHeader : inferContentType();
String charSetEncoding = null;
String contentType = null;
if (contentTypeHeader != null) {
charSetEncoding = BuilderUtil.getCharSetEncoding(contentTypeHeader);
contentType = TransportUtils.getContentType(contentTypeHeader, msgContext);
}
// get the contentType of char encoding
if (charSetEncoding == null) {
charSetEncoding = MessageContext.DEFAULT_CHAR_SET_ENCODING;
}
String method = request.getRequest() != null ? request.getRequest().getRequestLine().getMethod().toUpperCase() : "";
msgContext.setTo(new EndpointReference(request.getUri()));
msgContext.setProperty(HTTPConstants.HTTP_METHOD, method);
msgContext.setProperty(Constants.Configuration.CHARACTER_SET_ENCODING, charSetEncoding);
msgContext.setServerSide(true);
msgContext.setProperty(Constants.Configuration.CONTENT_TYPE, contentTypeHeader);
msgContext.setProperty(Constants.Configuration.MESSAGE_TYPE, contentType);
if (contentTypeHeader == null || HTTPTransportUtils.isRESTRequest(contentTypeHeader) || isRest(contentTypeHeader)) {
msgContext.setProperty(PassThroughConstants.REST_REQUEST_CONTENT_TYPE, contentType);
msgContext.setDoingREST(true);
SOAPEnvelope soapEnvelope = this.handleRESTUrlPost(contentTypeHeader);
msgContext.setProperty(PassThroughConstants.PASS_THROUGH_PIPE, request.getPipe());
processNonEntityEnclosingRESTHandler(soapEnvelope, msgContext, injectToAxis2Engine);
return;
} else {
String soapAction = request.getHeaders().get(SOAP_ACTION_HEADER);
int soapVersion = HTTPTransportUtils.initializeMessageContext(msgContext, soapAction, request.getUri(), contentTypeHeader);
SOAPEnvelope envelope;
if (soapVersion == 1) {
SOAPFactory fac = OMAbstractFactory.getSOAP11Factory();
envelope = fac.getDefaultEnvelope();
} else if (soapVersion == 2) {
SOAPFactory fac = OMAbstractFactory.getSOAP12Factory();
envelope = fac.getDefaultEnvelope();
} else {
SOAPFactory fac = OMAbstractFactory.getSOAP12Factory();
envelope = fac.getDefaultEnvelope();
}
if ((soapAction != null) && soapAction.startsWith("\"") && soapAction.endsWith("\"")) {
soapAction = soapAction.substring(1, soapAction.length() - 1);
msgContext.setSoapAction(soapAction);
}
msgContext.setEnvelope(envelope);
}
msgContext.setProperty(PassThroughConstants.PASS_THROUGH_PIPE, request.getPipe());
if (injectToAxis2Engine) {
AxisEngine.receive(msgContext);
}
} catch (AxisFault axisFault) {
handleException("Error processing " + request.getMethod() + " request for : " + request.getUri(), axisFault);
} catch (Exception e) {
handleException("Error processing " + request.getMethod() + " request for : " + request.getUri() + ". Error detail: " + e.getMessage() + ". ", e);
}
}
Aggregations