Search in sources :

Example 1 with ServerContextInformation

use of org.apache.synapse.ServerContextInformation in project wso2-synapse by wso2.

the class SynapseCommodityServiceTest method setUp.

protected void setUp() throws java.lang.Exception {
    ServerConfigurationInformation information = new ServerConfigurationInformation();
    information.setCreateNewInstance(false);
    information.setSynapseHome(".");
    // Initializing Synapse repository
    information.setSynapseXMLLocation("./../../repository/conf/sample/resources/misc/synapse.xml");
    information.setAxis2Xml("./../../repository/conf/axis2.xml");
    findAndReplace(new File("./../../repository/conf/axis2_pt_server.xml"), new File("./target/test_repos/axis2.xml"), "lib/", "./../../modules/distribution/src/main/conf/");
    findAndReplace(new File("./../../repository/conf/axis2_be_server.xml"), new File("./target/test_repos/axis2_be_server.xml"), "lib/", "./../../modules/distribution/src/main/conf/");
    System.setProperty("jmx.agent.name", "synapse");
    ConfigurationContext synapseConfigCtx = ConfigurationContextFactory.createConfigurationContextFromFileSystem("./target/test_repos/synapse", "./target/test_repos/axis2.xml");
    TransportInDescription synTrsIn = synapseConfigCtx.getAxisConfiguration().getTransportsIn().get("http");
    synTrsIn.getParameter("port").setValue("10100");
    synTrsIn = synapseConfigCtx.getAxisConfiguration().getTransportsIn().get("https");
    synTrsIn.getParameter("port").setValue("12100");
    startServer(synapseConfigCtx);
    ServerContextInformation contextInformation = new ServerContextInformation(synapseConfigCtx, information);
    ServerManager serverManager = new ServerManager();
    serverManager.init(information, contextInformation);
    serverManager.start();
    // Initializing Business Endpoint
    // Set a different agent name to avoid collisions between the MBeans registered
    // by the two servers.
    System.setProperty("jmx.agent.name", "business");
    ConfigurationContext businessConfigCtx = ConfigurationContextFactory.createConfigurationContextFromFileSystem("./target/test_repos/synapse", "./target/test_repos/axis2_be_server.xml");
    HashMap messageReciverMap = new HashMap();
    Class inOnlyMessageReceiver = org.apache.axis2.util.Loader.loadClass("org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver");
    org.apache.axis2.engine.MessageReceiver messageReceiver = (org.apache.axis2.engine.MessageReceiver) inOnlyMessageReceiver.newInstance();
    messageReciverMap.put(org.apache.axis2.description.WSDL2Constants.MEP_URI_IN_ONLY, messageReceiver);
    Class inoutMessageReceiver = org.apache.axis2.util.Loader.loadClass("org.apache.axis2.rpc.receivers.RPCMessageReceiver");
    MessageReceiver inOutmessageReceiver = (MessageReceiver) inoutMessageReceiver.newInstance();
    messageReciverMap.put(org.apache.axis2.description.WSDL2Constants.MEP_URI_IN_OUT, inOutmessageReceiver);
    messageReciverMap.put(org.apache.axis2.description.WSDL2Constants.MEP_URI_ROBUST_IN_ONLY, inOutmessageReceiver);
    AxisService businessService = AxisService.createService(Services.class.getName(), businessConfigCtx.getAxisConfiguration(), messageReciverMap, "http://business.org", "http://business.org", Services.class.getClassLoader());
    businessConfigCtx.getAxisConfiguration().addService(businessService);
    TransportInDescription busTrsIn = businessConfigCtx.getAxisConfiguration().getTransportsIn().get("http");
    busTrsIn.getParameter("port").setValue("10101");
    busTrsIn = businessConfigCtx.getAxisConfiguration().getTransportsIn().get("https");
    busTrsIn.getParameter("port").setValue("12101");
    startServer(businessConfigCtx);
}
Also used : ServerManager(org.apache.synapse.ServerManager) ConfigurationContext(org.apache.axis2.context.ConfigurationContext) MessageReceiver(org.apache.axis2.engine.MessageReceiver) HashMap(java.util.HashMap) AxisService(org.apache.axis2.description.AxisService) ServerConfigurationInformation(org.apache.synapse.ServerConfigurationInformation) TransportInDescription(org.apache.axis2.description.TransportInDescription) Services(org.apache.synapse.util.Services) ServerContextInformation(org.apache.synapse.ServerContextInformation) MessageReceiver(org.apache.axis2.engine.MessageReceiver)

Example 2 with ServerContextInformation

use of org.apache.synapse.ServerContextInformation 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 3 with ServerContextInformation

use of org.apache.synapse.ServerContextInformation in project wso2-synapse by wso2.

the class AnonymousServiceFactory method getCallbackReceiver.

/**
 * Create a single callback receiver if required, and return its reference
 * @param synCfg the Synapse configuration
 * @param axisCfg axis configuration
 * @return the callback receiver thats created or now exists
 */
