Search in sources :

Example 36 with ConfigurationContext

use of org.apache.axis2.context.ConfigurationContext in project wso2-synapse by wso2.

the class ProxyServiceDeployerTest method testDeploy.

/**
 * Testing the deployment of a proxy service
 *
 * @throws Exception
 */
@Test
public void testDeploy() throws Exception {
    String inputXML = "<proxy xmlns=\"http://ws.apache.org/ns/synapse\" name=\"TestProxy\">" + "        <target>" + "            <endpoint>" + "                <address uri=\"http://localhost:9000/services/SimpleStockQuoteService\"/>" + "            </endpoint>" + "            <outSequence>" + "                <send/>" + "            </outSequence>" + "        </target>" + "    </proxy>";
    OMElement inputElement = AXIOMUtil.stringToOM(inputXML);
    ProxyServiceDeployer proxyServiceDeployer = new ProxyServiceDeployer();
    SynapseConfiguration synapseConfiguration = new SynapseConfiguration();
    AxisConfiguration axisConfiguration = synapseConfiguration.getAxisConfiguration();
    ConfigurationContext cfgCtx = new ConfigurationContext(axisConfiguration);
    SynapseEnvironment synapseEnvironment = new Axis2SynapseEnvironment(cfgCtx, synapseConfiguration);
    axisConfiguration.addParameter(new Parameter(SynapseConstants.SYNAPSE_ENV, synapseEnvironment));
    axisConfiguration.addParameter(new Parameter(SynapseConstants.SYNAPSE_CONFIG, synapseConfiguration));
    cfgCtx.setAxisConfiguration(axisConfiguration);
    proxyServiceDeployer.init(cfgCtx);
    String response = proxyServiceDeployer.deploySynapseArtifact(inputElement, "sampleFile", new Properties());
    Assert.assertEquals("Proxy service not deployed!", "TestProxy", response);
}
Also used : AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) ConfigurationContext(org.apache.axis2.context.ConfigurationContext) Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) SynapseEnvironment(org.apache.synapse.core.SynapseEnvironment) Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) Parameter(org.apache.axis2.description.Parameter) OMElement(org.apache.axiom.om.OMElement) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration) Properties(java.util.Properties) Test(org.junit.Test)

Example 37 with ConfigurationContext

use of org.apache.axis2.context.ConfigurationContext in project wso2-synapse by wso2.

the class ProxyServiceDeployerTest method testUndeploy.

/**
 * Test undeploying a proxy service
 *
 * @throws Exception
 */
@Test
public void testUndeploy() throws Exception {
    String inputXML = "<proxy xmlns=\"http://ws.apache.org/ns/synapse\" name=\"TestProxy\">" + "        <target>" + "            <endpoint>" + "                <address uri=\"http://localhost:9000/services/SimpleStockQuoteService\"/>" + "            </endpoint>" + "            <outSequence>" + "                <send/>" + "            </outSequence>" + "        </target>" + "    </proxy>";
    OMElement inputElement = AXIOMUtil.stringToOM(inputXML);
    ProxyServiceDeployer proxyServiceDeployer = new ProxyServiceDeployer();
    SynapseConfiguration synapseConfiguration = new SynapseConfiguration();
    AxisConfiguration axisConfiguration = synapseConfiguration.getAxisConfiguration();
    ConfigurationContext cfgCtx = new ConfigurationContext(axisConfiguration);
    SynapseEnvironment synapseEnvironment = new Axis2SynapseEnvironment(cfgCtx, synapseConfiguration);
    axisConfiguration.addParameter(new Parameter(SynapseConstants.SYNAPSE_ENV, synapseEnvironment));
    axisConfiguration.addParameter(new Parameter(SynapseConstants.SYNAPSE_CONFIG, synapseConfiguration));
    cfgCtx.setAxisConfiguration(axisConfiguration);
    proxyServiceDeployer.init(cfgCtx);
    proxyServiceDeployer.deploySynapseArtifact(inputElement, "sampleFile", new Properties());
    Assert.assertNotNull("Proxy not deployed!", synapseConfiguration.getProxyService("TestProxy"));
    proxyServiceDeployer.undeploySynapseArtifact("TestProxy");
    Assert.assertNull("Proxy service cannot be undeployed", synapseConfiguration.getProxyService("TestProxy"));
}
Also used : AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) ConfigurationContext(org.apache.axis2.context.ConfigurationContext) Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) SynapseEnvironment(org.apache.synapse.core.SynapseEnvironment) Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) Parameter(org.apache.axis2.description.Parameter) OMElement(org.apache.axiom.om.OMElement) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration) Properties(java.util.Properties) Test(org.junit.Test)

