Search in sources :

Example 1 with WSDLModel

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

the class WSServiceDelegate method getWSDLModelfromSEI.

private WSDLService getWSDLModelfromSEI(final Class sei) {
    WebService ws = AccessController.doPrivileged(new PrivilegedAction<>() {

        public WebService run() {
            return (WebService) sei.getAnnotation(WebService.class);
        }
    });
    if (ws == null || ws.wsdlLocation().equals(""))
        return null;
    String wsdlLocation = ws.wsdlLocation();
    wsdlLocation = JAXWSUtils.absolutize(JAXWSUtils.getFileOrURLName(wsdlLocation));
    Source wsdl = new StreamSource(wsdlLocation);
    WSDLService service = null;
    try {
        URL url = wsdl.getSystemId() == null ? null : new URL(wsdl.getSystemId());
        WSDLModel model = parseWSDL(url, wsdl, sei);
        service = model.getService(this.serviceName);
        if (service == null)
            throw new WebServiceException(ClientMessages.INVALID_SERVICE_NAME(this.serviceName, buildNameList(model.getServices().keySet())));
    } catch (MalformedURLException e) {
        throw new WebServiceException(ClientMessages.INVALID_WSDL_URL(wsdl.getSystemId()));
    }
    return service;
}
Also used : MalformedURLException(java.net.MalformedURLException) WebServiceException(jakarta.xml.ws.WebServiceException) WebService(jakarta.jws.WebService) StreamSource(javax.xml.transform.stream.StreamSource) WSDLModel(com.sun.xml.ws.api.model.wsdl.WSDLModel) WSDLService(com.sun.xml.ws.api.model.wsdl.WSDLService) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) URL(java.net.URL)

Example 2 with WSDLModel

use of com.sun.xml.ws.api.model.wsdl.WSDLModel 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 3 with WSDLModel

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

the class SwaMimeAttachmentTest method getWSDLPort.

static WSDLPort getWSDLPort(URL wsdlLoc) throws Exception {
    EntityResolver er = XmlUtil.createDefaultCatalogResolver();
    WSDLModel wsdl = RuntimeWSDLParser.parse(wsdlLoc, new StreamSource(wsdlLoc.toExternalForm()), er, true, null, ServiceFinder.find(WSDLParserExtension.class).toArray());
    QName serviceName = wsdl.getFirstServiceName();
    return wsdl.getService(serviceName).getFirstPort();
}
Also used : QName(javax.xml.namespace.QName) StreamSource(javax.xml.transform.stream.StreamSource) WSDLModel(com.sun.xml.ws.api.model.wsdl.WSDLModel) EntityResolver(org.xml.sax.EntityResolver)

Example 4 with WSDLModel

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

the class WsDatabindingTestBase method createProxy.

public static <T> T createProxy(Class<T> proxySEI, DatabindingConfig srvConfig, DatabindingConfig cliConfig, boolean debug) throws Exception {
    Class<?> endpointClass = srvConfig.getEndpointClass();
    // TODO default BindingID
    if (srvConfig.getMappingInfo().getBindingID() == null)
        srvConfig.getMappingInfo().setBindingID(BindingID.parse(endpointClass));
    Databinding srvDb = (Databinding) factory.createRuntime(srvConfig);
    InVmWSDLResolver result = new InVmWSDLResolver();
    WSDLGenInfo wsdlGenInfo = new WSDLGenInfo();
    wsdlGenInfo.setWsdlResolver(result);
    // wsdlGenInfo.setContainer(container);
    wsdlGenInfo.setExtensions(ServiceFinder.find(WSDLGeneratorExtension.class).toArray());
    wsdlGenInfo.setInlineSchemas(true);
    srvDb.generateWSDL(wsdlGenInfo);
    if (debug)
        result.print();
    WSDLModel wsdl = RuntimeWSDLParser.parse(result.getWsdlSource(), result.getEntityResolver(), false, null, new WSDLParserExtension[0]);
    QName serviceName = wsdl.getFirstServiceName();
    WSDLPort wsdlPort = wsdl.getService(serviceName).getFirstPort();
    if (cliConfig.getWsdlPort() == null)
        cliConfig.setWsdlPort(wsdlPort);
    cliConfig.getMappingInfo().setServiceName(serviceName);
    Databinding cliDb = (Databinding) factory.createRuntime(cliConfig);
    Class<?>[] intf = { proxySEI };
    WsDatabindingTestFacade h = new WsDatabindingTestFacade(cliDb, srvDb, endpointClass);
    h.wireLog = debug;
    Object proxy = Proxy.newProxyInstance(proxySEI.getClassLoader(), intf, h);
    return proxySEI.cast(proxy);
}
Also used : QName(javax.xml.namespace.QName) WSDLModel(com.sun.xml.ws.api.model.wsdl.WSDLModel) WSDLGenInfo(com.sun.xml.ws.api.databinding.WSDLGenInfo) Databinding(com.sun.xml.ws.api.databinding.Databinding) WSDLPort(com.sun.xml.ws.api.model.wsdl.WSDLPort)

