Search in sources :

Example 1 with ServerConfigurationInformation

use of org.apache.synapse.ServerConfigurationInformation 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 ServerConfigurationInformation

use of org.apache.synapse.ServerConfigurationInformation 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 ServerConfigurationInformation

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

the class SynapseStartUpServlet method init.

public void init() throws ServletException {
    ServletConfig servletConfig = getServletConfig();
    ServletContext servletContext = servletConfig.getServletContext();
    if (Boolean.TRUE.equals(servletContext.getAttribute(ALREADY_INITED))) {
        return;
    }
    ServerManager serverManager = new ServerManager();
    ServerConfigurationInformation information = ServerConfigurationInformationFactory.createServerConfigurationInformation(servletConfig);
    serverManager.init(information, null);
    serverManager.start();
    servletContext.setAttribute(ALREADY_INITED, Boolean.TRUE);
    servletContext.setAttribute(SYNAPSE_SERVER_MANAGER, serverManager);
}
Also used : ServerManager(org.apache.synapse.ServerManager) ServletConfig(javax.servlet.ServletConfig) ServletContext(javax.servlet.ServletContext) ServerConfigurationInformation(org.apache.synapse.ServerConfigurationInformation)

Example 4 with ServerConfigurationInformation

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

the class AbstractAutomationTestCase method setUpSynapseEnv.

protected void setUpSynapseEnv() {
    System.setProperty("port", "8280");
    System.setProperty("org.apache.xerces.xni.parser.XMLParserConfiguration", "org.apache.xerces.parsers.XMLGrammarCachingConfiguration");
    System.setProperty("axis2.xml", "modules/samples/target/test_repos/synapse/conf/axis2.xml");
    ServerConfigurationInformation information = new ServerConfigurationInformation();
    information.setAxis2RepoLocation(SYNAPSE_REPO);
    serverManager = new ServerManager();
    serverManager.init(information, null);
    serverManager.start();
}
Also used : ServerManager(org.apache.synapse.ServerManager) SampleAxis2ServerManager(samples.util.SampleAxis2ServerManager) ServerConfigurationInformation(org.apache.synapse.ServerConfigurationInformation)

Example 5 with ServerConfigurationInformation

use of org.apache.synapse.ServerConfigurationInformation 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

ServerConfigurationInformation (org.apache.synapse.ServerConfigurationInformation)5 ServerContextInformation (org.apache.synapse.ServerContextInformation)3 ServerManager (org.apache.synapse.ServerManager)3 HashMap (java.util.HashMap)2 ConfigurationContext (org.apache.axis2.context.ConfigurationContext)2 AxisService (org.apache.axis2.description.AxisService)2 SynapseEnvironment (org.apache.synapse.core.SynapseEnvironment)2 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 ServletConfig (javax.servlet.ServletConfig)1 ServletContext (javax.servlet.ServletContext)1 TransportInDescription (org.apache.axis2.description.TransportInDescription)1 AxisConfiguration (org.apache.axis2.engine.AxisConfiguration)1 MessageReceiver (org.apache.axis2.engine.MessageReceiver)1 SynapseException (org.apache.synapse.SynapseException)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