Search in sources :

Example 31 with SynapseEnvironment

use of org.apache.synapse.core.SynapseEnvironment in project wso2-synapse by wso2.

the class TestUtils method createLightweightSynapseMessageContext.

public static MessageContext createLightweightSynapseMessageContext(String payload, SynapseConfiguration config) throws Exception {
    org.apache.axis2.context.MessageContext mc = new org.apache.axis2.context.MessageContext();
    SynapseEnvironment env = new Axis2SynapseEnvironment(config);
    MessageContext synMc = new Axis2MessageContext(mc, config, env);
    SOAPEnvelope envelope = OMAbstractFactory.getSOAP11Factory().getDefaultEnvelope();
    OMDocument omDoc = OMAbstractFactory.getSOAP11Factory().createOMDocument();
    omDoc.addChild(envelope);
    envelope.getBody().addChild(createOMElement(payload));
    synMc.setEnvelope(envelope);
    return synMc;
}
Also used : Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) SynapseEnvironment(org.apache.synapse.core.SynapseEnvironment) MessageContext(org.apache.synapse.MessageContext) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext) OMDocument(org.apache.axiom.om.OMDocument)

Example 32 with SynapseEnvironment

use of org.apache.synapse.core.SynapseEnvironment in project wso2-synapse by wso2.

the class EJBMediatorTest method testInitAndMediate.

/**
 * Initializing EJBMediator and Mediating a messageContext
 */
@Test
public void testInitAndMediate() throws Exception {
    SynapseEnvironment synapseEnvironment = Mockito.mock(SynapseEnvironment.class);
    ServerConfigurationInformation configurationInformation = new ServerConfigurationInformation();
    ServerContextInformation contextInformation = new ServerContextInformation(configurationInformation);
    Mockito.when(synapseEnvironment.getServerContextInformation()).thenReturn(contextInformation);
    try {
        ejbMediator.init(synapseEnvironment);
        Assert.fail("executed successfully when exception is expected");
    } catch (Exception ex) {
        Assert.assertEquals("assert exception class", SynapseException.class, ex.getClass());
        Assert.assertEquals("assert exception message", "Initialization failed. BeanstalkManager not found.", ex.getMessage());
    }
    ejbMediator.setBeanstalkName(BEANSTALK_NAME);
    EnterpriseBeanstalkManager beanstalkManager = Mockito.mock(EnterpriseBeanstalkManager.class);
    contextInformation.addProperty(EnterpriseBeanstalkConstants.BEANSTALK_MANAGER_PROP_NAME, beanstalkManager);
    try {
        ejbMediator.init(synapseEnvironment);
        Assert.fail("executed successfully when exception is expected");
    } catch (Exception ex) {
        Assert.assertEquals("assert exception class", SynapseException.class, ex.getClass());
        Assert.assertEquals("assert exception message", "Initialization failed. '" + BEANSTALK_NAME + "' " + "beanstalk not found.", ex.getMessage());
    }
    beanstalk = PowerMockito.mock(EnterpriseBeanstalk.class);
    Value beanId = new Value(VALUE);
    ejbMediator.setBeanId(beanId);
    Object obj = new Object();
    PowerMockito.when(beanstalk.getEnterpriseBean(any(String.class), any(String.class), any(String.class))).thenReturn(obj);
    PowerMockito.when(beanstalkManager.getBeanstalk(BEANSTALK_NAME)).thenReturn(beanstalk);
    PowerMockito.mockStatic(BeanUtils.class);
    PowerMockito.when(BeanUtils.invokeInstanceMethod(any(Object.class), any(Method.class), any(Object[].class))).thenReturn(new Object());
    ejbMediator.init(synapseEnvironment);
    String samplePayload = "<test>value</test>";
    Map<String, Entry> properties = new HashMap<>();
    Axis2MessageContext messageContext = TestUtils.getAxis2MessageContext(samplePayload, properties);
    ejbMediator.setClassName(CLASS_NAME);
    ejbMediator.setJndiName(JNDI_NAME);
    Assert.assertTrue("mediation must be successful", ejbMediator.mediate(messageContext));
}
Also used : SynapseException(org.apache.synapse.SynapseException) HashMap(java.util.HashMap) SynapseEnvironment(org.apache.synapse.core.SynapseEnvironment) EnterpriseBeanstalkManager(org.apache.synapse.commons.beanstalk.enterprise.EnterpriseBeanstalkManager) ServerConfigurationInformation(org.apache.synapse.ServerConfigurationInformation) Method(java.lang.reflect.Method) ExpectedException(org.junit.rules.ExpectedException) SynapseException(org.apache.synapse.SynapseException) EnterpriseBeanstalk(org.apache.synapse.commons.beanstalk.enterprise.EnterpriseBeanstalk) Entry(org.apache.synapse.config.Entry) ServerContextInformation(org.apache.synapse.ServerContextInformation) Value(org.apache.synapse.mediators.Value) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 33 with SynapseEnvironment

