Search in sources :

Example 6 with SOAPProxy

use of com.predic8.membrane.core.rules.SOAPProxy in project service-proxy by membrane.

the class UnavailableSoapProxyTest method setup.

@Before
public void setup() {
    r = new Router();
    HttpClientConfiguration httpClientConfig = new HttpClientConfiguration();
    httpClientConfig.setMaxRetries(1);
    r.setHttpClientConfig(httpClientConfig);
    r.setHotDeploy(false);
    r.setRetryInit(true);
    sp = new SOAPProxy();
    sp.setPort(2000);
    sp.setWsdl("http://localhost:2001/axis2/services/BLZService?wsdl");
    sp3 = new ServiceProxy();
    sp3.setPort(2000);
    sp3.setTarget(new AbstractServiceProxy.Target("localhost", 2001));
    ValidatorInterceptor v = new ValidatorInterceptor();
    v.setWsdl("http://localhost:2001/axis2/services/BLZService?wsdl");
    sp3.getInterceptors().add(v);
    SOAPProxy sp2 = new SOAPProxy();
    sp2.setPort(2001);
    sp2.setWsdl("http://www.thomas-bayer.com/axis2/services/BLZService?wsdl");
    r2 = new Router();
    r2.setHotDeploy(false);
    r2.getRules().add(sp2);
// r2 will be started during the test
}
Also used : ValidatorInterceptor(com.predic8.membrane.core.interceptor.schemavalidation.ValidatorInterceptor) Router(com.predic8.membrane.core.Router) HttpClientConfiguration(com.predic8.membrane.core.transport.http.client.HttpClientConfiguration) Before(org.junit.Before)

Example 7 with SOAPProxy

use of com.predic8.membrane.core.rules.SOAPProxy in project service-proxy by membrane.

the class SOAPProxy method parseWSDL.

/**
 * @return error or null for success
 */
private void parseWSDL() throws Exception {
    WSDLParserContext ctx = new WSDLParserContext();
    ctx.setInput(ResolverMap.combine(router.getBaseLocation(), wsdl));
    try {
        WSDLParser wsdlParser = new WSDLParser();
        wsdlParser.setResourceResolver(resolverMap.toExternalResolver().toExternalResolver());
        Definitions definitions = wsdlParser.parse(ctx);
        List<Service> services = definitions.getServices();
        if (services.size() != 1)
            throw new IllegalArgumentException("There are " + services.size() + " services defined in the WSDL, but exactly 1 is required for soapProxy.");
        Service service = services.get(0);
        if (StringUtils.isEmpty(name))
            name = StringUtils.isEmpty(service.getName()) ? definitions.getName() : service.getName();
        List<Port> ports = service.getPorts();
        Port port = selectPort(ports, portName);
        String location = port.getAddress().getLocation();
        if (location == null)
            throw new IllegalArgumentException("In the WSDL, there is no @location defined on the port.");
        try {
            URL url = new URL(location);
            target.setHost(url.getHost());
            if (url.getPort() != -1)
                target.setPort(url.getPort());
            else
                target.setPort(url.getDefaultPort());
            if (key.getPath() == null) {
                key.setUsePathPattern(true);
                key.setPathRegExp(false);
                key.setPath(url.getPath());
            } else {
                String query = "";
                if (url.getQuery() != null) {
                    query = "?" + url.getQuery();
                }
                targetPath = url.getPath() + query;
            }
            if (location.startsWith("https")) {
                SSLParser sslOutboundParser = new SSLParser();
                target.setSslParser(sslOutboundParser);
            }
            ((ServiceProxyKey) key).setMethod("*");
        } catch (MalformedURLException e) {
            throw new IllegalArgumentException("WSDL endpoint location '" + location + "' is not an URL.", e);
        }
        return;
    } catch (Exception e) {
        Throwable f = e;
        while (f.getCause() != null && !(f instanceof ResourceRetrievalException)) f = f.getCause();
        if (f instanceof ResourceRetrievalException) {
            ResourceRetrievalException rre = (ResourceRetrievalException) f;
            if (rre.getStatus() >= 400)
                throw rre;
            Throwable cause = rre.getCause();
            if (cause != null) {
                if (cause instanceof UnknownHostException)
                    throw (UnknownHostException) cause;
                else if (cause instanceof ConnectException)
                    throw (ConnectException) cause;
            }
        }
        throw new IllegalArgumentException("Could not download the WSDL '" + wsdl + "'.", e);
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) UnknownHostException(java.net.UnknownHostException) Definitions(com.predic8.wsdl.Definitions) Port(com.predic8.wsdl.Port) Service(com.predic8.wsdl.Service) URL(java.net.URL) ResourceRetrievalException(com.predic8.membrane.core.resolver.ResourceRetrievalException) ConnectException(java.net.ConnectException) MalformedURLException(java.net.MalformedURLException) UnknownHostException(java.net.UnknownHostException) ResourceRetrievalException(com.predic8.membrane.core.resolver.ResourceRetrievalException) SSLParser(com.predic8.membrane.core.config.security.SSLParser) WSDLParser(com.predic8.wsdl.WSDLParser) WSDLParserContext(com.predic8.wsdl.WSDLParserContext) ConnectException(java.net.ConnectException)

Aggregations

Rule (com.predic8.membrane.core.rules.Rule)3 SOAPProxy (com.predic8.membrane.core.rules.SOAPProxy)2 MalformedURLException (java.net.MalformedURLException)2 URL (java.net.URL)2 Router (com.predic8.membrane.core.Router)1 SSLParser (com.predic8.membrane.core.config.security.SSLParser)1 WSDLInterceptor (com.predic8.membrane.core.interceptor.WSDLInterceptor)1 RewriteInterceptor (com.predic8.membrane.core.interceptor.rewrite.RewriteInterceptor)1 ValidatorInterceptor (com.predic8.membrane.core.interceptor.schemavalidation.ValidatorInterceptor)1 WSDLPublisherInterceptor (com.predic8.membrane.core.interceptor.server.WSDLPublisherInterceptor)1 WebServiceExplorerInterceptor (com.predic8.membrane.core.interceptor.soap.WebServiceExplorerInterceptor)1 ResourceRetrievalException (com.predic8.membrane.core.resolver.ResourceRetrievalException)1 SwaggerProxy (com.predic8.membrane.core.rules.SwaggerProxy)1 HttpClientConfiguration (com.predic8.membrane.core.transport.http.client.HttpClientConfiguration)1 PathRewriter (com.predic8.membrane.core.ws.relocator.Relocator.PathRewriter)1 Process2 (com.predic8.membrane.examples.Process2)1 ProxiesXmlUtil (com.predic8.membrane.examples.ProxiesXmlUtil)1 Definitions (com.predic8.wsdl.Definitions)1 Port (com.predic8.wsdl.Port)1 Service (com.predic8.wsdl.Service)1