Example 5 with WSDLModel

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

the class WSAM_EPRTester method runMandatoryEPRTests.

private void runMandatoryEPRTests() throws Exception {
    URL res = getClass().getClassLoader().getResource("epr/wsamTest.wsdl");
    // assuming that this is a file:// URL.
    File folder = new File(new File(res.getFile()).getParentFile(), "mandatory");
    System.out.println("\n\nMandatory Tests:\n");
    for (File f : folder.listFiles()) {
        if (!f.getName().endsWith(".xml"))
            continue;
        System.out.println("***************************");
        System.out.println("TestFile: " + f.getParentFile().getName() + "/" + f.getName());
        try {
            InputStream is = new FileInputStream(f);
            StreamSource s = new StreamSource(is);
            EndpointReference epr = EndpointReference.readFrom(s);
            WSEndpointReference wsepr = new WSEndpointReference(epr);
            System.out.println("Address: " + wsepr.getAddress());
            WSEndpointReference.Metadata metadata = wsepr.getMetaData();
            System.out.println("Metadata Valid?: true");
            if (metadata.getPortTypeName() != null)
                System.out.println("InterfaceName: " + metadata.getPortTypeName());
            if (metadata.getServiceName() != null)
                System.out.println("ServiceName: " + metadata.getServiceName());
            if (metadata.getPortName() != null)
                System.out.println("Endpoint: " + metadata.getPortName().getLocalPart());
            String wsdliLocation = metadata.getWsdliLocation();
            if (metadata.getWsdliLocation() != null) {
                System.out.println("wsdli:wsdlLocation: " + wsdliLocation);
                String wsdlLocation = wsdliLocation.substring(wsdliLocation.lastIndexOf(" "));
                WSDLModel wsdlModel = RuntimeWSDLParser.parse(new URL(wsdlLocation), new StreamSource(wsdlLocation), XmlUtil.createDefaultCatalogResolver(), false, Container.NONE, ServiceFinder.find(WSDLParserExtension.class).toArray());
                QName binding = wsdlModel.getBinding(metadata.getServiceName(), metadata.getPortName()).getName();
                System.out.println("Binding from WSDL: " + binding);
            }
            System.out.println("");
        } catch (Exception e) {
            System.out.println("Metadata Valid?: false");
            System.out.println(e.getMessage());
        // e.printStackTrace();
        }
    }
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) QName(javax.xml.namespace.QName) StreamSource(javax.xml.transform.stream.StreamSource) WSEndpointReference(com.sun.xml.ws.api.addressing.WSEndpointReference) WSDLModel(com.sun.xml.ws.api.model.wsdl.WSDLModel) File(java.io.File) URL(java.net.URL) FileInputStream(java.io.FileInputStream) WSEndpointReference(com.sun.xml.ws.api.addressing.WSEndpointReference) EndpointReference(jakarta.xml.ws.EndpointReference)

Aggregations

WSDLModel (com.sun.xml.ws.api.model.wsdl.WSDLModel)10 QName (javax.xml.namespace.QName)8 StreamSource (javax.xml.transform.stream.StreamSource)7 URL (java.net.URL)6 WSDLPort (com.sun.xml.ws.api.model.wsdl.WSDLPort)5 WSEndpointReference (com.sun.xml.ws.api.addressing.WSEndpointReference)4 WSDLService (com.sun.xml.ws.api.model.wsdl.WSDLService)3 WebServiceException (jakarta.xml.ws.WebServiceException)3 Source (javax.xml.transform.Source)3 Databinding (com.sun.xml.ws.api.databinding.Databinding)2 WSDLGenInfo (com.sun.xml.ws.api.databinding.WSDLGenInfo)2 EndpointReference (jakarta.xml.ws.EndpointReference)2 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 MalformedURLException (java.net.MalformedURLException)2 EntityResolver (org.xml.sax.EntityResolver)2 NotNull (com.sun.istack.NotNull)1 WSDLOperation (com.sun.xml.ws.api.model.wsdl.WSDLOperation)1 WSDLPortType (com.sun.xml.ws.api.model.wsdl.WSDLPortType)1