Search in sources :

Example 1 with Provider

use of javax.xml.ws.spi.Provider in project tomee by apache.

the class ProviderWrapperTest method test.

public void test() throws Exception {
    System.setProperty(Provider.class.getName(), MockProvider.class.getName());
    Provider provider = Provider.provider();
    assertNotNull("provider is null", provider);
    assertFalse("provider should not be an instance of ProviderWrapper", provider instanceof ProviderWrapper);
    ProviderWrapper.beforeCreate(null, null, null);
    try {
        provider = Provider.provider();
        assertNotNull("provider is null", provider);
        assertTrue("provider should be an instance of ProviderWrapper", provider instanceof ProviderWrapper);
        final ProviderWrapper providerWrapper = (ProviderWrapper) provider;
        // check delegate
        final Provider delegate = providerWrapper.getDelegate();
        assertNotNull("providerWrapper delegate is null", delegate);
        assertFalse("providerWrapper delegate should not be an instance of ProviderWrapper", delegate instanceof ProviderWrapper);
    } finally {
        ProviderWrapper.afterCreate();
    }
}
Also used : Provider(javax.xml.ws.spi.Provider)

Example 2 with Provider

use of javax.xml.ws.spi.Provider in project tomee by apache.

the class JaxWsProviderWrapperTest method test.

public void test() throws Exception {
    System.setProperty(Provider.class.getName(), MockProvider.class.getName());
    Provider provider = Provider.provider();
    assertNotNull("provider is null", provider);
    assertFalse("provider should not be an instance of ProviderWrapper", provider instanceof JaxWsProviderWrapper);
    JaxWsProviderWrapper.beforeCreate(null);
    try {
        provider = Provider.provider();
        assertNotNull("provider is null", provider);
        assertTrue("provider should be an instance of ProviderWrapper", provider instanceof JaxWsProviderWrapper);
        final JaxWsProviderWrapper providerWrapper = (JaxWsProviderWrapper) provider;
        // check delegate
        final Provider delegate = providerWrapper.getDelegate();
        assertNotNull("providerWrapper delegate is null", delegate);
        assertFalse("providerWrapper delegate should not be an instance of ProviderWrapper", delegate instanceof JaxWsProviderWrapper);
    } finally {
        JaxWsProviderWrapper.afterCreate();
    }
}
Also used : Provider(javax.xml.ws.spi.Provider)

Example 3 with Provider

use of javax.xml.ws.spi.Provider in project tomee by apache.

the class JaxWsProviderWrapper method findProvider.

private static Provider findProvider() {
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    if (classLoader == null) {
        classLoader = ClassLoader.getSystemClassLoader();
    }
    // 0. System.getProperty("openejb.javax.xml.ws.spi.Provider")
    // This is so those using old axis rules still work as expected
    String providerClass = System.getProperty("openejb." + JAXWSPROVIDER_PROPERTY);
    Provider provider = createProviderInstance(providerClass, classLoader);
    if (provider != null) {
        return provider;
    }
    // 1. META-INF/services/javax.xml.ws.spi.Provider
    try {
        for (final URL url : Collections.list(classLoader.getResources("META-INF/services/" + JAXWSPROVIDER_PROPERTY))) {
            BufferedReader in = null;
            try {
                in = new BufferedReader(new InputStreamReader(url.openStream()));
                providerClass = in.readLine();
                provider = createProviderInstance(providerClass, classLoader);
                if (provider != null) {
                    return provider;
                }
            } catch (Exception ignored) {
            } finally {
                if (in != null) {
                    try {
                        in.close();
                    } catch (Throwable e) {
                    //ignore
                    }
                }
            }
        }
    } catch (Exception ingored) {
        logger.log(Level.INFO, "No META-INF/services/javax.xml.ws.spi.Provider found");
    }
    // 2. $java.home/lib/jaxws.properties
    final String javaHome = System.getProperty("java.home");
    final File jaxrpcPropertiesFile = new File(new File(javaHome, "lib"), "jaxrpc.properties");
    if (jaxrpcPropertiesFile.exists()) {
        InputStream in = null;
        try {
            in = new FileInputStream(jaxrpcPropertiesFile);
            final Properties properties = new Properties();
            properties.load(in);
            providerClass = properties.getProperty(JAXWSPROVIDER_PROPERTY);
            provider = createProviderInstance(providerClass, classLoader);
            if (provider != null) {
                return provider;
            }
        } catch (Exception ignored) {
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (Throwable e) {
                //Ignore
                }
            }
        }
    }
    // 3. System.getProperty("javax.xml.ws.spi.Provider")
    providerClass = System.getProperty(JAXWSPROVIDER_PROPERTY);
    provider = createProviderInstance(providerClass, classLoader);
    if (provider != null) {
        return provider;
    }
    // 4. Use javax.xml.ws.spi.Provider default
    try {
        // disable the OpenEJB JaxWS provider
        if (classLoader instanceof ProviderClassLoader) {
            ((ProviderClassLoader) classLoader).enabled = false;
        }
        System.getProperties().remove(JAXWSPROVIDER_PROPERTY);
        provider = Provider.provider();
        if (provider != null && !provider.getClass().getName().equals(JaxWsProviderWrapper.class.getName())) {
            return provider;
        }
    } finally {
        // reenable the OpenEJB JaxWS provider
        System.setProperty(JAXWSPROVIDER_PROPERTY, providerClass);
        if (classLoader instanceof ProviderClassLoader) {
            ((ProviderClassLoader) classLoader).enabled = true;
        }
    }
    throw new WebServiceException("No " + JAXWSPROVIDER_PROPERTY + " implementation found");
}
Also used : InputStreamReader(java.io.InputStreamReader) WebServiceException(javax.xml.ws.WebServiceException) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Properties(java.util.Properties) URL(java.net.URL) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) WebServiceException(javax.xml.ws.WebServiceException) FileInputStream(java.io.FileInputStream) Provider(javax.xml.ws.spi.Provider) BindingProvider(javax.xml.ws.BindingProvider) BufferedReader(java.io.BufferedReader) File(java.io.File)

