use of org.apache.synapse.config.SynapseConfiguration in project wso2-synapse by wso2.
the class ProxyServiceTest method testRecursiveImports2.
/**
* Test a proxy service with recursive imports and without a {@link ResourceMap}.
* Regression test for SYNAPSE-442.
*/
public void testRecursiveImports2() throws Exception {
ProxyService testService = new ProxyService("mytest");
SynapseConfiguration synCfg = new SynapseConfiguration();
AxisConfiguration axisCfg = new AxisConfiguration();
testService.setWsdlURI(getClass().getResource("SimpleStockService.wsdl").toURI());
testService.buildAxisService(synCfg, axisCfg);
}
use of org.apache.synapse.config.SynapseConfiguration in project wso2-synapse by wso2.
the class ProxyServiceTest method testWSDLWithoutPublishWSDL.
/**
* Test that a proxy service without publishWSDL will produce a meaningful WSDL.
* This is a regression test for SYNAPSE-366.
*/
public void testWSDLWithoutPublishWSDL() throws Exception {
// Build the proxy service
SynapseConfiguration synCfg = new SynapseConfiguration();
AxisConfiguration axisCfg = new AxisConfiguration();
ProxyService proxyService = new ProxyService("Test");
AxisService axisService = proxyService.buildAxisService(synCfg, axisCfg);
// Serialize the WSDL
ByteArrayOutputStream baos = new ByteArrayOutputStream();
axisService.printWSDL(baos);
// Check that the produced WSDL can be read by WSDL4J
WSDLReader wsdlReader = WSDLFactory.newInstance().newWSDLReader();
wsdlReader.readWSDL(null, new InputSource(new ByteArrayInputStream(baos.toByteArray())));
}
use of org.apache.synapse.config.SynapseConfiguration in project wso2-synapse by wso2.
the class ProxyServiceTest method testBuildAxisServiceWithUnreachableWsdlEndpointWithPublishWSDLSafeModeDisabled.
/**
* Tests building a proxy service with an unreachable endpoint specified as the published wsdl url with the
* 'enablePublishWSDLSafeMode' set to true.
*
* @throws Exception if an error occurs when converting the URI string to a URI
*/
public void testBuildAxisServiceWithUnreachableWsdlEndpointWithPublishWSDLSafeModeDisabled() throws Exception {
SynapseConfiguration synCfg = new SynapseConfiguration();
AxisConfiguration axisCfg = new AxisConfiguration();
ProxyService proxyService = new ProxyService("faultyPublishWsdlEndpointProxyWithPublishWSDLSafeModeDisabled");
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", false);
synCfg.addEndpoint("wsdlEndPoint", wsdlEndpoint);
try {
proxyService.buildAxisService(synCfg, axisCfg);
Assert.fail("Axis service built with an unreachable wsdl endpoint should throw fault");
} catch (SynapseException e) {
Assert.assertTrue("Unexpected exception thrown: " + e, e.getMessage().contains("Error reading from wsdl URI"));
}
}
use of org.apache.synapse.config.SynapseConfiguration 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.config.SynapseConfiguration 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);
}
Aggregations