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);
}
}
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");
}
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");
}
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();
}
}
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());
}
}
Aggregations