Example 4 with Provider

use of javax.xml.ws.spi.Provider in project tomee by apache.

the class ProviderWrapper method findProvider.

private static Provider findProvider() {
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    if (classLoader == null) {
        classLoader = ClassLoader.getSystemClassLoader();
    }
    // 0. System.getProperty("openejb.javax.xml.ws.spi.Provider")
    // This is so those using old axis rules still work as expected
    String providerClass = JavaSecurityManagers.getSystemProperty("openejb." + JAXWSPROVIDER_PROPERTY);
    Provider provider = createProviderInstance(providerClass, classLoader);
    if (provider != null) {
        return provider;
    }
    // 1. META-INF/services/javax.xml.ws.spi.Provider
    try {
        for (final URL url : Collections.list(classLoader.getResources("META-INF/services/" + JAXWSPROVIDER_PROPERTY))) {
            BufferedReader in = null;
            try {
                in = new BufferedReader(new InputStreamReader(url.openStream()));
                providerClass = in.readLine();
                provider = createProviderInstance(providerClass, classLoader);
                if (provider != null) {
                    return provider;
                }
            } catch (final Exception ignored) {
            // no-op
            } finally {
                if (in != null) {
                    try {
                        in.close();
                    } catch (final IOException e) {
                    // no-op
                    }
                }
            }
        }
    } catch (final Exception ingored) {
    // no-op
    }
    // 2. $java.home/lib/jaxws.properties
    final String javaHome = JavaSecurityManagers.getSystemProperty("java.home");
    final File jaxrpcPropertiesFile = new File(new File(javaHome, "lib"), "jaxrpc.properties");
    if (jaxrpcPropertiesFile.exists()) {
        try {
            final Properties properties = IO.readProperties(jaxrpcPropertiesFile);
            providerClass = properties.getProperty(JAXWSPROVIDER_PROPERTY);
            provider = createProviderInstance(providerClass, classLoader);
            if (provider != null) {
                return provider;
            }
        } catch (final Exception ignored) {
        // no-op
        }
    }
    // 3. System.getProperty("javax.xml.ws.spi.Provider")
    providerClass = JavaSecurityManagers.getSystemProperty(JAXWSPROVIDER_PROPERTY);
    provider = createProviderInstance(providerClass, classLoader);
    if (provider != null) {
        return provider;
    }
    // 4. Use javax.xml.ws.spi.Provider default
    try {
        JavaSecurityManagers.removeSystemProperty(JAXWSPROVIDER_PROPERTY);
        provider = Provider.provider();
        if (provider != null && !provider.getClass().getName().equals(ProviderWrapper.class.getName())) {
            return provider;
        }
    } finally {
        // restore original jax provider property
        JavaSecurityManagers.setSystemProperty(JAXWSPROVIDER_PROPERTY, providerClass);
    }
    throw new WebServiceException("No " + JAXWSPROVIDER_PROPERTY + " implementation found");
}
Also used : InputStreamReader(java.io.InputStreamReader) WebServiceException(javax.xml.ws.WebServiceException) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) Properties(java.util.Properties) File(java.io.File) URL(java.net.URL) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) WebServiceException(javax.xml.ws.WebServiceException) OpenEJBRuntimeException(org.apache.openejb.OpenEJBRuntimeException) Provider(javax.xml.ws.spi.Provider) BindingProvider(javax.xml.ws.BindingProvider)

Aggregations

Provider (javax.xml.ws.spi.Provider)4 BufferedReader (java.io.BufferedReader)2 File (java.io.File)2 IOException (java.io.IOException)2 InputStreamReader (java.io.InputStreamReader)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 URL (java.net.URL)2 Properties (java.util.Properties)2 BindingProvider (javax.xml.ws.BindingProvider)2 WebServiceException (javax.xml.ws.WebServiceException)2 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 OpenEJBRuntimeException (org.apache.openejb.OpenEJBRuntimeException)1