use of org.apache.axiom.soap.SOAPEnvelope in project wso2-axis2-transports by wso2.
the class PlainTextFormatterTest method createElementMessageContextElement.
private MessageContext createElementMessageContextElement(String textPayload) throws AxisFault {
try {
MessageContext messageContext = new MessageContext();
SOAPFactory factory = OMAbstractFactory.getSOAP11Factory();
SOAPEnvelope envelope = factory.getDefaultEnvelope();
OMElement textWrapper = factory.createOMElement(BaseConstants.DEFAULT_TEXT_WRAPPER);
OMElement payload = AXIOMUtil.stringToOM(textPayload);
textWrapper.addChild(payload);
envelope.getBody().addChild(textWrapper);
messageContext.setEnvelope(envelope);
return messageContext;
} catch (XMLStreamException e) {
// This is highly unlikely to happen
return null;
}
}
use of org.apache.axiom.soap.SOAPEnvelope in project wso2-axis2-transports by wso2.
the class XMLMessage method getMessageElement.
public OMElement getMessageElement() {
if (type == Type.POX) {
return payload;
} else {
SOAPFactory factory;
if (type == Type.SOAP11) {
factory = OMAbstractFactory.getSOAP11Factory();
} else {
factory = OMAbstractFactory.getSOAP12Factory();
}
SOAPEnvelope envelope = factory.getDefaultEnvelope();
envelope.getBody().addChild(payload);
return envelope;
}
}
use of org.apache.axiom.soap.SOAPEnvelope in project wso2-axis2-transports by wso2.
the class MinConcurrencyTest method runTest.
@Override
protected void runTest() throws Throwable {
int endpointCount = channels.length;
int expectedConcurrency = endpointCount * messages;
final MessageReceiver messageReceiver = new MessageReceiver() {
public void receive(MessageContext msgContext) throws AxisFault {
synchronized (concurrencyReachedLock) {
concurrencyReached++;
concurrencyReachedLock.notifyAll();
}
try {
synchronized (shutdownAwaitLock) {
shutdownAwaitLock.wait();
}
} catch (InterruptedException ex) {
}
}
};
TestResourceSet[] clientResourceSets = new TestResourceSet[endpointCount];
TestResourceSet[] endpointResourceSets = new TestResourceSet[endpointCount];
try {
for (int i = 0; i < endpointCount; i++) {
TestResourceSet clientResourceSet = new TestResourceSet(getResourceSet());
AsyncChannel channel = channels[i];
clientResourceSet.addResource(channel);
AxisAsyncTestClient client = new AxisAsyncTestClient(false);
clientResourceSet.addResource(client);
clientResourceSet.setUp();
clientResourceSets[i] = clientResourceSet;
TestResourceSet endpointResourceSet = new TestResourceSet(clientResourceSet);
endpointResourceSet.addResource(new AxisTestEndpoint() {
@Override
protected AxisOperation createOperation() {
AxisOperation operation = new InOnlyAxisOperation(new QName("in"));
operation.setMessageReceiver(messageReceiver);
return operation;
}
@Override
protected void onTransportError(Throwable ex) {
// TODO Auto-generated method stub
}
});
if (!preloadMessages) {
endpointResourceSet.setUp();
endpointResourceSets[i] = endpointResourceSet;
}
for (int j = 0; j < messages; j++) {
ClientOptions options = new ClientOptions(client, new ContentType(SOAP11Constants.SOAP_11_CONTENT_TYPE), "UTF-8");
AxisMessage message = new AxisMessage();
message.setMessageType(SOAP11Constants.SOAP_11_CONTENT_TYPE);
SOAPFactory factory = OMAbstractFactory.getSOAP11Factory();
SOAPEnvelope envelope = factory.getDefaultEnvelope();
message.setEnvelope(envelope);
client.sendMessage(options, new ContentType(message.getMessageType()), message);
}
if (preloadMessages) {
endpointResourceSet.setUp();
endpointResourceSets[i] = endpointResourceSet;
}
}
long startTime = System.currentTimeMillis();
while (concurrencyReached < expectedConcurrency && System.currentTimeMillis() < (startTime + 5000)) {
synchronized (concurrencyReachedLock) {
concurrencyReachedLock.wait(5000);
}
}
synchronized (shutdownAwaitLock) {
shutdownAwaitLock.notifyAll();
}
if (concurrencyReached < expectedConcurrency) {
fail("Concurrency reached is " + concurrencyReached + ", but expected " + expectedConcurrency);
}
} finally {
for (int i = 0; i < endpointCount; i++) {
if (endpointResourceSets[i] != null) {
endpointResourceSets[i].tearDown();
}
if (clientResourceSets[i] != null) {
clientResourceSets[i].tearDown();
}
}
}
}
use of org.apache.axiom.soap.SOAPEnvelope in project wso2-axis2-transports by wso2.
the class XMPPPacketListener method buildSOAPEnvelope.
/**
* builds SOAP envelop using message contained in packet
* @param packet
* @param msgContext
* @throws AxisFault
*/
private void buildSOAPEnvelope(Packet packet, MessageContext msgContext) throws AxisFault {
Message message = (Message) packet;
String logMsg = "Trying to create " + "message content using XMPP message received :" + packet.toXML();
String messageBody = StringEscapeUtils.unescapeXml(message.getBody());
if (msgContext.isServerSide()) {
log.debug("Received Envelope : " + messageBody);
}
InputStream inputStream = new ByteArrayInputStream(messageBody.getBytes());
SOAPEnvelope envelope = null;
try {
Object obj = message.getProperty(XMPPConstants.CONTAINS_SOAP_ENVELOPE);
if (obj != null && ((Boolean) obj).booleanValue()) {
String contentType = (String) message.getProperty(XMPPConstants.CONTENT_TYPE);
if (contentType == null) {
throw new AxisFault("Can not Find Content type Property in the XMPP Message");
}
envelope = TransportUtils.createSOAPMessage(msgContext, inputStream, contentType);
msgContext.setProperty(XMPPConstants.CONTAINS_SOAP_ENVELOPE, new Boolean(true));
} else {
// This message could either be a service call or a help command
if (!(messageContainsCommandsFromChat(messageBody, msgContext))) {
envelope = createSOAPEnvelopeForRawMessage(msgContext, messageBody);
}
}
if (envelope != null) {
msgContext.setEnvelope(envelope);
}
} catch (OMException e) {
log.error(logMsg, e);
throw new AxisFault(logMsg);
} catch (XMLStreamException e) {
log.error(logMsg, e);
throw new AxisFault(logMsg);
} catch (FactoryConfigurationError e) {
log.error(logMsg, e);
throw new AxisFault(logMsg);
} catch (AxisFault e) {
log.error(logMsg, e);
throw new AxisFault(logMsg);
}
}
use of org.apache.axiom.soap.SOAPEnvelope in project wso2-axis2-transports by wso2.
the class ProcessPacketTask method run.
public void run() {
MetricsCollector metrics = endpoint.getMetrics();
try {
InputStream inputStream = new ByteArrayInputStream(data, 0, length);
MessageContext msgContext = endpoint.createMessageContext();
SOAPEnvelope envelope = TransportUtils.createSOAPMessage(msgContext, inputStream, endpoint.getContentType());
msgContext.setEnvelope(envelope);
if (outInfo != null) {
if (outInfo.getContentType() == null) {
outInfo.setContentType(endpoint.getContentType());
}
msgContext.setProperty(Constants.OUT_TRANSPORT_INFO, outInfo);
}
AxisEngine.receive(msgContext);
metrics.incrementMessagesReceived();
metrics.incrementBytesReceived(length);
} catch (Exception ex) {
metrics.incrementFaultsReceiving();
StringBuilder buffer = new StringBuilder("Error during processing of datagram:\n");
Utils.hexDump(buffer, data, length);
log.error(buffer.toString(), ex);
}
}
Aggregations