Search in sources :

Example 1 with SOAP11Factory

use of org.apache.axiom.soap.impl.dom.soap11.SOAP11Factory in project wso2-synapse by wso2.

the class JmsMessageStoreTest method testProducer.

/**
 * Testing whether jms producer is storing the message to the store
 * @throws Exception
 */
@Test
public void testProducer() throws Exception {
    JmsStore jmsStore = new JmsStore();
    Map<String, Object> parameters = new HashMap<>();
    parameters.put("java.naming.factory.initial", "org.apache.activemq.jndi.ActiveMQInitialContextFactory");
    parameters.put("java.naming.provider.url", "tcp://127.0.0.1:61616");
    jmsStore.setParameters(parameters);
    jmsStore.setName("TestJmsStore");
    SynapseConfiguration synapseConfiguration = new SynapseConfiguration();
    synapseConfiguration.addMessageStore("JMSStore", jmsStore);
    SynapseEnvironment synapseEnvironment = new Axis2SynapseEnvironment(synapseConfiguration);
    Axis2MessageContext axis2MessageContext = new Axis2MessageContext(new org.apache.axis2.context.MessageContext(), synapseConfiguration, synapseEnvironment);
    MessageContext messageContext = axis2MessageContext;
    SOAP11Factory factory = new SOAP11Factory();
    SOAPEnvelope envelope = factory.createSOAPEnvelope();
    messageContext.setEnvelope(envelope);
    jmsStore.init(synapseEnvironment);
    JmsProducer jmsProducer = (JmsProducer) jmsStore.getProducer();
    boolean response = jmsProducer.storeMessage(messageContext);
    Assert.assertTrue("Message not stored!", response);
}
Also used : HashMap(java.util.HashMap) Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) SynapseEnvironment(org.apache.synapse.core.SynapseEnvironment) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration) Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) SOAP11Factory(org.apache.axiom.soap.impl.llom.soap11.SOAP11Factory) MessageContext(org.apache.synapse.MessageContext) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext) Test(org.junit.Test)

Example 2 with SOAP11Factory

use of org.apache.axiom.soap.impl.dom.soap11.SOAP11Factory in project wso2-synapse by wso2.

the class POXUtilsTest method createSoapFaultMessage.

/**
 * Helper method to create soap fault message
 * @param code fault code
 * @param reason fault reason
 * @param detail fault detail
 * @return SOAPEnvelope containing soap fault
 */
private SOAPEnvelope createSoapFaultMessage(String code, String reason, String detail) {
    SOAP11Factory factory = new SOAP11Factory();
    SOAPEnvelope envelope = factory.createSOAPEnvelope();
    SOAPBody body = factory.createSOAPBody(envelope);
    SOAPFault fault = factory.createSOAPFault(body);
    if (code != null) {
        factory.createSOAPFaultCode(fault).setText(code);
    }
    if (reason != null) {
        factory.createSOAPFaultReason(fault).setText(reason);
    }
    if (detail != null) {
        factory.createSOAPFaultDetail(fault).setText(detail);
    }
    return envelope;
}
Also used : SOAPBody(org.apache.axiom.soap.SOAPBody) SOAP11Factory(org.apache.axiom.soap.impl.llom.soap11.SOAP11Factory) SOAPFault(org.apache.axiom.soap.SOAPFault) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope)

Example 3 with SOAP11Factory

use of org.apache.axiom.soap.impl.dom.soap11.SOAP11Factory in project wso2-synapse by wso2.

the class FailoverForwardingServiceTest method test.

/**
 * Testing whether the failover forwarding service is successfully storing
 * the message in the queue
 *
 * @throws Exception
 */
