Search in sources :

Example 6 with ComponentEnvManager

use of com.sun.enterprise.container.common.spi.util.ComponentEnvManager in project Payara by payara.

the class ServletWebServiceDelegate method postInit.

@Override
public void postInit(ServletConfig servletConfig) throws ServletException {
    String servletName = "unknown";
    try {
        WebServiceContractImpl wscImpl = WebServiceContractImpl.getInstance();
        ComponentEnvManager compEnvManager = wscImpl.getComponentEnvManager();
        JndiNameEnvironment jndiNameEnv = compEnvManager.getCurrentJndiNameEnvironment();
        WebBundleDescriptor webBundle = null;
        if (jndiNameEnv != null && jndiNameEnv instanceof WebBundleDescriptor) {
            webBundle = ((WebBundleDescriptor) jndiNameEnv);
        } else {
            throw new WebServiceException("Cannot intialize the JAXRPCServlet for " + jndiNameEnv);
        }
        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
        servletName = servletConfig.getServletName();
        WebComponentDescriptor webComponent = webBundle.getWebComponentByCanonicalName(servletName);
        if (webComponent != null) {
            WebServicesDescriptor webServices = webBundle.getWebServices();
            Collection endpoints = webServices.getEndpointsImplementedBy(webComponent);
            // Only 1 endpoint per servlet is supported, even though
            // data structure implies otherwise.
            endpoint_ = (WebServiceEndpoint) endpoints.iterator().next();
            registerEndpoint(classLoader);
            // security
            if (secServ != null) {
                SystemHandlerDelegate securityHandlerDelegate = secServ.getSecurityHandler(endpoint_);
                if (securityHandlerDelegate != null) {
                    rpcDelegate_.setSystemHandlerDelegate(securityHandlerDelegate);
                    // need to invoke the endpoint lifecylcle
                    endpointImpl_ = JAXRPCEndpointImpl.class.cast(wsEngine_.createHandler(securityHandlerDelegate, endpoint_));
                    rpcDelegate_.setSystemHandlerDelegate(endpointImpl_);
                }
            }
        } else {
            throw new ServletException(servletName + " not found");
        }
    } catch (Throwable t) {
        String msg = MessageFormat.format(logger.getResourceBundle().getString(LogUtils.SERVLET_ENDPOINT_FAILURE), servletName);
        logger.log(Level.WARNING, msg, t);
        throw new ServletException(t);
    }
}
Also used : WebServicesDescriptor(com.sun.enterprise.deployment.WebServicesDescriptor) WebServiceException(javax.xml.ws.WebServiceException) ComponentEnvManager(com.sun.enterprise.container.common.spi.util.ComponentEnvManager) SystemHandlerDelegate(com.sun.xml.rpc.spi.runtime.SystemHandlerDelegate) WebComponentDescriptor(com.sun.enterprise.deployment.WebComponentDescriptor) JndiNameEnvironment(com.sun.enterprise.deployment.JndiNameEnvironment) WebBundleDescriptor(com.sun.enterprise.deployment.WebBundleDescriptor) JAXRPCEndpointImpl(org.glassfish.webservices.monitoring.JAXRPCEndpointImpl)

Example 7 with ComponentEnvManager

use of com.sun.enterprise.container.common.spi.util.ComponentEnvManager in project Payara by payara.

the class WSServletContextListener method contextInitialized.

@Override
public void contextInitialized(ServletContextEvent sce) {
    WebServiceContractImpl wscImpl = WebServiceContractImpl.getInstance();
    ComponentEnvManager compEnvManager = wscImpl.getComponentEnvManager();
    JndiNameEnvironment jndiNameEnv = compEnvManager.getCurrentJndiNameEnvironment();
    WebBundleDescriptor webBundle = null;
    if (jndiNameEnv != null && jndiNameEnv instanceof BundleDescriptor && ((BundleDescriptor) jndiNameEnv).getModuleType().equals(DOLUtils.warType())) {
        webBundle = ((WebBundleDescriptor) jndiNameEnv);
    } else {
        throw new WebServiceException("Cannot intialize the JAXWSServlet for " + jndiNameEnv);
    }
    contextRoot = webBundle.getContextRoot();
    WebServicesDescriptor webServices = webBundle.getWebServices();
    try {
        for (WebServiceEndpoint endpoint : webServices.getEndpoints()) {
            registerEndpoint(endpoint, sce.getServletContext());
        }
    } catch (Throwable t) {
        // TODO Fix Rama
        logger.log(Level.WARNING, LogUtils.DEPLOYMENT_FAILED, t);
        sce.getServletContext().removeAttribute("ADAPTER_LIST");
        throw new RuntimeException("Servlet web service endpoint '" + "' failure", t);
    }
}
Also used : WebServiceException(javax.xml.ws.WebServiceException) ComponentEnvManager(com.sun.enterprise.container.common.spi.util.ComponentEnvManager)

