use of org.apache.synapse.MessageContext in project wso2-synapse by wso2.
the class ProxyServiceTest method testBuildAxisServiceWithUnreachableWsdlEndpointWithPublishWSDLSafeModeEnabled.
/**
* Tests building a proxy service with an unreachable endpoint specified as the published wsdl url with the
* 'enablePublishWSDLSafeMode' set to false.
*
* @throws Exception if an error occurs when converting the URI string to a URI
*/
public void testBuildAxisServiceWithUnreachableWsdlEndpointWithPublishWSDLSafeModeEnabled() throws Exception {
MessageContext synCtx = new TestMessageContext();
SynapseConfiguration synCfg = new SynapseConfiguration();
synCtx.setConfiguration(synCfg);
AxisConfiguration axisCfg = new AxisConfiguration();
ProxyService proxyService = new ProxyService("faultyPublishWsdlEndpointProxyWithPublishWSDLSafeModeEnabled");
proxyService.setPublishWSDLEndpoint("wsdlEndPoint");
AddressEndpoint wsdlEndpoint = new AddressEndpoint();
EndpointDefinition endpointDefinition = new EndpointDefinition();
endpointDefinition.setAddress((new URI("http://localhost/SimpleStockService.wsdl")).toString());
wsdlEndpoint.setDefinition(endpointDefinition);
proxyService.addParameter("enablePublishWSDLSafeMode", true);
synCfg.addEndpoint("wsdlEndPoint", wsdlEndpoint);
Assert.assertNull("Axis service built with an unreachable wsdl endpoint be null", proxyService.buildAxisService(synCfg, axisCfg));
}
use of org.apache.synapse.MessageContext 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);
}
use of org.apache.synapse.MessageContext in project wso2-synapse by wso2.
the class DebugManagerTest method testBreakPointTemplate.
public void testBreakPointTemplate() throws Exception {
TestMediator t1 = new TestMediator();
t1.setHandler(new TestMediateHandler() {
public void handle(MessageContext synCtx) {
result.append("T1.");
}
});
TestMediator t2 = new TestMediator();
t2.setHandler(new TestMediateHandler() {
public void handle(MessageContext synCtx) {
result.append("T2.");
}
});
TestMediator t3 = new TestMediator();
t3.setHandler(new TestMediateHandler() {
public void handle(MessageContext synCtx) {
result.append("T3");
}
});
TemplateMediator temp = new TemplateMediator();
temp.addChild(t1);
temp.addChild(t2);
temp.addChild(t3);
temp.setName("test_sequence_template_6");
temp.setParameters(new HashSet<String>());
synConfig.addSequenceTemplate(temp.getName(), temp);
String debug_command = "{\"command\":\"set\",\"command-argument\":\"breakpoint\",\"mediation-component\":" + "\"template\",\"template\":{\"template-key\":\"test_sequence_template_6\",\"mediator-position\": \"0\"}}";
dm.processDebugCommand(debug_command);
debug_command = "{\"command\":\"set\",\"command-argument\":\"breakpoint\",\"mediation-component\":\"template\"," + "\"template\":{\"template-key\":\"test_sequence_template_6\",\"mediator-position\": \"1\"}}";
dm.processDebugCommand(debug_command);
MessageContext synCtx = TestUtils.getTestContext("<empty/>");
synEnv.setDebugEnabled(false);
temp.mediate(synCtx);
assertTrue("T1.T2.T3".equals(result.toString()));
}
use of org.apache.synapse.MessageContext in project wso2-synapse by wso2.
the class DynamicLoadBalanceEndpointTest method testSend.
/**
* Test sending a message to a load balance EP
*
* @throws AxisFault on an issue sending message to DynamicLoadBalanceEndpoint
*/
@Test
public void testSend() throws AxisFault {
DynamicLoadbalanceEndpoint dynamicLoadbalanceEndpoint = new DynamicLoadbalanceEndpoint();
SynapseEnvironment synapseEnvironment = getMockedSynapseEnvironment();
dynamicLoadbalanceEndpoint.init(synapseEnvironment);
MessageContext messageContext = createMessageContext();
// Mock a LoadBalanceMembershipHandler and set
LoadBalanceMembershipHandler loadBalanceMembershipHandler = PowerMockito.mock(LoadBalanceMembershipHandler.class);
Member member1 = new Member("localhost", 9000);
Mockito.when(loadBalanceMembershipHandler.getNextApplicationMember(any(AlgorithmContext.class))).thenReturn(member1);
dynamicLoadbalanceEndpoint.setLoadBalanceMembershipHandler(loadBalanceMembershipHandler);
// set mocked SynapseEnvironment to message context
((Axis2MessageContext) messageContext).getAxis2MessageContext().getConfigurationContext().getAxisConfiguration().addParameter(SynapseConstants.SYNAPSE_ENV, synapseEnvironment);
messageContext.setEnvironment(synapseEnvironment);
// send message
dynamicLoadbalanceEndpoint.send(messageContext);
Assert.assertNotNull("SynapseConstants.LAST_ENDPOINT should return a not null value", messageContext.getProperty(SynapseConstants.LAST_ENDPOINT));
}
use of org.apache.synapse.MessageContext 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;
}
Aggregations