Example 38 with ConfigurationContext

use of org.apache.axis2.context.ConfigurationContext in project wso2-synapse by wso2.

the class DynamicLoadBalanceEndpointTest method createMessageContext.

/**
 * Create a empty message context
 *
 * @return A context with empty message
 * @throws AxisFault on an error creating a context
 */
private MessageContext createMessageContext() throws AxisFault {
    Axis2SynapseEnvironment synapseEnvironment = new Axis2SynapseEnvironment(new SynapseConfiguration());
    org.apache.axis2.context.MessageContext axis2MC = new org.apache.axis2.context.MessageContext();
    axis2MC.setConfigurationContext(new ConfigurationContext(new AxisConfiguration()));
    ServiceContext svcCtx = new ServiceContext();
    OperationContext opCtx = new OperationContext(new InOutAxisOperation(), svcCtx);
    axis2MC.setServiceContext(svcCtx);
    axis2MC.setOperationContext(opCtx);
    axis2MC.setTransportIn(new TransportInDescription("http"));
    axis2MC.setTo(new EndpointReference("http://localhost:9000/services/SimpleStockQuoteService"));
    MessageContext mc = new Axis2MessageContext(axis2MC, new SynapseConfiguration(), synapseEnvironment);
    mc.setMessageID(UIDGenerator.generateURNString());
    mc.setEnvelope(OMAbstractFactory.getSOAP12Factory().createSOAPEnvelope());
    mc.getEnvelope().addChild(OMAbstractFactory.getSOAP12Factory().createSOAPBody());
    return mc;
}
Also used : OperationContext(org.apache.axis2.context.OperationContext) ConfigurationContext(org.apache.axis2.context.ConfigurationContext) AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) ServiceContext(org.apache.axis2.context.ServiceContext) TransportInDescription(org.apache.axis2.description.TransportInDescription) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration) EndpointReference(org.apache.axis2.addressing.EndpointReference) Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) MessageContext(org.apache.synapse.MessageContext) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext) InOutAxisOperation(org.apache.axis2.description.InOutAxisOperation) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext)

Example 39 with ConfigurationContext

use of org.apache.axis2.context.ConfigurationContext in project wso2-synapse by wso2.

the class DynamicLoadBalanceEndpointTest method getMockedSynapseEnvironment.

/**
 * Create a mock SynapseEnvironment object
 *
 * @return Axis2SynapseEnvironment instance
 * @throws AxisFault on creating/mocking object
 */
private Axis2SynapseEnvironment getMockedSynapseEnvironment() throws AxisFault {
    Axis2SynapseEnvironment synapseEnvironment = PowerMockito.mock(Axis2SynapseEnvironment.class);
    ConfigurationContext axis2ConfigurationContext = new ConfigurationContext(new AxisConfiguration());
    axis2ConfigurationContext.getAxisConfiguration().addParameter(SynapseConstants.SYNAPSE_ENV, synapseEnvironment);
    Mockito.when(synapseEnvironment.getAxis2ConfigurationContext()).thenReturn(axis2ConfigurationContext);
    return synapseEnvironment;
}
Also used : Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) ConfigurationContext(org.apache.axis2.context.ConfigurationContext) AxisConfiguration(org.apache.axis2.engine.AxisConfiguration)

Example 40 with ConfigurationContext

use of org.apache.axis2.context.ConfigurationContext in project wso2-synapse by wso2.

the class ProxyServiceTest method testRegisterFaultHandler.

/**
 * Tests if the correct fault handler is set when a fault handler is not explicitly set, and when set by using
 * targetFaultSequence and targetInlineFaultSequence properties of the proxy.
 */
