Search in sources :

Example 96 with SOAPEnvelope

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;
    }
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) OMElement(org.apache.axiom.om.OMElement) MessageContext(org.apache.axis2.context.MessageContext) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) SOAPFactory(org.apache.axiom.soap.SOAPFactory)

Example 97 with SOAPEnvelope

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;
    }
}
Also used : SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) SOAPFactory(org.apache.axiom.soap.SOAPFactory)

Example 98 with SOAPEnvelope

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();
            }
        }
    }
}
Also used : ClientOptions(org.apache.axis2.transport.testkit.client.ClientOptions) InOnlyAxisOperation(org.apache.axis2.description.InOnlyAxisOperation) AxisOperation(org.apache.axis2.description.AxisOperation) ContentType(javax.mail.internet.ContentType) QName(javax.xml.namespace.QName) AsyncChannel(org.apache.axis2.transport.testkit.channel.AsyncChannel) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) AxisTestEndpoint(org.apache.axis2.transport.testkit.axis2.endpoint.AxisTestEndpoint) SOAPFactory(org.apache.axiom.soap.SOAPFactory) InOnlyAxisOperation(org.apache.axis2.description.InOnlyAxisOperation) MessageReceiver(org.apache.axis2.engine.MessageReceiver) AxisTestEndpoint(org.apache.axis2.transport.testkit.axis2.endpoint.AxisTestEndpoint) AxisAsyncTestClient(org.apache.axis2.transport.testkit.axis2.client.AxisAsyncTestClient) MessageContext(org.apache.axis2.context.MessageContext) TestResourceSet(org.apache.axis2.transport.testkit.tests.TestResourceSet) AxisMessage(org.apache.axis2.transport.testkit.message.AxisMessage)

Example 99 with SOAPEnvelope

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);
    }
}
Also used : AxisFault(org.apache.axis2.AxisFault) Message(org.jivesoftware.smack.packet.Message) XMLStreamException(javax.xml.stream.XMLStreamException) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) OMException(org.apache.axiom.om.OMException) FactoryConfigurationError(javax.xml.parsers.FactoryConfigurationError)

Example 100 with SOAPEnvelope

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);
    }
}
Also used : MetricsCollector(org.apache.axis2.transport.base.MetricsCollector) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) MessageContext(org.apache.axis2.context.MessageContext) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope)

Aggregations

SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)105 OMElement (org.apache.axiom.om.OMElement)32 SOAPBody (org.apache.axiom.soap.SOAPBody)24 OMNamespace (org.apache.axiom.om.OMNamespace)22 SOAPHeader (org.apache.axiom.soap.SOAPHeader)20 SOAPFactory (org.apache.axiom.soap.SOAPFactory)18 QName (javax.xml.namespace.QName)16 SOAPFault (org.apache.axiom.soap.SOAPFault)14 ByteArrayInputStream (java.io.ByteArrayInputStream)12 SOAPHeaderBlock (org.apache.axiom.soap.SOAPHeaderBlock)12 OMNode (org.apache.axiom.om.OMNode)11 SOAPModelBuilder (org.apache.axiom.soap.SOAPModelBuilder)11 MessageContext (org.apache.axis2.context.MessageContext)10 SOAPFaultCode (org.apache.axiom.soap.SOAPFaultCode)8 InputStream (java.io.InputStream)7 XMLStreamException (javax.xml.stream.XMLStreamException)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 StringReader (java.io.StringReader)6 DataHandler (javax.activation.DataHandler)6 OMException (org.apache.axiom.om.OMException)6