use of org.apache.synapse.core.SynapseEnvironment in project wso2-synapse by wso2.

the class XpathExtensionUtil method resolveVariableContext.

/**
 * Returns an object resolved by Variable Context extension registered for given
 * QName/namespaceURI+prefix+localName combination
 *
 * @param ctxt         Synapse Message Context
 * @param namespaceURI binding namespace in xpath expression
 * @param prefix       binding prefix string in xpath expression
 * @param localName    binding localname string in xpath expression
 * @return Object variable resolved by corresponding extension
 */
public static Object resolveVariableContext(MessageContext ctxt, String namespaceURI, String prefix, String localName) {
    SynapseEnvironment environment = ctxt.getEnvironment();
    if (environment != null) {
        Map<QName, SynapseXpathVariableResolver> extensions = environment.getXpathVariableExtensions();
        SynapseXpathVariableResolver variableResolver = getMatchingExtensionProvider(extensions, namespaceURI, prefix, localName);
        if (variableResolver != null) {
            return resolveXpathVariable(variableResolver, ctxt);
        }
    }
    return null;
}
Also used : SynapseEnvironment(org.apache.synapse.core.SynapseEnvironment) QName(javax.xml.namespace.QName)

Example 34 with SynapseEnvironment

use of org.apache.synapse.core.SynapseEnvironment in project wso2-synapse by wso2.

the class HessianMessageBuilderTest method testProcessDocumentWithSynEnv.

public void testProcessDocumentWithSynEnv() throws IOException {
    SynapseEnvironment synEnv = new Axis2SynapseEnvironment(new ConfigurationContext(new AxisConfiguration()), new SynapseConfiguration());
    testProcessDocument(synEnv);
}
Also used : Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) ConfigurationContext(org.apache.axis2.context.ConfigurationContext) AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) SynapseEnvironment(org.apache.synapse.core.SynapseEnvironment) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration)

Example 35 with SynapseEnvironment

use of org.apache.synapse.core.SynapseEnvironment in project wso2-synapse by wso2.

the class HessianMessageBuilderTest method testProcessDocumentFaultWithSynEnv.

public void testProcessDocumentFaultWithSynEnv() throws IOException {
    SynapseEnvironment synEnv = new Axis2SynapseEnvironment(new ConfigurationContext(new AxisConfiguration()), new SynapseConfiguration());
    testProcessDocumentFault(synEnv);
}
Also used : Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) ConfigurationContext(org.apache.axis2.context.ConfigurationContext) AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) SynapseEnvironment(org.apache.synapse.core.SynapseEnvironment) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration)

Aggregations

SynapseEnvironment (org.apache.synapse.core.SynapseEnvironment)67 Axis2SynapseEnvironment (org.apache.synapse.core.axis2.Axis2SynapseEnvironment)50 SynapseConfiguration (org.apache.synapse.config.SynapseConfiguration)49 AxisConfiguration (org.apache.axis2.engine.AxisConfiguration)44 ConfigurationContext (org.apache.axis2.context.ConfigurationContext)43 Test (org.junit.Test)40 OMElement (org.apache.axiom.om.OMElement)35 Parameter (org.apache.axis2.description.Parameter)29 MessageContext (org.apache.synapse.MessageContext)18 Axis2MessageContext (org.apache.synapse.core.axis2.Axis2MessageContext)18 ArrayList (java.util.ArrayList)8 AddressEndpoint (org.apache.synapse.endpoints.AddressEndpoint)8 Endpoint (org.apache.synapse.endpoints.Endpoint)8 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)6 HashMap (java.util.HashMap)5 OMDocument (org.apache.axiom.om.OMDocument)4 SynapseException (org.apache.synapse.SynapseException)4 TestMessageContext (org.apache.synapse.TestMessageContext)4 IOException (java.io.IOException)3 ManagedLifecycle (org.apache.synapse.ManagedLifecycle)3