use of com.sun.enterprise.container.common.spi.util.InjectionException in project Payara by payara.
the class WSServletContextListener method contextDestroyed.
@Override
public void contextDestroyed(ServletContextEvent sce) {
ServletContext servletContext = sce.getServletContext();
synchronized (this) {
ServletAdapterList list = (ServletAdapterList) servletContext.getAttribute("ADAPTER_LIST");
if (list != null) {
for (ServletAdapter x : list) {
x.getEndpoint().dispose();
for (Handler handler : x.getEndpoint().getBinding().getHandlerChain()) {
try {
WebServiceContractImpl wscImpl = WebServiceContractImpl.getInstance();
InjectionManager injManager = wscImpl.getInjectionManager();
injManager.destroyManagedObject(handler);
} catch (InjectionException e) {
logger.log(Level.WARNING, LogUtils.DESTORY_ON_HANDLER_FAILED, new Object[] { handler.getClass(), x.getEndpoint().getServiceName(), e.getMessage() });
continue;
}
}
}
servletContext.removeAttribute("ADAPTER_LIST");
}
JAXWSAdapterRegistry.getInstance().removeAdapter(contextRoot);
/*
Fix for bug 3932/4052 since the x.getEndpoint().dispose is being
called above we do not need to call this explicitly
try {
(new WsUtil()).doPreDestroy(endpoint, classLoader);
} catch (Throwable t) {
logger.log(Level.WARNING, "@PreDestroy lifecycle call failed for service"
+ endpoint.getName(), t);
}*/
}
JAXWSServletModule.destroy(contextRoot);
}
use of com.sun.enterprise.container.common.spi.util.InjectionException in project Payara by payara.
the class WebServiceEjbEndpointRegistry method unregisterEndpoint.
@Override
public void unregisterEndpoint(String endpointAddressUri) {
EjbRuntimeEndpointInfo endpoint = null;
synchronized (webServiceEjbEndpoints) {
String uriRaw = endpointAddressUri;
String uri = (uriRaw.charAt(0) == '/') ? uriRaw.substring(1) : uriRaw;
ServletAdapterList list = adapterListMap.get(uri);
if (list != null) {
// since we are using the uri in the adapterListMap
for (ServletAdapter x : list) {
x.getEndpoint().dispose();
for (Handler handler : x.getEndpoint().getBinding().getHandlerChain()) {
try {
WebServiceContractImpl wscImpl = WebServiceContractImpl.getInstance();
if (wscImpl.getInvocationManager().getCurrentInvocation() != null) {
InjectionManager injManager = wscImpl.getInjectionManager();
injManager.destroyManagedObject(handler);
}
} catch (InjectionException e) {
logger.log(Level.WARNING, LogUtils.DESTORY_ON_HANDLER_FAILED, new Object[] { handler.getClass(), x.getEndpoint().getServiceName(), e.getMessage() });
continue;
}
}
}
// Fix for issue 9523
adapterListMap.remove(uri);
}
endpoint = (EjbRuntimeEndpointInfo) webServiceEjbEndpoints.remove(uri);
regenerateEjbContextRoots();
}
if (endpoint == null) {
return;
}
// notify the monitoring layers that an endpoint is destroyed
WebServiceEngineImpl engine = WebServiceEngineImpl.getInstance();
engine.removeHandler(endpoint.getEndpoint());
}
use of com.sun.enterprise.container.common.spi.util.InjectionException 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 com.sun.enterprise.container.common.spi.util.InjectionException in project Payara by payara.
the class WsUtil method processConfiguredHandlers.
private List<Handler> processConfiguredHandlers(List<WebServiceHandler> handlersList, Set<String> roles) {
List<Handler> handlerChain = new ArrayList<Handler>();
for (WebServiceHandler h : handlersList) {
Handler handler = null;
ClassLoader loader = Thread.currentThread().getContextClassLoader();
// Get Handler Class instance
Class handlerClass;
try {
handlerClass = Class.forName(h.getHandlerClass(), true, loader);
} catch (Throwable t) {
String msg = MessageFormat.format(logger.getResourceBundle().getString(LogUtils.HANDLER_UNABLE_TO_ADD), h.getHandlerClass());
logger.log(Level.SEVERE, msg, t);
continue;
}
// perform injection
try {
WebServiceContractImpl wscImpl = WebServiceContractImpl.getInstance();
InjectionManager injManager = wscImpl.getInjectionManager();
// PostConstruct is invoked by createManagedObject as well
handler = (Handler) injManager.createManagedObject(handlerClass);
} catch (InjectionException e) {
logger.log(Level.SEVERE, LogUtils.HANDLER_INJECTION_FAILED, new Object[] { h.getHandlerClass(), e.getMessage() });
continue;
}
// Add soap-roles
Collection<String> rolesColl = h.getSoapRoles();
roles.addAll(rolesColl);
// Add this handler to the mail list
handlerChain.add(handler);
}
return handlerChain;
}
use of com.sun.enterprise.container.common.spi.util.InjectionException in project Payara by payara.
the class InjectionManagerImpl method createManagedObject.
/**
* Create a managed object for the given class. The object will be injected and if invokePostConstruct is true,
* any @PostConstruct methods on the instance's class(and super-classes) will be invoked after injection. The returned
* object can be cast to the clazz type but is not necessarily a direct reference to the managed instance. All
* invocations on the returned object should be on its public methods.
*
* It is the responsibility of the caller to destroy the returned object by calling destroyManagedObject(Object
* managedObject).
*
* @param clazz
* Class to be instantiated
* @param invokePostConstruct
* if true, invoke any @PostConstruct methods on the instance's class(and super-classes) after injection.
* @return managed object
* @throws InjectionException
*/
public <T> T createManagedObject(Class<T> clazz, boolean invokePostConstruct) throws InjectionException {
T managedObject = null;
try {
ManagedBean managedBeanAnn = clazz.getAnnotation(ManagedBean.class);
ManagedBeanManager managedBeanMgr = serviceLocator.getService(ManagedBeanManager.class);
if (managedBeanAnn != null) {
// EE style @ManagedBean
// Create , inject, and call PostConstruct (if necessary) via managed bean manager
managedObject = managedBeanMgr.createManagedBean(clazz, invokePostConstruct);
} else {
JCDIService jcdiService = serviceLocator.getService(JCDIService.class);
if ((jcdiService != null) && jcdiService.isCurrentModuleJCDIEnabled()) {
// Create , inject, and call PostConstruct (if necessary) via managed bean manager
managedObject = managedBeanMgr.createManagedBean(clazz, invokePostConstruct);
} else {
// Not in a 299-enabled module and not annoated with @ManagedBean, so
// just instantiate using new and perform injection
Constructor<T> noArgCtor = clazz.getConstructor();
managedObject = noArgCtor.newInstance();
// Inject and call PostConstruct if necessary
injectInstance(managedObject, invokePostConstruct);
}
}
} catch (Exception e) {
throw new InjectionException(localStrings.getLocalString("injection-manager.error-creating-managed-object", "Error creating managed object for class: {0}", clazz), e);
}
return managedObject;
}
Aggregations