Search in sources :

Example 66 with WebServiceException

use of javax.xml.ws.WebServiceException in project Payara by payara.

the class ResourceInjectorImpl method inject.

public void inject(WSWebServiceContext context, Object instance) throws WebServiceException {
    try {
        // Set proper component context
        invMgr.preInvoke(inv);
        // Injection first
        InjectionManager injManager = WebServiceContractImpl.getInstance().getInjectionManager();
        injManager.injectInstance(instance);
        // Set webservice context here
        // If the endpoint has a WebServiceContext with @Resource then
        // that has to be used
        WebServiceContextImpl wsc = null;
        WebBundleDescriptor bundle = (WebBundleDescriptor) endpoint.getBundleDescriptor();
        Iterator<ResourceReferenceDescriptor> it = bundle.getResourceReferenceDescriptors().iterator();
        while (it.hasNext()) {
            ResourceReferenceDescriptor r = it.next();
            if (r.isWebServiceContext()) {
                Iterator<InjectionTarget> iter = r.getInjectionTargets().iterator();
                boolean matchingClassFound = false;
                while (iter.hasNext()) {
                    InjectionTarget target = iter.next();
                    if (endpoint.getServletImplClass().equals(target.getClassName())) {
                        matchingClassFound = true;
                        break;
                    }
                }
                if (!matchingClassFound) {
                    continue;
                }
                try {
                    javax.naming.InitialContext ic = new javax.naming.InitialContext();
                    wsc = (WebServiceContextImpl) ic.lookup("java:comp/env/" + r.getName());
                } catch (Throwable t) {
                    // Do something here
                    if (logger.isLoggable(Level.FINE)) {
                        logger.log(Level.FINE, LogUtils.EXCEPTION_THROWN, t);
                    }
                }
                if (wsc != null) {
                    wsc.setContextDelegate(context);
                    // needed to support isUserInRole() on WSC;
                    wsc.setServletName(bundle.getWebComponentDescriptors());
                }
            }
        }
    } catch (InjectionException ie) {
        throw new WebServiceException(ie);
    } finally {
        invMgr.postInvoke(inv);
    }
}
Also used : WebServiceException(javax.xml.ws.WebServiceException) InjectionException(com.sun.enterprise.container.common.spi.util.InjectionException) WebBundleDescriptor(com.sun.enterprise.deployment.WebBundleDescriptor) InjectionTarget(com.sun.enterprise.deployment.InjectionTarget) ResourceReferenceDescriptor(com.sun.enterprise.deployment.ResourceReferenceDescriptor) InjectionManager(com.sun.enterprise.container.common.spi.util.InjectionManager)

Example 67 with WebServiceException

use of javax.xml.ws.WebServiceException 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 68 with WebServiceException

use of javax.xml.ws.WebServiceException 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)

Example 69 with WebServiceException

use of javax.xml.ws.WebServiceException in project spring-framework by spring-projects.

the class JaxWsSupportTests method doTestJaxWsPortAccess.

