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);
}
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));
}
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);
}
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();
}
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));
}
Aggregations