Search in sources :

Example 1 with Parser

use of com.sun.xml.ws.api.wsdl.parser.XMLEntityResolver.Parser in project metro-jax-ws by eclipse-ee4j.

the class RuntimeWSDLParser method resolveWSDL.

private Parser resolveWSDL(@Nullable URL wsdlLoc, @NotNull Source wsdlSource, Class serviceClass) throws IOException, SAXException, XMLStreamException {
    String systemId = wsdlSource.getSystemId();
    XMLEntityResolver.Parser parser = resolver.resolveEntity(null, systemId);
    if (parser == null && wsdlLoc != null) {
        String exForm = wsdlLoc.toExternalForm();
        parser = resolver.resolveEntity(null, exForm);
        if (parser == null && serviceClass != null) {
            URL ru = serviceClass.getResource(".");
            if (ru != null) {
                String ruExForm = ru.toExternalForm();
                if (exForm.startsWith(ruExForm)) {
                    parser = resolver.resolveEntity(null, exForm.substring(ruExForm.length()));
                }
            }
        }
    }
    if (parser == null) {
        // an additional time if a valid WSDL Source is provided - Deva Sagar 09/20/2011
        if (isKnownReadableSource(wsdlSource)) {
            parser = new Parser(wsdlLoc, createReader(wsdlSource));
        } else if (wsdlLoc != null) {
            parser = new Parser(wsdlLoc, createReader(wsdlLoc, serviceClass));
        }
        // parser since Source is not null
        if (parser == null) {
            parser = new Parser(wsdlLoc, createReader(wsdlSource));
        }
    }
    return parser;
}
Also used : Parser(com.sun.xml.ws.api.wsdl.parser.XMLEntityResolver.Parser) XMLEntityResolver(com.sun.xml.ws.api.wsdl.parser.XMLEntityResolver) URL(java.net.URL) Parser(com.sun.xml.ws.api.wsdl.parser.XMLEntityResolver.Parser)

Example 2 with Parser

use of com.sun.xml.ws.api.wsdl.parser.XMLEntityResolver.Parser in project metro-jax-ws by eclipse-ee4j.

the class RuntimeWSDLParser method parse.

/**
 * Parses the WSDL and gives WSDLModel. If wsdl parameter is null, then wsdlLoc is used to get the WSDL. If the WSDL
 * document could not be obtained then {@link MetadataResolverFactory} is tried to get the WSDL document, if not found
 * then as last option, if the wsdlLoc has no '?wsdl' as query parameter then it is tried by appending '?wsdl'.
 *
 * @param wsdlLoc
 *      Either this or {@code wsdl} parameter must be given.
 *      Null location means the system won't be able to resolve relative references in the WSDL,
 */
public static WSDLModel parse(@Nullable URL wsdlLoc, @NotNull Source wsdlSource, @NotNull EntityResolver resolver, boolean isClientSide, Container container, Class serviceClass, @NotNull PolicyResolver policyResolver, boolean isUseStreamFromEntityResolverWrapper, WSDLParserExtension... extensions) throws IOException, XMLStreamException, SAXException {
    assert resolver != null;
    RuntimeWSDLParser wsdlParser = new RuntimeWSDLParser(wsdlSource.getSystemId(), new EntityResolverWrapper(resolver, isUseStreamFromEntityResolverWrapper), isClientSide, container, policyResolver, extensions);
    Parser parser;
    try {
        parser = wsdlParser.resolveWSDL(wsdlLoc, wsdlSource, serviceClass);
        if (!hasWSDLDefinitions(parser.parser)) {
            throw new XMLStreamException(ClientMessages.RUNTIME_WSDLPARSER_INVALID_WSDL(parser.systemId, WSDLConstants.QNAME_DEFINITIONS, parser.parser.getName(), parser.parser.getLocation()));
        }
    } catch (XMLStreamException e) {
        // Try MEX if there is WSDLLoc available
        if (wsdlLoc == null)
            throw e;
        return tryWithMex(wsdlParser, wsdlLoc, resolver, isClientSide, container, e, serviceClass, policyResolver, extensions);
    } catch (IOException e) {
        // Try MEX if there is WSDLLoc available
        if (wsdlLoc == null)
            throw e;
        return tryWithMex(wsdlParser, wsdlLoc, resolver, isClientSide, container, e, serviceClass, policyResolver, extensions);
    }
    wsdlParser.extensionFacade.start(wsdlParser.context);
    wsdlParser.parseWSDL(parser, false);
    wsdlParser.wsdlDoc.freeze();
    wsdlParser.extensionFacade.finished(wsdlParser.context);
    wsdlParser.extensionFacade.postFinished(wsdlParser.context);
    if (wsdlParser.wsdlDoc.getServices().isEmpty())
        throw new WebServiceException(ClientMessages.WSDL_CONTAINS_NO_SERVICE(wsdlLoc));
    return wsdlParser.wsdlDoc;
}
Also used : WebServiceException(jakarta.xml.ws.WebServiceException) IOException(java.io.IOException) Parser(com.sun.xml.ws.api.wsdl.parser.XMLEntityResolver.Parser)