private void doTestJaxWsPortAccess(WebServiceFeature... features) throws Exception {
    GenericApplicationContext ac = new GenericApplicationContext();
    GenericBeanDefinition serviceDef = new GenericBeanDefinition();
    serviceDef.setBeanClass(OrderServiceImpl.class);
    ac.registerBeanDefinition("service", serviceDef);
    GenericBeanDefinition exporterDef = new GenericBeanDefinition();
    exporterDef.setBeanClass(SimpleJaxWsServiceExporter.class);
    exporterDef.getPropertyValues().add("baseAddress", "http://localhost:9999/");
    ac.registerBeanDefinition("exporter", exporterDef);
    GenericBeanDefinition clientDef = new GenericBeanDefinition();
    clientDef.setBeanClass(JaxWsPortProxyFactoryBean.class);
    clientDef.getPropertyValues().add("wsdlDocumentUrl", "http://localhost:9999/OrderService?wsdl");
    clientDef.getPropertyValues().add("namespaceUri", "http://jaxws.remoting.springframework.org/");
    clientDef.getPropertyValues().add("username", "juergen");
    clientDef.getPropertyValues().add("password", "hoeller");
    clientDef.getPropertyValues().add("serviceName", "OrderService");
    clientDef.getPropertyValues().add("serviceInterface", OrderService.class);
    clientDef.getPropertyValues().add("lookupServiceOnStartup", Boolean.FALSE);
    if (features != null) {
        clientDef.getPropertyValues().add("portFeatures", features);
    }
    ac.registerBeanDefinition("client", clientDef);
    GenericBeanDefinition serviceFactoryDef = new GenericBeanDefinition();
    serviceFactoryDef.setBeanClass(LocalJaxWsServiceFactoryBean.class);
    serviceFactoryDef.getPropertyValues().add("wsdlDocumentUrl", "http://localhost:9999/OrderService?wsdl");
    serviceFactoryDef.getPropertyValues().add("namespaceUri", "http://jaxws.remoting.springframework.org/");
    serviceFactoryDef.getPropertyValues().add("serviceName", "OrderService");
    ac.registerBeanDefinition("orderService", serviceFactoryDef);
    ac.registerBeanDefinition("accessor", new RootBeanDefinition(ServiceAccessor.class));
    AnnotationConfigUtils.registerAnnotationConfigProcessors(ac);
    try {
        ac.refresh();
        OrderService orderService = ac.getBean("client", OrderService.class);
        assertTrue(orderService instanceof BindingProvider);
        ((BindingProvider) orderService).getRequestContext();
        String order = orderService.getOrder(1000);
        assertEquals("order 1000", order);
        try {
            orderService.getOrder(0);
            fail("Should have thrown OrderNotFoundException");
        } catch (OrderNotFoundException ex) {
        // expected
        } catch (RemoteAccessException ex) {
        // ignore - probably setup issue with JAX-WS provider vs JAXB
        }
        ServiceAccessor serviceAccessor = ac.getBean("accessor", ServiceAccessor.class);
        order = serviceAccessor.orderService.getOrder(1000);
        assertEquals("order 1000", order);
        try {
            serviceAccessor.orderService.getOrder(0);
            fail("Should have thrown OrderNotFoundException");
        } catch (OrderNotFoundException ex) {
        // expected
        } catch (WebServiceException ex) {
        // ignore - probably setup issue with JAX-WS provider vs JAXB
        }
    } catch (BeanCreationException ex) {
        if ("exporter".equals(ex.getBeanName()) && ex.getRootCause() instanceof ClassNotFoundException) {
        // ignore - probably running on JDK without the JAX-WS impl present
        } else {
            throw ex;
        }
    } finally {
        ac.close();
    }
}
Also used : GenericBeanDefinition(org.springframework.beans.factory.support.GenericBeanDefinition) BeanCreationException(org.springframework.beans.factory.BeanCreationException) GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) WebServiceException(javax.xml.ws.WebServiceException) RemoteAccessException(org.springframework.remoting.RemoteAccessException) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) BindingProvider(javax.xml.ws.BindingProvider)

Example 70 with WebServiceException

use of javax.xml.ws.WebServiceException in project wildfly by wildfly.

the class EJBEndpointNoClassLevelSecurityAnnotationAuthenticationTestCase method accessHelloForNoneWithValidRole2.

@Test
public void accessHelloForNoneWithValidRole2() throws Exception {
    URL wsdlURL = new URL(baseUrl, deploymentWsdlURL);
    Service service = Service.create(wsdlURL, serviceName);
    EJBEndpointIface proxy = service.getPort(EJBEndpointIface.class);
    Map<String, Object> reqContext = ((BindingProvider) proxy).getRequestContext();
    reqContext.put(BindingProvider.USERNAME_PROPERTY, "user2");
    reqContext.put(BindingProvider.PASSWORD_PROPERTY, "password2");
    try {
        proxy.helloForNone("World");
        Assert.fail("Test should fail, user shouldn't be allowed to invoke that method");
    } catch (WebServiceException e) {
        // failure is expected
        Assert.assertEquals(getNotAllowedExceptionMessage("helloForNone"), e.getCause().getMessage());
    }
}
Also used : WebServiceException(javax.xml.ws.WebServiceException) Service(javax.xml.ws.Service) BindingProvider(javax.xml.ws.BindingProvider) URL(java.net.URL) Test(org.junit.Test)

Aggregations

WebServiceException (javax.xml.ws.WebServiceException)120 Test (org.junit.Test)50 URL (java.net.URL)37 BindingProvider (javax.xml.ws.BindingProvider)25 Service (javax.xml.ws.Service)22 QName (javax.xml.namespace.QName)14 IOException (java.io.IOException)10 Message (org.apache.cxf.common.i18n.Message)9 JAXBException (javax.xml.bind.JAXBException)8 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)8 Bus (org.apache.cxf.Bus)7 Packet (com.sun.xml.ws.api.message.Packet)6 AuthStatus (javax.security.auth.message.AuthStatus)6 SOAPException (javax.xml.soap.SOAPException)6 SOAPMessage (javax.xml.soap.SOAPMessage)6 ArrayList (java.util.ArrayList)5 WebService (javax.jws.WebService)5 Subject (javax.security.auth.Subject)5 HttpSession (javax.servlet.http.HttpSession)5 Handler (javax.xml.ws.handler.Handler)5