Search in sources :

Example 1 with RewriteInterceptor

use of com.predic8.membrane.core.interceptor.rewrite.RewriteInterceptor 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++;
    }
}
Also used : RewriteInterceptor(com.predic8.membrane.core.interceptor.rewrite.RewriteInterceptor) MalformedURLException(java.net.MalformedURLException) PathRewriter(com.predic8.membrane.core.ws.relocator.Relocator.PathRewriter) Matcher(java.util.regex.Matcher) WebServiceExplorerInterceptor(com.predic8.membrane.core.interceptor.soap.WebServiceExplorerInterceptor) WSDLInterceptor(com.predic8.membrane.core.interceptor.WSDLInterceptor) WSDLPublisherInterceptor(com.predic8.membrane.core.interceptor.server.WSDLPublisherInterceptor) URL(java.net.URL)

Example 2 with RewriteInterceptor

use of com.predic8.membrane.core.interceptor.rewrite.RewriteInterceptor in project service-proxy by membrane.

the class RewriteInterceptorTest method setUp.

@Before
public void setUp() throws Exception {
    HttpRouter router = new HttpRouter();
    di = new DispatchingInterceptor();
    di.init(router);
    sp = new ServiceProxy(new ServiceProxyKey(80, null), "www.predic8.de", 80);
    sp.init(router);
    exc = new Exchange(null);
    exc.setRequest(MessageUtil.getGetRequest("/buy/banana/3"));
    rewriter = new RewriteInterceptor();
    List<Mapping> mappings = new ArrayList<Mapping>();
    mappings.add(new Mapping("/buy/(.*)/(.*)", "/buy?item=$1&amount=$2", null));
    rewriter.setMappings(mappings);
    rewriter.init(router);
}
Also used : Exchange(com.predic8.membrane.core.exchange.Exchange) ServiceProxyKey(com.predic8.membrane.core.rules.ServiceProxyKey) ServiceProxy(com.predic8.membrane.core.rules.ServiceProxy) ArrayList(java.util.ArrayList) Mapping(com.predic8.membrane.core.interceptor.rewrite.RewriteInterceptor.Mapping) HttpRouter(com.predic8.membrane.core.HttpRouter) DispatchingInterceptor(com.predic8.membrane.core.interceptor.DispatchingInterceptor) Before(org.junit.Before)

Example 3 with RewriteInterceptor

use of com.predic8.membrane.core.interceptor.rewrite.RewriteInterceptor in project service-proxy by membrane.

the class RESTBLZServiceIntegrationTest method setUp.

@Before
public void setUp() throws Exception {
    Rule rule = new ServiceProxy(new ServiceProxyKey("localhost", "*", ".*", 3005), "thomas-bayer.com", 80);
    router = new HttpRouter();
    router.getRuleManager().addProxyAndOpenPortIfNew(rule);
    HTTP2XMLInterceptor http2xml = new HTTP2XMLInterceptor();
    router.getTransport().getInterceptors().add(http2xml);
    RewriteInterceptor urlRewriter = new RewriteInterceptor();
    List<Mapping> mappings = new ArrayList<Mapping>();
    mappings.add(new Mapping("/bank/.*", "/axis2/services/BLZService", null));
    urlRewriter.setMappings(mappings);
    router.getTransport().getInterceptors().add(urlRewriter);
    XSLTInterceptor xslt = new XSLTInterceptor();
    xslt.setXslt("classpath:/blz-httpget2soap-request.xsl");
    xslt.setFlow(Flow.Set.REQUEST);
    xslt.setXslt("classpath:/strip-soap-envelope.xsl");
    xslt.setFlow(Flow.Set.RESPONSE);
    router.getTransport().getInterceptors().add(xslt);
}
Also used : Mapping(com.predic8.membrane.core.interceptor.rewrite.RewriteInterceptor.Mapping) Rule(com.predic8.membrane.core.rules.Rule) HttpRouter(com.predic8.membrane.core.HttpRouter) XSLTInterceptor(com.predic8.membrane.core.interceptor.xslt.XSLTInterceptor)

Example 4 with RewriteInterceptor

use of com.predic8.membrane.core.interceptor.rewrite.RewriteInterceptor in project service-proxy by membrane.

the class RewriteInterceptorIntegrationTest method setUp.

@Before
public void setUp() throws Exception {
    interceptor = new RewriteInterceptor();
    interceptor.getMappings().add(new Mapping("/blz-service\\?wsdl", "/axis2/services/BLZService?wsdl", null));
    Rule rule = new ServiceProxy(new ServiceProxyKey("localhost", "POST", ".*", 3006), "thomas-bayer.com", 80);
    rule.getInterceptors().add(interceptor);
    router = new HttpRouter();
    router.getRuleManager().addProxyAndOpenPortIfNew(rule);
}
Also used : Mapping(com.predic8.membrane.core.interceptor.rewrite.RewriteInterceptor.Mapping) Rule(com.predic8.membrane.core.rules.Rule) HttpRouter(com.predic8.membrane.core.HttpRouter)

Aggregations

HttpRouter (com.predic8.membrane.core.HttpRouter)3 Mapping (com.predic8.membrane.core.interceptor.rewrite.RewriteInterceptor.Mapping)3 Rule (com.predic8.membrane.core.rules.Rule)2 Exchange (com.predic8.membrane.core.exchange.Exchange)1 DispatchingInterceptor (com.predic8.membrane.core.interceptor.DispatchingInterceptor)1 WSDLInterceptor (com.predic8.membrane.core.interceptor.WSDLInterceptor)1 RewriteInterceptor (com.predic8.membrane.core.interceptor.rewrite.RewriteInterceptor)1 WSDLPublisherInterceptor (com.predic8.membrane.core.interceptor.server.WSDLPublisherInterceptor)1 WebServiceExplorerInterceptor (com.predic8.membrane.core.interceptor.soap.WebServiceExplorerInterceptor)1 XSLTInterceptor (com.predic8.membrane.core.interceptor.xslt.XSLTInterceptor)1 ServiceProxy (com.predic8.membrane.core.rules.ServiceProxy)1 ServiceProxyKey (com.predic8.membrane.core.rules.ServiceProxyKey)1 PathRewriter (com.predic8.membrane.core.ws.relocator.Relocator.PathRewriter)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 Matcher (java.util.regex.Matcher)1 Before (org.junit.Before)1