Search in sources :

Example 1 with WSDLService

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

the class WSServiceDelegate method getPort.

@Override
public <T> T getPort(Class<T> portInterface, WebServiceFeature... features) {
    // get the portType from SEI
    QName portTypeName = RuntimeModeler.getPortTypeName(portInterface, getMetadadaReader(new WebServiceFeatureList(features), portInterface.getClassLoader()));
    WSDLService tmpWsdlService = this.wsdlService;
    if (tmpWsdlService == null) {
        // assigning it to local variable and not setting it back to this.wsdlService intentionally
        // as we don't want to include the service instance with information gathered from sei
        tmpWsdlService = getWSDLModelfromSEI(portInterface);
        // still null? throw error need wsdl metadata to create a proxy
        if (tmpWsdlService == null) {
            throw new WebServiceException(ProviderApiMessages.NO_WSDL_NO_PORT(portInterface.getName()));
        }
    }
    // get the first port corresponding to the SEI
    WSDLPort port = tmpWsdlService.getMatchingPort(portTypeName);
    if (port == null) {
        throw new WebServiceException(ClientMessages.UNDEFINED_PORT_TYPE(portTypeName));
    }
    QName portName = port.getName();
    return getPort(portName, portInterface, features);
}
Also used : WebServiceException(jakarta.xml.ws.WebServiceException) QName(javax.xml.namespace.QName) WSDLService(com.sun.xml.ws.api.model.wsdl.WSDLService) WebServiceFeatureList(com.sun.xml.ws.binding.WebServiceFeatureList) WSDLPort(com.sun.xml.ws.api.model.wsdl.WSDLPort)

Example 2 with WSDLService

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

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

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

the class MetadataTester method testMultiplePort.

public void testMultiplePort() throws IOException, SAXException, XMLStreamException {
    URL url = JAXWSUtils.getFileOrURL(msURL);
    com.sun.xml.ws.api.model.wsdl.WSDLModel doc = RuntimeWSDLParser.parse(url, new StreamSource(url.toExternalForm()), getResolver(), true, Container.NONE);
    WSDLService service = doc.getService(new QName("http://InteropBaseAddress/interop", "PingService10"));
    WSDLPort port1 = service.get(new QName("http://InteropBaseAddress/interop", "X10_IPingService"));
    assertTrue(port1 != null);
    WSDLPort port2 = service.get(new QName("http://InteropBaseAddress/interop", "X10-NoTimestamp_IPingService"));
    assertTrue(port2 != null);
    WSDLPort port3 = service.get(new QName("http://InteropBaseAddress/interop", "K10_IPingService"));
    assertTrue(port3 != null);
    WSDLPort port4 = service.get(new QName("http://InteropBaseAddress/interop", "KD10_IPingService"));
    assertTrue(port4 != null);
}
Also used : QName(javax.xml.namespace.QName) StreamSource(javax.xml.transform.stream.StreamSource) WSDLService(com.sun.xml.ws.api.model.wsdl.WSDLService) URL(java.net.URL) WSDLPort(com.sun.xml.ws.api.model.wsdl.WSDLPort)

Example 5 with WSDLService

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

the class ProviderImpl method createW3CEndpointReference.