Example 8 with ComponentEnvManager

use of com.sun.enterprise.container.common.spi.util.ComponentEnvManager in project Payara by payara.

the class JAXWSServlet method init.

public void init(ServletConfig servletConfig) throws ServletException {
    String servletName = "unknown";
    try {
        super.init(servletConfig);
        wsEngine_ = WebServiceEngineImpl.getInstance();
        // Register endpoints here
        WebServiceContractImpl wscImpl = WebServiceContractImpl.getInstance();
        ComponentEnvManager compEnvManager = wscImpl.getComponentEnvManager();
        JndiNameEnvironment jndiNameEnv = compEnvManager.getCurrentJndiNameEnvironment();
        WebBundleDescriptor webBundle = null;
        if (jndiNameEnv != null && jndiNameEnv instanceof WebBundleDescriptor) {
            webBundle = ((WebBundleDescriptor) jndiNameEnv);
        } else {
            throw new WebServiceException("Cannot intialize the JAXWSServlet for " + jndiNameEnv);
        }
        servletName = servletConfig.getServletName();
        contextRoot = webBundle.getContextRoot();
        WebComponentDescriptor webComponent = webBundle.getWebComponentByCanonicalName(servletName);
        if (webComponent != null) {
            WebServicesDescriptor webServices = webBundle.getWebServices();
            Collection<WebServiceEndpoint> endpoints = webServices.getEndpointsImplementedBy(webComponent);
            // Only 1 endpoint per servlet is supported, even though
            // data structure implies otherwise.
            endpoint = endpoints.iterator().next();
        } else {
            throw new ServletException(servletName + " not found");
        }
        // need to invoke the endpoint lifecylcle
        if (!(HTTPBinding.HTTP_BINDING.equals(endpoint.getProtocolBinding()))) {
            // Doing this so that restful service are not monitored
            wsEngine_.createHandler(endpoint);
        }
        if (endpoint.getWsdlExposed() != null) {
            wsdlExposed = Boolean.parseBoolean(endpoint.getWsdlExposed());
        }
        // For web components, this will be relative to the web app
        // context root.  Make sure there is a leading slash.
        String uri = endpoint.getEndpointAddressUri();
        urlPattern = uri.startsWith("/") ? uri : "/" + uri;
    } catch (Throwable t) {
        String msg = MessageFormat.format(logger.getResourceBundle().getString(LogUtils.SERVLET_ENDPOINT_FAILURE), servletName);
        logger.log(Level.WARNING, msg, t);
        throw new ServletException(t);
    }
    requestTracing = org.glassfish.internal.api.Globals.getDefaultHabitat().getService(RequestTracingService.class);
}
Also used : WebServiceException(javax.xml.ws.WebServiceException) ComponentEnvManager(com.sun.enterprise.container.common.spi.util.ComponentEnvManager) RequestTracingService(fish.payara.nucleus.requesttracing.RequestTracingService) ServletException(javax.servlet.ServletException)

Example 9 with ComponentEnvManager

use of com.sun.enterprise.container.common.spi.util.ComponentEnvManager in project Payara by payara.

the class JavaModuleNamingProxy method getAppName.

private String getAppName() throws NamingException {
    ComponentEnvManager namingMgr = habitat.getService(ComponentEnvManager.class);
    String appName = null;
    if (namingMgr != null) {
        JndiNameEnvironment env = namingMgr.getCurrentJndiNameEnvironment();
        BundleDescriptor bd = null;
        if (env instanceof EjbDescriptor) {
            bd = ((EjbDescriptor) env).getEjbBundleDescriptor();
        } else if (env instanceof BundleDescriptor) {
            bd = (BundleDescriptor) env;
        }
        if (bd != null) {
            Application app = bd.getApplication();
            appName = app.getAppName();
        } else {
            ApplicationEnvironment applicationEnvironment = namingMgr.getCurrentApplicationEnvironment();
            if (applicationEnvironment != null) {
                appName = applicationEnvironment.getName();
            }
        }
    }
    if (appName == null) {
        throw new NamingException("Could not resolve " + JAVA_APP_NAME);
    }
    return appName;
}
Also used : ComponentEnvManager(com.sun.enterprise.container.common.spi.util.ComponentEnvManager) NamingException(javax.naming.NamingException) ApplicationEnvironment(org.glassfish.api.invocation.ApplicationEnvironment)

