use of com.predic8.membrane.core.rules.SOAPProxy in project service-proxy by membrane.
the class ValidatorInterceptor method init.
@Override
public void init() throws Exception {
validator = null;
String baseLocation = router == null ? null : router.getBaseLocation();
if (wsdl != null) {
name = "SOAP Validator";
setValidator(new WSDLValidator(resourceResolver, ResolverMap.combine(baseLocation, wsdl), createFailureHandler(), skipFaults));
}
if (schema != null) {
name = "XML Schema Validator";
setValidator(new XMLSchemaValidator(resourceResolver, ResolverMap.combine(baseLocation, schema), createFailureHandler()));
}
if (jsonSchema != null) {
name = "JSON Schema Validator";
setValidator(new JSONValidator(resourceResolver, ResolverMap.combine(baseLocation, jsonSchema), createFailureHandler()));
}
if (schematron != null) {
name = "Schematron Validator";
setValidator(new SchematronValidator(resourceResolver, ResolverMap.combine(baseLocation, schematron), createFailureHandler(), router, applicationContext));
}
if (validator == null) {
Rule parent = router.getParentProxy(this);
if (parent instanceof SOAPProxy) {
wsdl = ((SOAPProxy) parent).getWsdl();
name = "SOAP Validator";
setValidator(new WSDLValidator(resourceResolver, ResolverMap.combine(baseLocation, wsdl), createFailureHandler(), skipFaults));
}
if (validator == null)
throw new Exception("<validator> must have an attribute specifying the validator.");
}
if (skipFaults && wsdl == null)
throw new Exception("validator/@skipFaults only makes sense with validator/@wsdl");
}
use of com.predic8.membrane.core.rules.SOAPProxy in project service-proxy by membrane.
the class WSDLPublisherInterceptor method init.
@Override
public void init() throws Exception {
// inherit wsdl="..." from SoapProxy
if (wsdl == null) {
Rule parent = router.getParentProxy(this);
if (parent instanceof SOAPProxy) {
wsdl = ((SOAPProxy) parent).getWsdl();
setWsdl(wsdl);
}
}
}
use of com.predic8.membrane.core.rules.SOAPProxy in project service-proxy by membrane.
the class SwaggerRewriterInterceptor method init.
@Override
public void init() throws Exception {
// inherit wsdl="..." from SoapProxy
if (this.swagger == null) {
Rule parent = router.getParentProxy(this);
if (parent instanceof SwaggerProxy) {
setSwagger(((SwaggerProxy) parent).getSwagger());
}
}
// use default if no SwaggerProxy is found
if (this.swagger == null) {
String swaggerSource = IOUtils.toString(this.getRouter().getResolverMap().resolve(this.swaggerJson));
this.swagger = new SwaggerParser().parse(swaggerSource);
this.swaggerUrl = this.swaggerJson;
}
}
use of com.predic8.membrane.core.rules.SOAPProxy in project service-proxy by membrane.
the class QuickstartSOAPTest method doit.
@Test
public void doit() throws IOException, InterruptedException {
File baseDir = getExampleDir("quickstart-soap");
Process2 sl = new Process2.Builder().in(baseDir).script("service-proxy").waitForMembrane().start();
try {
ProxiesXmlUtil pxu = new ProxiesXmlUtil(new File(baseDir, "proxies.xml"));
pxu.updateWith("<spring:beans xmlns=\"http://membrane-soa.org/proxies/1/\"\r\n" + " xmlns:spring=\"http://www.springframework.org/schema/beans\"\r\n" + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\r\n" + " xsi:schemaLocation=\"http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd\r\n" + " http://membrane-soa.org/proxies/1/ http://membrane-soa.org/schemas/proxies-1.xsd\">\r\n" + "\r\n" + " <router>\r\n" + " \r\n" + " <soapProxy port=\"2000\" wsdl=\"http://www.thomas-bayer.com/axis2/services/BLZService?wsdl\">\r\n" + " <path>/MyBLZService</path>\r\n" + " </soapProxy>\r\n" + " \r\n" + " <serviceProxy port=\"9000\">\r\n" + " <basicAuthentication>\r\n" + " <user name=\"admin\" password=\"membrane\" />\r\n" + " </basicAuthentication> \r\n" + " <adminConsole />\r\n" + " </serviceProxy>\r\n" + " \r\n" + " </router>\r\n" + "</spring:beans>", sl);
String endpoint = "http://localhost:2000/MyBLZService";
String result = getAndAssert200(endpoint + "?wsdl");
assertContains("wsdl:documentation", result);
// assert that rewriting did take place
assertContains("localhost:2000/MyBLZService", result);
result = AssertUtils.postAndAssert200(endpoint, "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:blz=\"http://thomas-bayer.com/blz/\">\r\n" + " <soapenv:Header/>\r\n" + " <soapenv:Body>\r\n" + " <blz:getBank>\r\n" + " <blz:blz>37050198</blz:blz>\r\n" + " </blz:getBank>\r\n" + " </soapenv:Body>\r\n" + "</soapenv:Envelope>");
assertContains("Sparkasse", result);
AssertUtils.setupHTTPAuthentication("localhost", 9000, "admin", "membrane");
result = getAndAssert200("http://localhost:9000/admin/");
result.contains("BLZService");
String invalidRequest = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:blz=\"http://thomas-bayer.com/blz/\">\r\n" + " <soapenv:Header/>\r\n" + " <soapenv:Body>\r\n" + " <blz:getBank>\r\n" + " <blz:blz>37050198</blz:blz>\r\n" + " <foo />\r\n" + " </blz:getBank>\r\n" + " </soapenv:Body>\r\n" + "</soapenv:Envelope>";
result = postAndAssert(500, endpoint, invalidRequest);
assertContains(".java:", result);
AssertUtils.closeConnections();
AssertUtils.setupHTTPAuthentication("localhost", 9000, "admin", "membrane");
pxu.updateWith("<spring:beans xmlns=\"http://membrane-soa.org/proxies/1/\"\r\n" + " xmlns:spring=\"http://www.springframework.org/schema/beans\"\r\n" + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\r\n" + " xsi:schemaLocation=\"http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd\r\n" + " http://membrane-soa.org/proxies/1/ http://membrane-soa.org/schemas/proxies-1.xsd\">\r\n" + "\r\n" + " <router>\r\n" + " \r\n" + " <soapProxy port=\"2000\" wsdl=\"http://www.thomas-bayer.com/axis2/services/BLZService?wsdl\">\r\n" + " <path>/MyBLZService</path>\r\n" + " <soapStackTraceFilter/>\r\n" + " </soapProxy>\r\n" + " \r\n" + " <serviceProxy port=\"9000\">\r\n" + " <basicAuthentication>\r\n" + " <user name=\"admin\" password=\"membrane\" />\r\n" + " </basicAuthentication> \r\n" + " <adminConsole />\r\n" + " </serviceProxy>\r\n" + " \r\n" + " </router>\r\n" + "</spring:beans>", sl);
result = postAndAssert(500, endpoint, invalidRequest);
assertContainsNot(".java:", result);
AssertUtils.closeConnections();
AssertUtils.setupHTTPAuthentication("localhost", 9000, "admin", "membrane");
pxu.updateWith("<spring:beans xmlns=\"http://membrane-soa.org/proxies/1/\"\r\n" + " xmlns:spring=\"http://www.springframework.org/schema/beans\"\r\n" + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\r\n" + " xsi:schemaLocation=\"http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd\r\n" + " http://membrane-soa.org/proxies/1/ http://membrane-soa.org/schemas/proxies-1.xsd\">\r\n" + "\r\n" + " <router>\r\n" + " \r\n" + " <soapProxy port=\"2000\" wsdl=\"http://www.thomas-bayer.com/axis2/services/BLZService?wsdl\">\r\n" + " <path>/MyBLZService</path>\r\n" + " <soapStackTraceFilter/>\r\n" + " <validator/>\r\n" + " </soapProxy>\r\n" + " \r\n" + " <serviceProxy port=\"9000\">\r\n" + " <basicAuthentication>\r\n" + " <user name=\"admin\" password=\"membrane\" />\r\n" + " </basicAuthentication> \r\n" + " <adminConsole />\r\n" + " </serviceProxy>\r\n" + " \r\n" + " </router>\r\n" + "</spring:beans>", sl);
result = postAndAssert(400, endpoint, invalidRequest);
assertContains("Validation failed", result);
result = getAndAssert200("http://localhost:9000/admin/service-proxy/show?name=BLZService%3A2000");
result.contains("1 of 1 messages have been invalid");
result = getAndAssert200(endpoint);
assertContains("Target Namespace", result);
result = getAndAssert200(endpoint + "/operation/BLZServiceSOAP11Binding/BLZServicePortType/getBank");
assertContains("blz>?XXX?", result);
AssertUtils.closeConnections();
pxu.updateWith("<spring:beans xmlns=\"http://membrane-soa.org/proxies/1/\"\r\n" + " xmlns:spring=\"http://www.springframework.org/schema/beans\"\r\n" + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\r\n" + " xsi:schemaLocation=\"http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd\r\n" + " http://membrane-soa.org/proxies/1/ http://membrane-soa.org/schemas/proxies-1.xsd\">\r\n" + "\r\n" + " <router>\r\n" + " \r\n" + " <soapProxy port=\"2000\" wsdl=\"http://www.thomas-bayer.com/axis2/services/BLZService?wsdl\">\r\n" + " <path>/MyBLZService</path>\r\n" + " <soapStackTraceFilter/>\r\n" + " <validator/>\r\n" + " </soapProxy>\r\n" + " \r\n" + " <serviceProxy port=\"9000\">\r\n" + " <basicAuthentication>\r\n" + " <user name=\"admin\" password=\"membrane\" />\r\n" + " </basicAuthentication> \r\n" + " <adminConsole />\r\n" + " </serviceProxy>\r\n" + " \r\n" + " <serviceProxy port=\"2000\">\r\n" + " <index />\r\n" + " </serviceProxy>\r\n" + " \r\n" + " </router>\r\n" + "</spring:beans>", sl);
result = getAndAssert200("http://localhost:2000");
assertContains("/MyBLZService", result);
} finally {
sl.killScript();
}
}
use of com.predic8.membrane.core.rules.SOAPProxy in project service-proxy by membrane.
the class SOAPProxy method configure.
public void configure() throws Exception {
parseWSDL();
// remove previously added interceptors
for (; automaticallyAddedInterceptorCount > 0; automaticallyAddedInterceptorCount--) interceptors.remove(0);
// add interceptors (in reverse order) to position 0.
WebServiceExplorerInterceptor sui = new WebServiceExplorerInterceptor();
sui.setWsdl(wsdl);
sui.setPortName(portName);
interceptors.add(0, sui);
automaticallyAddedInterceptorCount++;
boolean hasPublisher = getInterceptorOfType(WSDLPublisherInterceptor.class) != null;
if (!hasPublisher) {
WSDLPublisherInterceptor wp = new WSDLPublisherInterceptor();
wp.setWsdl(wsdl);
interceptors.add(0, wp);
automaticallyAddedInterceptorCount++;
}
WSDLInterceptor wsdlInterceptor = getInterceptorOfType(WSDLInterceptor.class);
boolean hasRewriter = wsdlInterceptor != null;
if (!hasRewriter) {
wsdlInterceptor = new WSDLInterceptor();
interceptors.add(0, wsdlInterceptor);
automaticallyAddedInterceptorCount++;
}
if (key.getPath() != null) {
final String keyPath = key.getPath();
final String name = URLUtil.getName(router.getUriFactory(), keyPath);
wsdlInterceptor.setPathRewriter(new PathRewriter() {
@Override
public String rewrite(String path2) {
try {
if (path2.contains("://")) {
path2 = new URL(new URL(path2), keyPath).toString();
} else {
Matcher m = relativePathPattern.matcher(path2);
path2 = m.replaceAll("./" + name + "?");
}
} catch (MalformedURLException e) {
}
return path2;
}
});
}
if (hasRewriter && !hasPublisher)
log.warn("A <soapProxy> contains a <wsdlRewriter>, but no <wsdlPublisher>. Probably you want to insert a <wsdlPublisher> just after the <wsdlRewriter>. (Or, if this is a valid use case, please notify us at " + Constants.PRODUCT_CONTACT_EMAIL + ".)");
if (targetPath != null) {
RewriteInterceptor ri = new RewriteInterceptor();
ri.setMappings(Lists.newArrayList(new RewriteInterceptor.Mapping("^" + Pattern.quote(key.getPath()), Matcher.quoteReplacement(targetPath), "rewrite")));
interceptors.add(0, ri);
automaticallyAddedInterceptorCount++;
}
}
Aggregations