public void testRegisterFaultHandler() {
    ProxyService proxyService = new ProxyService("TestRegisterFaultHandlerProxy");
    MessageContext messageContext = new TestMessageContext();
    SynapseConfiguration synCfg = new SynapseConfiguration();
    messageContext.setConfiguration(synCfg);
    SequenceMediator faultMediator = new SequenceMediator();
    synCfg.addSequence("fault", faultMediator);
    // test if the default fault proxy set in the message context is returned when a fault sequence is not
    // explicitly set
    faultMediator.setName("defaultFault");
    proxyService.registerFaultHandler(messageContext);
    String faultMediatorName = ((SequenceMediator) ((MediatorFaultHandler) messageContext.getFaultStack().pop()).getFaultMediator()).getName();
    Assert.assertEquals("Incorrect fault handler set: " + faultMediatorName, "defaultFault", faultMediatorName);
    // tests the functionality when the fault sequence is set in line in the target
    faultMediator.setName("targetInLineFaultSequenceMediator");
    proxyService.setTargetInLineFaultSequence(faultMediator);
    proxyService.registerFaultHandler(messageContext);
    faultMediatorName = ((SequenceMediator) ((MediatorFaultHandler) messageContext.getFaultStack().pop()).getFaultMediator()).getName();
    Assert.assertEquals("Incorrect fault handler set: " + faultMediatorName, "targetInLineFaultSequenceMediator", faultMediatorName);
    // tests the functionality when the fault sequence is set separately in the target
    AxisConfiguration axisCfg = new AxisConfiguration();
    SynapseEnvironment synEnv = new Axis2SynapseEnvironment(new ConfigurationContext(axisCfg), synCfg);
    messageContext.setEnvironment(synEnv);
    proxyService.setTargetFaultSequence("targetFaultSequence");
    // when the message context does not have the correct fault sequence specified as the target fault sequence
    faultMediator.setName("defaultFaultMediator");
    proxyService.registerFaultHandler(messageContext);
    faultMediatorName = ((SequenceMediator) ((MediatorFaultHandler) messageContext.getFaultStack().pop()).getFaultMediator()).getName();
    Assert.assertEquals("Incorrect fault handler set: " + faultMediatorName, "defaultFaultMediator", faultMediatorName);
    // when the message context has the correct fault sequence specified as the target fault sequence
    faultMediator.setName("targetFaultSequenceMediator");
    synCfg.addSequence("targetFaultSequence", faultMediator);
    proxyService.registerFaultHandler(messageContext);
    faultMediatorName = ((SequenceMediator) ((MediatorFaultHandler) messageContext.getFaultStack().pop()).getFaultMediator()).getName();
    Assert.assertEquals("Incorrect fault handler set: " + faultMediatorName, "targetFaultSequenceMediator", faultMediatorName);
}
Also used : AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) ConfigurationContext(org.apache.axis2.context.ConfigurationContext) MediatorFaultHandler(org.apache.synapse.mediators.MediatorFaultHandler) TestMessageContext(org.apache.synapse.TestMessageContext) SynapseEnvironment(org.apache.synapse.core.SynapseEnvironment) MessageContext(org.apache.synapse.MessageContext) TestMessageContext(org.apache.synapse.TestMessageContext) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration)

Aggregations

ConfigurationContext (org.apache.axis2.context.ConfigurationContext)184 AxisConfiguration (org.apache.axis2.engine.AxisConfiguration)119 Axis2SynapseEnvironment (org.apache.synapse.core.axis2.Axis2SynapseEnvironment)70 Test (org.junit.Test)64 SynapseConfiguration (org.apache.synapse.config.SynapseConfiguration)62 Parameter (org.apache.axis2.description.Parameter)56 SynapseEnvironment (org.apache.synapse.core.SynapseEnvironment)48 OMElement (org.apache.axiom.om.OMElement)43 AxisFault (org.apache.axis2.AxisFault)34 MessageContext (org.apache.synapse.MessageContext)34 Axis2MessageContext (org.apache.synapse.core.axis2.Axis2MessageContext)31 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)30 AxisService (org.apache.axis2.description.AxisService)26 EndpointReference (org.apache.axis2.addressing.EndpointReference)24 MessageContext (org.apache.axis2.context.MessageContext)23 Options (org.apache.axis2.client.Options)22 HashMap (java.util.HashMap)20 ServiceContext (org.apache.axis2.context.ServiceContext)19 Map (java.util.Map)18 TransportOutDescription (org.apache.axis2.description.TransportOutDescription)16