use of com.predic8.membrane.core.interceptor.server.WSDLPublisherInterceptor 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++;
}
}
use of com.predic8.membrane.core.interceptor.server.WSDLPublisherInterceptor in project service-proxy by membrane.
the class WSDLPublisherTest method before.
@Before
public void before() throws Exception {
router = new HttpRouter();
ServiceProxy sp2 = new ServiceProxy(new ServiceProxyKey("*", "*", ".*", port), "", -1);
WSDLPublisherInterceptor wi = new WSDLPublisherInterceptor();
wi.setWsdl(wsdlLocation);
wi.init(router);
sp2.getInterceptors().add(wi);
router.getRuleManager().addProxyAndOpenPortIfNew(sp2);
router.init();
}
use of com.predic8.membrane.core.interceptor.server.WSDLPublisherInterceptor in project service-proxy by membrane.
the class WSDLPublisherInterceptor method processDocuments.
private void processDocuments(Exchange exc) throws Exception {
// exc.response is set to garbage and should be discarded after this method
synchronized (paths) {
try {
while (true) {
String doc = documents_to_process.poll();
if (doc == null)
break;
log.debug("WSDLPublisherInterceptor: processing " + doc);
exc.setResponse(WebServerInterceptor.createResponse(router.getResolverMap(), doc));
WSDLInterceptor wi = new WSDLInterceptor();
wi.setRewriteEndpoint(false);
wi.setPathRewriter(new RelativePathRewriter(exc, doc));
wi.handleResponse(exc);
}
} catch (ResourceRetrievalException e) {
log.error("Could not recursively load all documents referenced by '" + wsdl + "'.", e);
}
}
}
Aggregations