JAX-WS = When Apache CXF is installed it “steals” default JDK JAX-WS implementation, how to solve?

后端 未结 5 1278
轮回少年
轮回少年 2020-11-28 03:15

I have a strange problem.

  1. Using wsimport I generated als JAX-WS Code from a WSDL (in a dedicated eclipse java project). This works fine in JDK6 without any

5条回答
  •  甜味超标
    2020-11-28 04:00

    I had a similar problem. In my case I had to use org.apache.cxf.jaxws.spi.ProviderImpl for JAX-WS stuff (creating webservice endpoints etc.) and com.sun.xml.internal.ws.spi.ProviderImpl for publishing endpoints on com.sun.net.httpserver.HttpsServer.

    I managed to solve this by creating my own provider which extends javax.xml.ws.spi.Provider and using it instead of the default one.

    package provider;
    
    import java.net.URL;
    import java.util.List;
    
    import javax.xml.namespace.QName;
    import javax.xml.transform.Source;
    import javax.xml.ws.Endpoint;
    import javax.xml.ws.EndpointReference;
    import javax.xml.ws.WebServiceFeature;
    import javax.xml.ws.spi.Provider;
    import javax.xml.ws.spi.ServiceDelegate;
    import javax.xml.ws.wsaddressing.W3CEndpointReference;
    
    import org.w3c.dom.Element;
    
    public class MyProvider extends Provider
    {
    
    @SuppressWarnings({ "rawtypes", "unchecked" })
    @Override
    public ServiceDelegate createServiceDelegate(URL wsdlDocumentLocation, QName serviceName, Class serviceClass)
    {
        try {
            return ((Provider) Class.forName("org.apache.cxf.jaxws.spi.ProviderImpl").newInstance()).createServiceDelegate(wsdlDocumentLocation, serviceName, serviceClass.getClass());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
    
    @Override
    public Endpoint createEndpoint(String bindingId, Object implementor)
    {
        try {
            return ((Provider) Class.forName("com.sun.xml.internal.ws.spi.ProviderImpl").newInstance()).createEndpoint(bindingId, implementor);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
    
    @Override
    public Endpoint createAndPublishEndpoint(String address, Object implementor)
    {
        try {
            return ((Provider) Class.forName("com.sun.xml.internal.ws.spi.ProviderImpl").newInstance()).createAndPublishEndpoint(address, implementor);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
    
    @Override
    public EndpointReference readEndpointReference(Source eprInfoset)
    {
        try {
            return ((Provider) Class.forName("org.apache.cxf.jaxws.spi.ProviderImpl").newInstance()).readEndpointReference(eprInfoset);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
    
    @Override
    public  T getPort(EndpointReference endpointReference, Class serviceEndpointInterface, WebServiceFeature... features)
    {
        try {
            return ((Provider) Class.forName("org.apache.cxf.jaxws.spi.ProviderImpl").newInstance()).getPort(endpointReference, serviceEndpointInterface, features);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
    
    @Override
    public W3CEndpointReference createW3CEndpointReference(String address, QName serviceName, QName portName, List metadata, String wsdlDocumentLocation, List referenceParameters)
    {
        try {
            return ((Provider) Class.forName("org.apache.cxf.jaxws.spi.ProviderImpl").newInstance()).createW3CEndpointReference(address, serviceName, portName, metadata, wsdlDocumentLocation,
                    referenceParameters);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
    
    }
    

    Then simply create:

    /src/main/resources/META-INF/services/javax.xml.ws.spi.Provider
    

    file (assuming you are using Maven) with the following contents:

    package.MyProvider
    

提交回复
热议问题