@Test
public void test() throws Exception {
    JmsStore jmsStore = new JmsStore();
    Map<String, Object> parameters = new HashMap<>();
    parameters.put("java.naming.factory.initial", "org.apache.activemq.jndi.ActiveMQInitialContextFactory");
    parameters.put("java.naming.provider.url", "tcp://127.0.0.1:61616");
    jmsStore.setParameters(parameters);
    jmsStore.setName("JMSStore");
    MessageProcessor messageProcessor = new FailoverScheduledMessageForwardingProcessor();
    Map<String, Object> parametersPro = new HashMap<>();
    parametersPro.put("message.target.store.name", jmsStore.getName());
    parametersPro.put("interval", "5000");
    messageProcessor.setName("FailoverProcessor");
    messageProcessor.setParameters(parametersPro);
    messageProcessor.setMessageStoreName("JMSStore");
    SynapseConfiguration synapseConfiguration = new SynapseConfiguration();
    ConfigurationContext cfgCtx = new ConfigurationContext(synapseConfiguration.getAxisConfiguration());
    SynapseEnvironment synapseEnvironment = new Axis2SynapseEnvironment(cfgCtx, synapseConfiguration);
    synapseConfiguration.addMessageStore("JMSStore", jmsStore);
    synapseConfiguration.addMessageProcessor("FailoverProcessor", messageProcessor);
    jmsStore.init(synapseEnvironment);
    FailoverForwardingService failoverForwardingService = new FailoverForwardingService(messageProcessor, synapseEnvironment, 5000, false);
    failoverForwardingService.init(synapseEnvironment);
    Axis2MessageContext axis2MessageContext = new Axis2MessageContext(new org.apache.axis2.context.MessageContext(), synapseConfiguration, synapseEnvironment);
    MessageContext messageContext = axis2MessageContext;
    SOAP11Factory factory = new SOAP11Factory();
    SOAPEnvelope envelope = factory.getDefaultEnvelope();
    OMElement element = AXIOMUtil.stringToOM("<name><value>Test</value></name>");
    envelope.getBody().addChild(element);
    messageContext.setEnvelope(envelope);
    Assert.assertEquals("Queue is not empty!", 0, broker.getAdminView().getTotalMessageCount());
    failoverForwardingService.dispatch(messageContext);
    Assert.assertEquals("Message not forwarded!", 1, broker.getAdminView().getTotalMessageCount());
}
Also used : ConfigurationContext(org.apache.axis2.context.ConfigurationContext) HashMap(java.util.HashMap) Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) SynapseEnvironment(org.apache.synapse.core.SynapseEnvironment) MessageProcessor(org.apache.synapse.message.processor.MessageProcessor) OMElement(org.apache.axiom.om.OMElement) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration) Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) JmsStore(org.apache.synapse.message.store.impl.jms.JmsStore) SOAP11Factory(org.apache.axiom.soap.impl.llom.soap11.SOAP11Factory) MessageContext(org.apache.synapse.MessageContext) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext) Test(org.junit.Test)

Example 4 with SOAP11Factory

use of org.apache.axiom.soap.impl.dom.soap11.SOAP11Factory in project wso2-synapse by wso2.

the class PayloadHelperTest method testSetXmlPayload.

/**
 * Testing whether xml payload is set successfully
 * @throws Exception
 */
@Test
public void testSetXmlPayload() throws Exception {
    SOAP11Factory factory = new SOAP11Factory();
    SOAPEnvelope envelope = factory.getDefaultEnvelope();
    OMElement element = AXIOMUtil.stringToOM("<name><value>Test</value></name>");
    PayloadHelper.setXMLPayload(envelope, element);
    Assert.assertEquals("Couldn't set payload!", "name", envelope.getBody().getFirstElementLocalName());
}
Also used : SOAP11Factory(org.apache.axiom.soap.impl.llom.soap11.SOAP11Factory) OMElement(org.apache.axiom.om.OMElement) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) Test(org.junit.Test)

Example 5 with SOAP11Factory

use of org.apache.axiom.soap.impl.dom.soap11.SOAP11Factory in project wso2-synapse by wso2.

the class PayloadHelperTest method testGetPayloadType.

/**
 * Testing whether the type of payload retrieved successfully
 * @throws Exception
 */
@Test
public void testGetPayloadType() throws Exception {
    SOAP11Factory factory = new SOAP11Factory();
    SOAPEnvelope envelope = factory.getDefaultEnvelope();
    OMElement element = AXIOMUtil.stringToOM("<name><value>Test</value></name>");
    envelope.getBody().addChild(element);
    int type = PayloadHelper.getPayloadType(envelope);
    Assert.assertEquals("Payload type is mismatching!", 0, type);
}
Also used : SOAP11Factory(org.apache.axiom.soap.impl.llom.soap11.SOAP11Factory) OMElement(org.apache.axiom.om.OMElement) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) Test(org.junit.Test)

Aggregations

SOAP11Factory (org.apache.axiom.soap.impl.llom.soap11.SOAP11Factory)14 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)11 AxisFault (org.apache.axis2.AxisFault)8 OMElement (org.apache.axiom.om.OMElement)7 HashMap (java.util.HashMap)4 SOAPFactory (org.apache.axiom.soap.SOAPFactory)4 Test (org.junit.Test)4 XMLStreamException (javax.xml.stream.XMLStreamException)3 Map (java.util.Map)2 DataHandler (javax.activation.DataHandler)2 DataSource (javax.activation.DataSource)2 ByteArrayDataSource (org.apache.axiom.attachments.ByteArrayDataSource)2 OMException (org.apache.axiom.om.OMException)2 EndpointReference (org.apache.axis2.addressing.EndpointReference)2 Header (org.apache.http.Header)2 MessageContext (org.apache.synapse.MessageContext)2 SynapseConfiguration (org.apache.synapse.config.SynapseConfiguration)2 SynapseEnvironment (org.apache.synapse.core.SynapseEnvironment)2 Axis2MessageContext (org.apache.synapse.core.axis2.Axis2MessageContext)2 Axis2SynapseEnvironment (org.apache.synapse.core.axis2.Axis2SynapseEnvironment)2