Search in sources :

Example 1 with InjectionException

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);
}
Also used : InjectionException(com.sun.enterprise.container.common.spi.util.InjectionException) ServletAdapter(com.sun.xml.ws.transport.http.servlet.ServletAdapter) ServletContext(javax.servlet.ServletContext) Handler(javax.xml.ws.handler.Handler) ServletAdapterList(com.sun.xml.ws.transport.http.servlet.ServletAdapterList) InjectionManager(com.sun.enterprise.container.common.spi.util.InjectionManager)

Example 2 with InjectionException

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());
}
Also used : InjectionException(com.sun.enterprise.container.common.spi.util.InjectionException) ServletAdapter(com.sun.xml.ws.transport.http.servlet.ServletAdapter) Handler(javax.xml.ws.handler.Handler) ServletAdapterList(com.sun.xml.ws.transport.http.servlet.ServletAdapterList) WebServiceEngineImpl(org.glassfish.webservices.monitoring.WebServiceEngineImpl) InjectionManager(com.sun.enterprise.container.common.spi.util.InjectionManager)

Example 3 with InjectionException

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);
    }
}
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 4 with InjectionException

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;
}
Also used : StreamingHandler(com.sun.xml.rpc.spi.runtime.StreamingHandler) Handler(javax.xml.ws.handler.Handler) InjectionException(com.sun.enterprise.container.common.spi.util.InjectionException) InjectionManager(com.sun.enterprise.container.common.spi.util.InjectionManager)

Example 5 with InjectionException

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;
}
Also used : InjectionException(com.sun.enterprise.container.common.spi.util.InjectionException) JCDIService(com.sun.enterprise.container.common.spi.JCDIService) ManagedBean(javax.annotation.ManagedBean) NamingException(javax.naming.NamingException) InjectionException(com.sun.enterprise.container.common.spi.util.InjectionException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ManagedBeanManager(com.sun.enterprise.container.common.spi.ManagedBeanManager)

Aggregations

InjectionException (com.sun.enterprise.container.common.spi.util.InjectionException)16 InjectionManager (com.sun.enterprise.container.common.spi.util.InjectionManager)4 Method (java.lang.reflect.Method)4 ComponentInvocation (org.glassfish.api.invocation.ComponentInvocation)4 JndiNameEnvironment (com.sun.enterprise.deployment.JndiNameEnvironment)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 NamingException (javax.naming.NamingException)3 Handler (javax.xml.ws.handler.Handler)3 JCDIService (com.sun.enterprise.container.common.spi.JCDIService)2 ManagedBeanManager (com.sun.enterprise.container.common.spi.ManagedBeanManager)2 ComponentEnvManager (com.sun.enterprise.container.common.spi.util.ComponentEnvManager)2 InjectionTarget (com.sun.enterprise.deployment.InjectionTarget)2 ServletAdapter (com.sun.xml.ws.transport.http.servlet.ServletAdapter)2 ServletAdapterList (com.sun.xml.ws.transport.http.servlet.ServletAdapterList)2 ManagedBean (javax.annotation.ManagedBean)2 ServiceLocator (org.glassfish.hk2.api.ServiceLocator)2 InjectionCapable (com.sun.enterprise.deployment.InjectionCapable)1 ResourceReferenceDescriptor (com.sun.enterprise.deployment.ResourceReferenceDescriptor)1 WebBundleDescriptor (com.sun.enterprise.deployment.WebBundleDescriptor)1 AppServSecurityContext (com.sun.enterprise.security.integration.AppServSecurityContext)1