private static synchronized SynapseCallbackReceiver getCallbackReceiver(SynapseConfiguration synCfg, AxisConfiguration axisCfg) {
    if (synapseCallbackReceiver == null) {
        Parameter serverCtxParam = axisCfg.getParameter(SynapseConstants.SYNAPSE_SERVER_CTX_INFO);
        if (serverCtxParam == null || !(serverCtxParam.getValue() instanceof ServerContextInformation)) {
            String msg = "ServerContextInformation not found";
            log.error(msg);
            throw new SynapseException(msg);
        }
        ServerContextInformation contextInformation = (ServerContextInformation) serverCtxParam.getValue();
        synapseCallbackReceiver = new SynapseCallbackReceiver(synCfg, contextInformation);
        contextInformation.setSynapseCallbackReceiver(synapseCallbackReceiver);
    }
    return synapseCallbackReceiver;
}
Also used : ServerContextInformation(org.apache.synapse.ServerContextInformation) SynapseException(org.apache.synapse.SynapseException)

Example 4 with ServerContextInformation

use of org.apache.synapse.ServerContextInformation in project wso2-synapse by wso2.

the class ProxyServiceTest method testBuildAxisServiceWithPinnedServers.

/**
 * Configures pinned servers for the proxy server and asserts if the proxy gets built correctly with and without
 * correct pinned servers.
 *
 * @throws Exception is an error occurs while adding the synapse environment to the axis configuration
 */
public void testBuildAxisServiceWithPinnedServers() throws Exception {
    String pinnedServer = "localhost";
    SynapseConfiguration synCfg = new SynapseConfiguration();
    AxisConfiguration axisCfg = new AxisConfiguration();
    ServerConfigurationInformation serverConfigurationInformation = Mockito.mock(ServerConfigurationInformation.class);
    ServerContextInformation serverContextInformation = new ServerContextInformation(serverConfigurationInformation);
    SynapseEnvironment synEnv = new Axis2SynapseEnvironment(new ConfigurationContext(axisCfg), synCfg, serverContextInformation);
    axisCfg.addParameter(SynapseConstants.SYNAPSE_ENV, synEnv);
    ProxyService proxyService = new ProxyService("testBuildAxisServiceWithPinnedServersProxy");
    List<String> pinnedServersList = new ArrayList<>();
    pinnedServersList.add(pinnedServer);
    proxyService.setPinnedServers(pinnedServersList);
    // Tests with incorrect pinned servers
    Mockito.when(synEnv.getServerContextInformation().getServerConfigurationInformation().getServerName()).thenReturn("10.10.10.1");
    AxisService axisService = proxyService.buildAxisService(synCfg, axisCfg);
    Assert.assertNull("Axis service built with incorrect pinned servers should be null", axisService);
    // Asserts with correct pinned servers
    Mockito.when(synEnv.getServerContextInformation().getServerConfigurationInformation().getServerName()).thenReturn(pinnedServer);
    Assert.assertNotNull("Axis service should be built with correct pinned servers", proxyService.buildAxisService(synCfg, axisCfg));
}
Also used : AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) ConfigurationContext(org.apache.axis2.context.ConfigurationContext) ServerContextInformation(org.apache.synapse.ServerContextInformation) SynapseEnvironment(org.apache.synapse.core.SynapseEnvironment) AxisService(org.apache.axis2.description.AxisService) ArrayList(java.util.ArrayList) ServerConfigurationInformation(org.apache.synapse.ServerConfigurationInformation) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration)

Aggregations

ServerContextInformation (org.apache.synapse.ServerContextInformation)4 ServerConfigurationInformation (org.apache.synapse.ServerConfigurationInformation)3 HashMap (java.util.HashMap)2 ConfigurationContext (org.apache.axis2.context.ConfigurationContext)2 AxisService (org.apache.axis2.description.AxisService)2 SynapseException (org.apache.synapse.SynapseException)2 SynapseEnvironment (org.apache.synapse.core.SynapseEnvironment)2 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 TransportInDescription (org.apache.axis2.description.TransportInDescription)1 AxisConfiguration (org.apache.axis2.engine.AxisConfiguration)1 MessageReceiver (org.apache.axis2.engine.MessageReceiver)1 ServerManager (org.apache.synapse.ServerManager)1 EnterpriseBeanstalk (org.apache.synapse.commons.beanstalk.enterprise.EnterpriseBeanstalk)1 EnterpriseBeanstalkManager (org.apache.synapse.commons.beanstalk.enterprise.EnterpriseBeanstalkManager)1 Entry (org.apache.synapse.config.Entry)1 SynapseConfiguration (org.apache.synapse.config.SynapseConfiguration)1 Axis2MessageContext (org.apache.synapse.core.axis2.Axis2MessageContext)1 Value (org.apache.synapse.mediators.Value)1 Services (org.apache.synapse.util.Services)1