use of com.predic8.membrane.core.ws.relocator.Relocator.PathRewriter in project service-proxy by membrane.
the class WADLInterceptor method rewrite.
@Override
protected void rewrite(Exchange exc) throws Exception, IOException {
log.debug("Changing endpoint address in WADL");
ByteArrayOutputStream stream = new ByteArrayOutputStream();
Relocator relocator = new Relocator(new OutputStreamWriter(stream, exc.getResponse().getCharset()), getLocationProtocol(), getLocationHost(exc), getLocationPort(exc), pathRewriter);
relocator.getRelocatingAttributes().put(new QName(WADL_NS, "resources"), "base");
relocator.getRelocatingAttributes().put(new QName(WADL_NS, "include"), "href");
relocator.relocate(new InputStreamReader(exc.getResponse().getBodyAsStreamDecoded(), exc.getResponse().getCharset()));
exc.getResponse().setBodyContent(stream.toByteArray());
}
use of com.predic8.membrane.core.ws.relocator.Relocator.PathRewriter in project service-proxy by membrane.
the class WSDLInterceptor method rewrite.
@Override
protected void rewrite(Exchange exc) throws Exception, IOException {
log.debug("Changing endpoint address in WSDL");
ByteArrayOutputStream stream = new ByteArrayOutputStream();
Relocator relocator = new Relocator(new OutputStreamWriter(stream, exc.getResponse().getCharset()), getLocationProtocol(), getLocationHost(exc), getLocationPort(exc), pathRewriter);
if (rewriteEndpoint) {
relocator.getRelocatingAttributes().put(new QName(WSDL_SOAP11_NS, "address"), "location");
relocator.getRelocatingAttributes().put(new QName(WSDL_SOAP12_NS, "address"), "location");
relocator.getRelocatingAttributes().put(new QName(WSDL_HTTP_NS, "address"), "location");
}
relocator.getRelocatingAttributes().put(new QName(XSD_NS, "import"), "schemaLocation");
relocator.getRelocatingAttributes().put(new QName(XSD_NS, "include"), "schemaLocation");
relocator.relocate(new InputStreamReader(exc.getResponse().getBodyAsStreamDecoded(), exc.getResponse().getCharset()));
if (relocator.isWsdlFound()) {
registerWSDL(exc);
}
exc.getResponse().setBodyContent(stream.toByteArray());
}
use of com.predic8.membrane.core.ws.relocator.Relocator.PathRewriter 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.ws.relocator.Relocator.PathRewriter in project service-proxy by membrane.
the class TestServiceInterceptor method init.
@Override
public void init(final Router router) throws Exception {
super.init(router);
wi.init(router);
Rule r = router.getParentProxy(this);
if (r instanceof AbstractServiceProxy) {
final Path path = ((AbstractServiceProxy) r).getPath();
if (path != null) {
if (path.isRegExp())
throw new Exception("<testService> may not be used together with <path isRegExp=\"true\">.");
final String keyPath = path.getValue();
final String name = URLUtil.getName(router.getUriFactory(), keyPath);
wi.setPathRewriter(new PathRewriter() {
@Override
public String rewrite(String path2) {
try {
if (path2.contains("://")) {
path2 = new URL(new URL(path2), keyPath).toString();
} else {
Matcher m = RELATIVE_PATH_PATTERN.matcher(path2);
path2 = m.replaceAll("./" + name + "?");
}
} catch (MalformedURLException e) {
}
return path2;
}
});
}
}
}
Aggregations