Search in sources :

Example 1 with ServiceDescriptor

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

the class MetadataFinder method getFromMetadataResolver.

/*
    * If source and target namespace are also passed in,
    * then if the mex resolver is found and it cannot get
    * the data, wsimport attempts to add ?wsdl to the
    * address and retrieve the data with a normal http get.
    * This behavior should only happen when trying a
    * mex request first.
    */
@Nullable
private Element getFromMetadataResolver(String systemId, Exception ex) {
    // try MEX
    MetaDataResolver resolver;
    ServiceDescriptor serviceDescriptor = null;
    for (MetadataResolverFactory resolverFactory : ServiceFinder.find(MetadataResolverFactory.class, ServiceLoader.load(MetadataResolverFactory.class))) {
        resolver = resolverFactory.metadataResolver(options.entityResolver);
        try {
            serviceDescriptor = resolver.resolve(new URI(systemId));
            // we got the ServiceDescriptor, now break
            if (serviceDescriptor != null)
                break;
        } catch (URISyntaxException e) {
            throw new ParseException(e);
        }
    }
    if (serviceDescriptor != null) {
        errorReceiver.warning(new SAXParseException(WsdlMessages.TRY_WITH_MEX(ex.getMessage()), null, ex));
        return parseMetadata(systemId, serviceDescriptor);
    } else {
        errorReceiver.error(null, WsdlMessages.PARSING_UNABLE_TO_GET_METADATA(ex.getMessage(), WscompileMessages.WSIMPORT_NO_WSDL(systemId)), ex);
    }
    return null;
}
Also used : MetaDataResolver(com.sun.xml.ws.api.wsdl.parser.MetaDataResolver) ServiceDescriptor(com.sun.xml.ws.api.wsdl.parser.ServiceDescriptor) SAXParseException(org.xml.sax.SAXParseException) MetadataResolverFactory(com.sun.xml.ws.api.wsdl.parser.MetadataResolverFactory) ParseException(com.sun.tools.ws.wsdl.framework.ParseException) SAXParseException(org.xml.sax.SAXParseException) Nullable(com.sun.istack.Nullable)

Example 2 with ServiceDescriptor

use of com.sun.xml.ws.api.wsdl.parser.ServiceDescriptor 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

MetaDataResolver (com.sun.xml.ws.api.wsdl.parser.MetaDataResolver)2 MetadataResolverFactory (com.sun.xml.ws.api.wsdl.parser.MetadataResolverFactory)2 ServiceDescriptor (com.sun.xml.ws.api.wsdl.parser.ServiceDescriptor)2 Nullable (com.sun.istack.Nullable)1 ParseException (com.sun.tools.ws.wsdl.framework.ParseException)1 Parser (com.sun.xml.ws.api.wsdl.parser.XMLEntityResolver.Parser)1 URL (java.net.URL)1 Source (javax.xml.transform.Source)1 StreamSource (javax.xml.transform.stream.StreamSource)1 SAXParseException (org.xml.sax.SAXParseException)1