Example 3 with Parser

use of com.sun.xml.ws.api.wsdl.parser.XMLEntityResolver.Parser in project metro-jax-ws by eclipse-ee4j.

the class EndpointFactory method getWSDLPort.

/**
 * Parses the primary WSDL and returns the {@link WSDLPort} for the given service and port names
 *
 * @param primaryWsdl Primary WSDL
 * @param metadata it may contain imported WSDL and schema documents
 * @param serviceName service name in wsdl
 * @param portName port name in WSDL
 * @param container container in which this service is running
 * @return non-null wsdl port object
 */
@NotNull
private static WSDLPort getWSDLPort(SDDocumentSource primaryWsdl, Collection<? extends SDDocumentSource> metadata, @NotNull QName serviceName, @NotNull QName portName, Container container, EntityResolver resolver) {
    URL wsdlUrl = primaryWsdl.getSystemId();
    try {
        // TODO: delegate to another entity resolver
        WSDLModel wsdlDoc = RuntimeWSDLParser.parse(new Parser(primaryWsdl), new EntityResolverImpl(metadata, resolver), false, container, ServiceFinder.find(WSDLParserExtension.class).toArray());
        if (wsdlDoc.getServices().size() == 0) {
            throw new ServerRtException(ServerMessages.localizableRUNTIME_PARSER_WSDL_NOSERVICE_IN_WSDLMODEL(wsdlUrl));
        }
        WSDLService wsdlService = wsdlDoc.getService(serviceName);
        if (wsdlService == null) {
            throw new ServerRtException(ServerMessages.localizableRUNTIME_PARSER_WSDL_INCORRECTSERVICE(serviceName, wsdlUrl));
        }
        WSDLPort wsdlPort = wsdlService.get(portName);
        if (wsdlPort == null) {
            throw new ServerRtException(ServerMessages.localizableRUNTIME_PARSER_WSDL_INCORRECTSERVICEPORT(serviceName, portName, wsdlUrl));
        }
        return wsdlPort;
    } catch (IOException | ServiceConfigurationError | SAXException e) {
        throw new ServerRtException("runtime.parser.wsdl", wsdlUrl, e);
    } catch (XMLStreamException e) {
        throw new ServerRtException("runtime.saxparser.exception", e.getMessage(), e.getLocation(), e);
    }
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) WSDLModel(com.sun.xml.ws.api.model.wsdl.WSDLModel) ServiceConfigurationError(com.sun.xml.ws.util.ServiceConfigurationError) WSDLService(com.sun.xml.ws.api.model.wsdl.WSDLService) IOException(java.io.IOException) URL(java.net.URL) Parser(com.sun.xml.ws.api.wsdl.parser.XMLEntityResolver.Parser) RuntimeWSDLParser(com.sun.xml.ws.wsdl.parser.RuntimeWSDLParser) WSDLPort(com.sun.xml.ws.api.model.wsdl.WSDLPort) SAXException(org.xml.sax.SAXException) NotNull(com.sun.istack.NotNull)

Example 4 with Parser

use of com.sun.xml.ws.api.wsdl.parser.XMLEntityResolver.Parser in project metro-jax-ws by eclipse-ee4j.

the class RuntimeWSDLParser method parseImport.

private void parseImport(@NotNull URL wsdlLoc) throws XMLStreamException, IOException, SAXException {
    String systemId = wsdlLoc.toExternalForm();
    XMLEntityResolver.Parser parser = resolver.resolveEntity(null, systemId);
    if (parser == null) {
        parser = new Parser(wsdlLoc, createReader(wsdlLoc));
    }
    parseWSDL(parser, true);
}
Also used : Parser(com.sun.xml.ws.api.wsdl.parser.XMLEntityResolver.Parser) XMLEntityResolver(com.sun.xml.ws.api.wsdl.parser.XMLEntityResolver) Parser(com.sun.xml.ws.api.wsdl.parser.XMLEntityResolver.Parser)

Example 5 with Parser

use of com.sun.xml.ws.api.wsdl.parser.XMLEntityResolver.Parser in project metro-jax-ws by eclipse-ee4j.