Example 10 with ComponentEnvManager

use of com.sun.enterprise.container.common.spi.util.ComponentEnvManager in project Payara by payara.

the class JavaModuleNamingProxy method getJavaModuleOrAppEJB.

private Object getJavaModuleOrAppEJB(String name) throws NamingException {
    String newName = null;
    Object returnValue = null;
    if (habitat != null) {
        ComponentEnvManager namingMgr = habitat.getService(ComponentEnvManager.class);
        if (namingMgr != null) {
            JndiNameEnvironment env = namingMgr.getCurrentJndiNameEnvironment();
            BundleDescriptor bd = null;
            if (env instanceof EjbDescriptor) {
                bd = ((EjbDescriptor) env).getEjbBundleDescriptor();
            } else if (env instanceof BundleDescriptor) {
                bd = (BundleDescriptor) env;
            }
            if (bd != null) {
                Application app = bd.getApplication();
                String appName = null;
                if (!app.isVirtual()) {
                    appName = app.getAppName();
                }
                String moduleName = bd.getModuleDescriptor().getModuleName();
                StringBuffer javaGlobalName = new StringBuffer("java:global/");
                if (name.startsWith(JAVA_APP_CONTEXT)) {
                    if (appName != null) {
                        javaGlobalName.append(appName);
                        javaGlobalName.append("/");
                    }
                    // Replace java:app/ with the fully-qualified global portion
                    int javaAppLength = JAVA_APP_CONTEXT.length();
                    javaGlobalName.append(name.substring(javaAppLength));
                } else {
                    if (appName != null) {
                        javaGlobalName.append(appName);
                        javaGlobalName.append("/");
                    }
                    javaGlobalName.append(moduleName);
                    javaGlobalName.append("/");
                    // Replace java:module/ with the fully-qualified global portion
                    int javaModuleLength = JAVA_MODULE_CONTEXT.length();
                    javaGlobalName.append(name.substring(javaModuleLength));
                }
                newName = javaGlobalName.toString();
            }
        }
    }
    if (newName != null) {
        try {
            if (processType == ProcessType.ACC) {
                ManagedBeanManager mbMgr = habitat.getService(ManagedBeanManager.class);
                try {
                    returnValue = mbMgr.getManagedBean(newName);
                } catch (Exception e) {
                    NamingException ne = new NamingException("Error creating ACC managed bean " + newName);
                    ne.initCause(e);
                    throw ne;
                }
            }
            if (returnValue == null) {
                returnValue = ic.lookup(newName);
            }
        } catch (NamingException ne) {
            _logger.log(Level.FINE, newName + " Unable to map " + name + " to derived name " + newName, ne);
        }
    }
    return returnValue;
}
Also used : ComponentEnvManager(com.sun.enterprise.container.common.spi.util.ComponentEnvManager) NamingException(javax.naming.NamingException) NamingException(javax.naming.NamingException) ManagedBeanManager(com.sun.enterprise.container.common.spi.ManagedBeanManager)

Aggregations

ComponentEnvManager (com.sun.enterprise.container.common.spi.util.ComponentEnvManager)13 NamingException (javax.naming.NamingException)4 WebServiceException (javax.xml.ws.WebServiceException)3 ManagedBeanManager (com.sun.enterprise.container.common.spi.ManagedBeanManager)2 InjectionException (com.sun.enterprise.container.common.spi.util.InjectionException)2 JndiNameEnvironment (com.sun.enterprise.deployment.JndiNameEnvironment)2 WebBundleDescriptor (com.sun.enterprise.deployment.WebBundleDescriptor)2 java.util (java.util)2 InvocationManager (org.glassfish.api.invocation.InvocationManager)2 ServiceLocator (org.glassfish.hk2.api.ServiceLocator)2 BundleDescriptor (com.sun.enterprise.deployment.BundleDescriptor)1 EjbBundleDescriptor (com.sun.enterprise.deployment.EjbBundleDescriptor)1 EjbDescriptor (com.sun.enterprise.deployment.EjbDescriptor)1 WebComponentDescriptor (com.sun.enterprise.deployment.WebComponentDescriptor)1 WebServicesDescriptor (com.sun.enterprise.deployment.WebServicesDescriptor)1 SystemHandlerDelegate (com.sun.xml.rpc.spi.runtime.SystemHandlerDelegate)1 RequestTracingService (fish.payara.nucleus.requesttracing.RequestTracingService)1 String (java.lang.String)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1