Search in sources :

Example 1 with WSDLParser

use of com.predic8.wsdl.WSDLParser in project service-proxy by membrane.

the class WSDLValidator method getSchemas.

@Override
protected List<Schema> getSchemas() {
    WSDLParserContext ctx = new WSDLParserContext();
    ctx.setInput(location);
    try {
        WSDLParser wsdlParser = new WSDLParser();
        // System.out.println("Resolver----" + resourceResolver);
        wsdlParser.setResourceResolver(resourceResolver.toExternalResolver().toExternalResolver());
        List<Schema> schemaList = new ArrayList<Schema>();
        for (Types t : wsdlParser.parse(ctx).getTypes()) schemaList.addAll(t.getSchemas());
        return schemaList;
    } catch (RuntimeException e) {
        throw new IllegalArgumentException("Could not download the WSDL " + location + " or its dependent XML Schemas.", e);
    }
}
Also used : Types(com.predic8.wsdl.Types) Schema(com.predic8.schema.Schema) ArrayList(java.util.ArrayList) WSDLParser(com.predic8.wsdl.WSDLParser) WSDLParserContext(com.predic8.wsdl.WSDLParserContext)

Example 2 with WSDLParser

use of com.predic8.wsdl.WSDLParser in project service-proxy by membrane.

the class WebServiceExplorerInterceptor method getParsedWSDL.

private Definitions getParsedWSDL() {
    if (parsedWSDL != null)
        return parsedWSDL;
    WSDLParserContext ctx = new WSDLParserContext();
    ctx.setInput(ResolverMap.combine(router.getBaseLocation(), wsdl));
    WSDLParser wsdlParser = new WSDLParser();
    wsdlParser.setResourceResolver(router.getResolverMap().toExternalResolver().toExternalResolver());
    return parsedWSDL = wsdlParser.parse(ctx);
}
Also used : WSDLParser(com.predic8.wsdl.WSDLParser) WSDLParserContext(com.predic8.wsdl.WSDLParserContext)

Example 3 with WSDLParser

use of com.predic8.wsdl.WSDLParser in project irontest by zheng-wang.

the class WSDLResource method getOperationInfo.

@GET
@Path("/{wsdlUrl}/bindings/{bindingName}/operations/{operationName}")
public SOAPOperationInfo getOperationInfo(@PathParam("wsdlUrl") String wsdlUrl, @PathParam("bindingName") String bindingName, @PathParam("operationName") String operationName) {
    SOAPOperationInfo info = new SOAPOperationInfo();
    WSDLParser parser = new WSDLParser();
    Definitions definition = parser.parse(wsdlUrl);
    StringWriter writer = new StringWriter();
    SOARequestCreator creator = new SOARequestCreator(definition, new RequestTemplateCreator(), new MarkupBuilder(writer));
    creator.createRequest(null, operationName, bindingName);
    info.setSampleRequest(writer.toString());
    return info;
}
Also used : RequestTemplateCreator(com.predic8.wstool.creator.RequestTemplateCreator) StringWriter(java.io.StringWriter) Definitions(com.predic8.wsdl.Definitions) MarkupBuilder(groovy.xml.MarkupBuilder) SOAPOperationInfo(io.irontest.models.teststep.SOAPOperationInfo) WSDLParser(com.predic8.wsdl.WSDLParser) SOARequestCreator(com.predic8.wstool.creator.SOARequestCreator) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 4 with WSDLParser

use of com.predic8.wsdl.WSDLParser in project service-proxy by membrane.

the class ResolverTest method testMembraneSoaModel.

@Test
public void testMembraneSoaModel() throws IOException {
    if (hit = !setupLocations())
        return;
    try {
        WSDLParserContext ctx = new WSDLParserContext();
        ctx.setInput(wsdlLocation);
        WSDLParser wsdlParser = new WSDLParser();
        wsdlParser.setResourceResolver(resolverMap.toExternalResolver().toExternalResolver());
        Definitions definitions = wsdlParser.parse(ctx);
        for (Schema schema : definitions.getSchemas()) // trigger lazy-loading
        schema.getElements();
    } catch (Exception e) {
        throw new RuntimeException("wsdlLocation = " + xsdLocation, e);
    }
}
Also used : Definitions(com.predic8.wsdl.Definitions) Schema(com.predic8.schema.Schema) WSDLParser(com.predic8.wsdl.WSDLParser) WSDLParserContext(com.predic8.wsdl.WSDLParserContext) InvalidParameterException(java.security.InvalidParameterException) IOException(java.io.IOException) Test(org.junit.Test)

Example 5 with WSDLParser

use of com.predic8.wsdl.WSDLParser 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

WSDLParser (com.predic8.wsdl.WSDLParser)7 Definitions (com.predic8.wsdl.Definitions)5 WSDLParserContext (com.predic8.wsdl.WSDLParserContext)4 Schema (com.predic8.schema.Schema)2 RequestTemplateCreator (com.predic8.wstool.creator.RequestTemplateCreator)2 SOARequestCreator (com.predic8.wstool.creator.SOARequestCreator)2 MarkupBuilder (groovy.xml.MarkupBuilder)2 StringWriter (java.io.StringWriter)2 ArrayList (java.util.ArrayList)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 SSLParser (com.predic8.membrane.core.config.security.SSLParser)1 ResourceRetrievalException (com.predic8.membrane.core.resolver.ResourceRetrievalException)1 Binding (com.predic8.wsdl.Binding)1 BindingOperation (com.predic8.wsdl.BindingOperation)1 Port (com.predic8.wsdl.Port)1 Service (com.predic8.wsdl.Service)1 Types (com.predic8.wsdl.Types)1 SSLTrustedExternalResolver (io.irontest.core.SSLTrustedExternalResolver)1 WSDLBinding (io.irontest.models.WSDLBinding)1