the class RuntimeWSDLParser method parseUsingMex.

private WSDLModel parseUsingMex(@NotNull URL wsdlLoc, @NotNull EntityResolver resolver, boolean isClientSide, Container container, Class serviceClass, PolicyResolver policyResolver, WSDLParserExtension[] extensions) throws IOException, SAXException, XMLStreamException, URISyntaxException {
    // try MEX
    MetaDataResolver mdResolver = null;
    ServiceDescriptor serviceDescriptor = null;
    RuntimeWSDLParser wsdlParser = null;
    // Currently we try the first available MetadataResolverFactory that gives us a WSDL document
    for (MetadataResolverFactory resolverFactory : ServiceFinder.find(MetadataResolverFactory.class)) {
        mdResolver = resolverFactory.metadataResolver(resolver);
        serviceDescriptor = mdResolver.resolve(wsdlLoc.toURI());
        // we got the ServiceDescriptor, now break
        if (serviceDescriptor != null)
            break;
    }
    if (serviceDescriptor != null) {
        List<? extends Source> wsdls = serviceDescriptor.getWSDLs();
        wsdlParser = new RuntimeWSDLParser(wsdlLoc.toExternalForm(), new MexEntityResolver(wsdls), isClientSide, container, policyResolver, extensions);
        wsdlParser.extensionFacade.start(wsdlParser.context);
        for (Source src : wsdls) {
            String systemId = src.getSystemId();
            Parser parser = wsdlParser.resolver.resolveEntity(null, systemId);
            wsdlParser.parseWSDL(parser, false);
        }
    }
    // it a last shot else fail
    if ((mdResolver == null || serviceDescriptor == null) && (wsdlLoc.getProtocol().equals("http") || wsdlLoc.getProtocol().equals("https")) && (wsdlLoc.getQuery() == null)) {
        String urlString = wsdlLoc.toExternalForm();
        urlString += "?wsdl";
        wsdlLoc = new URL(urlString);
        wsdlParser = new RuntimeWSDLParser(wsdlLoc.toExternalForm(), new EntityResolverWrapper(resolver), isClientSide, container, policyResolver, extensions);
        wsdlParser.extensionFacade.start(wsdlParser.context);
        Parser parser = resolveWSDL(wsdlLoc, new StreamSource(wsdlLoc.toExternalForm()), serviceClass);
        wsdlParser.parseWSDL(parser, false);
    }
    if (wsdlParser == null)
        return null;
    wsdlParser.wsdlDoc.freeze();
    wsdlParser.extensionFacade.finished(wsdlParser.context);
    wsdlParser.extensionFacade.postFinished(wsdlParser.context);
    return wsdlParser.wsdlDoc;
}
Also used : MetaDataResolver(com.sun.xml.ws.api.wsdl.parser.MetaDataResolver) ServiceDescriptor(com.sun.xml.ws.api.wsdl.parser.ServiceDescriptor) StreamSource(javax.xml.transform.stream.StreamSource) MetadataResolverFactory(com.sun.xml.ws.api.wsdl.parser.MetadataResolverFactory) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) URL(java.net.URL) Parser(com.sun.xml.ws.api.wsdl.parser.XMLEntityResolver.Parser)

Aggregations

Parser (com.sun.xml.ws.api.wsdl.parser.XMLEntityResolver.Parser)5 URL (java.net.URL)3 XMLEntityResolver (com.sun.xml.ws.api.wsdl.parser.XMLEntityResolver)2 IOException (java.io.IOException)2 NotNull (com.sun.istack.NotNull)1 WSDLModel (com.sun.xml.ws.api.model.wsdl.WSDLModel)1 WSDLPort (com.sun.xml.ws.api.model.wsdl.WSDLPort)1 WSDLService (com.sun.xml.ws.api.model.wsdl.WSDLService)1 MetaDataResolver (com.sun.xml.ws.api.wsdl.parser.MetaDataResolver)1 MetadataResolverFactory (com.sun.xml.ws.api.wsdl.parser.MetadataResolverFactory)1 ServiceDescriptor (com.sun.xml.ws.api.wsdl.parser.ServiceDescriptor)1 ServiceConfigurationError (com.sun.xml.ws.util.ServiceConfigurationError)1 RuntimeWSDLParser (com.sun.xml.ws.wsdl.parser.RuntimeWSDLParser)1 WebServiceException (jakarta.xml.ws.WebServiceException)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 Source (javax.xml.transform.Source)1 StreamSource (javax.xml.transform.stream.StreamSource)1 SAXException (org.xml.sax.SAXException)1