Search in sources :

Example 1 with WSDLInterceptor

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

the class WSDLPublisherInterceptor method handleRequest.

@Override
public Outcome handleRequest(final Exchange exc) throws Exception {
    if (!"GET".equals(exc.getRequest().getMethod()))
        return Outcome.CONTINUE;
    try {
        String resource = null;
        if (exc.getRequestURI().endsWith("?wsdl") || exc.getRequestURI().endsWith("?WSDL")) {
            processDocuments(exc);
            exc.setResponse(WebServerInterceptor.createResponse(router.getResolverMap(), resource = wsdl));
            exc.getResponse().getHeader().setContentType(MimeType.TEXT_XML);
        }
        if (exc.getRequestURI().contains("?xsd=")) {
            Map<String, String> params = URLParamUtil.getParams(router.getUriFactory(), exc);
            if (params.containsKey("xsd")) {
                int n = Integer.parseInt(params.get("xsd"));
                String path;
                processDocuments(exc);
                synchronized (paths) {
                    if (!paths.containsKey(n)) {
                        exc.setResponse(Response.forbidden("Unknown parameter. You may only retrieve documents referenced by the WSDL.").build());
                        return Outcome.ABORT;
                    }
                    path = paths.get(n);
                }
                exc.setResponse(WebServerInterceptor.createResponse(router.getResolverMap(), resource = path));
                exc.getResponse().getHeader().setContentType(MimeType.TEXT_XML);
            }
        }
        if (resource != null) {
            WSDLInterceptor wi = new WSDLInterceptor();
            wi.setRewriteEndpoint(false);
            wi.setPathRewriter(new RelativePathRewriter(exc, resource));
            wi.handleResponse(exc);
            return Outcome.RETURN;
        }
    } catch (NumberFormatException e) {
        exc.setResponse(HttpUtil.setHTMLErrorResponse(Response.internalServerError(), "Bad parameter format.", ""));
        return Outcome.ABORT;
    } catch (ResourceRetrievalException e) {
        exc.setResponse(Response.notFound().build());
        return Outcome.ABORT;
    }
    return Outcome.CONTINUE;
}
Also used : WSDLInterceptor(com.predic8.membrane.core.interceptor.WSDLInterceptor) ResourceRetrievalException(com.predic8.membrane.core.resolver.ResourceRetrievalException)

Example 2 with WSDLInterceptor

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

the class WSDLInterceptorTest method setUp.

@Before
public void setUp() throws Exception {
    exc = new Exchange(new FakeHttpHandler(3011));
    exc.setRequest(MessageUtil.getGetRequest("/axis2/services/BLZService?wsdl"));
    InputStream resourceAsStream = this.getClass().getResourceAsStream("/blz-service.wsdl");
    Response okResponse = Response.ok().contentType("text/xml; charset=utf-8").body(resourceAsStream, true).build();
    exc.setResponse(okResponse);
    exc.setOriginalHostHeader("thomas-bayer.com:80");
    interceptor = new WSDLInterceptor();
}
Also used : Exchange(com.predic8.membrane.core.exchange.Exchange) Response(com.predic8.membrane.core.http.Response) InputStream(java.io.InputStream) FakeHttpHandler(com.predic8.membrane.core.transport.http.FakeHttpHandler) Before(org.junit.Before)

Example 3 with WSDLInterceptor

use of com.predic8.membrane.core.interceptor.WSDLInterceptor 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 4 with WSDLInterceptor

use of com.predic8.membrane.core.interceptor.WSDLInterceptor 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);
        }
    }
}
Also used : WSDLInterceptor(com.predic8.membrane.core.interceptor.WSDLInterceptor) ResourceRetrievalException(com.predic8.membrane.core.resolver.ResourceRetrievalException)

Aggregations

WSDLInterceptor (com.predic8.membrane.core.interceptor.WSDLInterceptor)3 ResourceRetrievalException (com.predic8.membrane.core.resolver.ResourceRetrievalException)2 Exchange (com.predic8.membrane.core.exchange.Exchange)1 Response (com.predic8.membrane.core.http.Response)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 FakeHttpHandler (com.predic8.membrane.core.transport.http.FakeHttpHandler)1 PathRewriter (com.predic8.membrane.core.ws.relocator.Relocator.PathRewriter)1 InputStream (java.io.InputStream)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 Matcher (java.util.regex.Matcher)1 Before (org.junit.Before)1