public W3CEndpointReference createW3CEndpointReference(String address, QName interfaceName, QName serviceName, QName portName, List<Element> metadata, String wsdlDocumentLocation, List<Element> referenceParameters, List<Element> elements, Map<QName, String> attributes) {
    Container container = ContainerResolver.getInstance().getContainer();
    if (address == null) {
        if (serviceName == null || portName == null) {
            throw new IllegalStateException(ProviderApiMessages.NULL_ADDRESS_SERVICE_ENDPOINT());
        } else {
            // check if it is run in a Java EE Container and if so, get address using serviceName and portName
            Module module = container.getSPI(Module.class);
            if (module != null) {
                List<BoundEndpoint> beList = module.getBoundEndpoints();
                for (BoundEndpoint be : beList) {
                    WSEndpoint wse = be.getEndpoint();
                    if (wse.getServiceName().equals(serviceName) && wse.getPortName().equals(portName)) {
                        try {
                            address = be.getAddress().toString();
                        } catch (WebServiceException e) {
                        // May be the container does n't support this
                        // just ignore the exception
                        }
                        break;
                    }
                }
            }
            // address is still null? may be its not run in a JavaEE Container
            if (address == null)
                throw new IllegalStateException(ProviderApiMessages.NULL_ADDRESS());
        }
    }
    if ((serviceName == null) && (portName != null)) {
        throw new IllegalStateException(ProviderApiMessages.NULL_SERVICE());
    }
    // Validate Service and Port in WSDL
    String wsdlTargetNamespace = null;
    if (wsdlDocumentLocation != null) {
        try {
            EntityResolver er = XmlUtil.createDefaultCatalogResolver();
            URL wsdlLoc = new URL(wsdlDocumentLocation);
            WSDLModel wsdlDoc = RuntimeWSDLParser.parse(wsdlLoc, new StreamSource(wsdlLoc.toExternalForm()), er, true, container, ServiceFinder.find(WSDLParserExtension.class).toArray());
            if (serviceName != null) {
                WSDLService wsdlService = wsdlDoc.getService(serviceName);
                if (wsdlService == null)
                    throw new IllegalStateException(ProviderApiMessages.NOTFOUND_SERVICE_IN_WSDL(serviceName, wsdlDocumentLocation));
                if (portName != null) {
                    WSDLPort wsdlPort = wsdlService.get(portName);
                    if (wsdlPort == null)
                        throw new IllegalStateException(ProviderApiMessages.NOTFOUND_PORT_IN_WSDL(portName, serviceName, wsdlDocumentLocation));
                }
                wsdlTargetNamespace = serviceName.getNamespaceURI();
            } else {
                QName firstService = wsdlDoc.getFirstServiceName();
                wsdlTargetNamespace = firstService.getNamespaceURI();
            }
        } catch (Exception e) {
            throw new IllegalStateException(ProviderApiMessages.ERROR_WSDL(wsdlDocumentLocation), e);
        }
    }
    // wcf3.0/3.5 rejected empty metadata element.
    if (metadata != null && metadata.size() == 0) {
        metadata = null;
    }
    return new WSEndpointReference(AddressingVersion.fromSpecClass(W3CEndpointReference.class), address, serviceName, portName, interfaceName, metadata, wsdlDocumentLocation, wsdlTargetNamespace, referenceParameters, elements, attributes).toSpec(W3CEndpointReference.class);
}
Also used : WebServiceException(jakarta.xml.ws.WebServiceException) 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) BoundEndpoint(com.sun.xml.ws.api.server.BoundEndpoint) URL(java.net.URL) WebServiceException(jakarta.xml.ws.WebServiceException) JAXBException(jakarta.xml.bind.JAXBException) WSDLPort(com.sun.xml.ws.api.model.wsdl.WSDLPort) Container(com.sun.xml.ws.api.server.Container) WSEndpoint(com.sun.xml.ws.api.server.WSEndpoint) WSEndpointReference(com.sun.xml.ws.api.addressing.WSEndpointReference) WSDLService(com.sun.xml.ws.api.model.wsdl.WSDLService) Module(com.sun.xml.ws.api.server.Module)

Aggregations

WSDLService (com.sun.xml.ws.api.model.wsdl.WSDLService)7 WSDLPort (com.sun.xml.ws.api.model.wsdl.WSDLPort)6 WebServiceException (jakarta.xml.ws.WebServiceException)4 URL (java.net.URL)4 WSDLModel (com.sun.xml.ws.api.model.wsdl.WSDLModel)3 QName (javax.xml.namespace.QName)3 StreamSource (javax.xml.transform.stream.StreamSource)3 WebServiceFeatureList (com.sun.xml.ws.binding.WebServiceFeatureList)2 NotNull (com.sun.istack.NotNull)1 WSEndpointReference (com.sun.xml.ws.api.addressing.WSEndpointReference)1 BoundEndpoint (com.sun.xml.ws.api.server.BoundEndpoint)1 Container (com.sun.xml.ws.api.server.Container)1 Module (com.sun.xml.ws.api.server.Module)1 WSEndpoint (com.sun.xml.ws.api.server.WSEndpoint)1 Parser (com.sun.xml.ws.api.wsdl.parser.XMLEntityResolver.Parser)1 ServiceConfigurationError (com.sun.xml.ws.util.ServiceConfigurationError)1 RuntimeWSDLParser (com.sun.xml.ws.wsdl.parser.RuntimeWSDLParser)1 WebService (jakarta.jws.WebService)1 JAXBException (jakarta.xml.bind.JAXBException)1 WebServiceFeature (jakarta.xml.ws.WebServiceFeature)1