Search in sources :

Example 1 with WebServiceContext

use of jakarta.xml.ws.WebServiceContext in project tomee by apache.

the class JndiEncBuilder method buildMap.

public Map<String, Object> buildMap(final JndiScope scope) throws OpenEJBException {
    // let it be sorted for real binding
    final Map<String, Object> bindings = new TreeMap<>();
    // get JtaEntityManagerRegistry
    final JtaEntityManagerRegistry jtaEntityManagerRegistry = SystemInstance.get().getComponent(JtaEntityManagerRegistry.class);
    for (final EjbReferenceInfo referenceInfo : jndiEnc.ejbReferences) {
        final Reference reference;
        if (referenceInfo.location != null) {
            reference = buildReferenceLocation(referenceInfo.location);
        } else if (referenceInfo.ejbDeploymentId == null) {
            reference = new LazyEjbReference(new Ref(referenceInfo), moduleUri, useCrossClassLoaderRef);
        } else {
            final String jndiName = "openejb/Deployment/" + JndiBuilder.format(referenceInfo.ejbDeploymentId, referenceInfo.interfaceClassName, referenceInfo.localbean ? InterfaceType.LOCALBEAN : InterfaceType.BUSINESS_REMOTE);
            if (useCrossClassLoaderRef && referenceInfo.externalReference) {
                reference = new CrossClassLoaderJndiReference(jndiName);
            } else {
                reference = new IntraVmJndiReference(jndiName);
            }
        }
        bindings.put(normalize(referenceInfo.referenceName), reference);
    }
    for (final EjbReferenceInfo referenceInfo : jndiEnc.ejbLocalReferences) {
        final Reference reference;
        if (referenceInfo.location != null) {
            reference = buildReferenceLocation(referenceInfo.location);
        } else if (referenceInfo.ejbDeploymentId == null) {
            reference = new LazyEjbReference(new Ref(referenceInfo), moduleUri, false);
        } else {
            final String jndiName = "openejb/Deployment/" + JndiBuilder.format(referenceInfo.ejbDeploymentId, referenceInfo.interfaceClassName, referenceInfo.localbean ? InterfaceType.LOCALBEAN : InterfaceType.BUSINESS_LOCAL);
            reference = new IntraVmJndiReference(jndiName);
        }
        bindings.put(normalize(referenceInfo.referenceName), reference);
    }
    for (final EnvEntryInfo entry : jndiEnc.envEntries) {
        if (entry.location != null) {
            final Reference reference = buildReferenceLocation(entry.location);
            bindings.put(normalize(entry.referenceName), reference);
            continue;
        }
        // It is possible that the value and location are both null, as it is allowed to use @Resource(name="java:global/env/abc") with no value is specified in DD
        if (entry.value == null) {
            continue;
        }
        try {
            final Class type = Classes.deprimitivize(getType(entry.type, entry));
            final Object obj;
            if (type == String.class) {
                obj = new String(entry.value);
            } else if (type == Double.class) {
                obj = new Double(entry.value);
            } else if (type == Integer.class) {
                obj = new Integer(entry.value);
            } else if (type == Long.class) {
                obj = new Long(entry.value);
            } else if (type == Float.class) {
                obj = new Float(entry.value);
            } else if (type == Short.class) {
                obj = new Short(entry.value);
            } else if (type == Boolean.class) {
                obj = Boolean.valueOf(entry.value);
            } else if (type == Byte.class) {
                obj = new Byte(entry.value);
            } else if (type == Character.class) {
                final StringBuilder sb = new StringBuilder(entry.value + " ");
                obj = sb.charAt(0);
            } else if (type == URL.class) {
                obj = new URL(entry.value);
            } else if (type == Class.class) {
                obj = new ClassReference(entry.value.trim());
            } else if (type.isEnum()) {
                obj = Enum.valueOf(type, entry.value.trim());
            } else {
                throw new IllegalArgumentException("Invalid env-entry-type " + type);
            }
            bindings.put(normalize(entry.referenceName), obj);
        } catch (final NumberFormatException e) {
            throw new IllegalArgumentException("The env-entry-value for entry " + entry.referenceName + " was not recognizable as type " + entry.type + ". Received Message: " + e.getLocalizedMessage(), e);
        } catch (final MalformedURLException e) {
            throw new IllegalArgumentException("URL for reference " + entry.referenceName + " was not a valid URL: " + entry.value, e);
        }
    }
    for (final ResourceReferenceInfo referenceInfo : jndiEnc.resourceRefs) {
        if (!(referenceInfo instanceof ContextReferenceInfo)) {
            if (referenceInfo.location != null) {
                final Reference reference = buildReferenceLocation(referenceInfo.location);
                bindings.put(normalize(referenceInfo.referenceName), reference);
                continue;
            }
            final Class<?> type = getType(referenceInfo.referenceType, referenceInfo);
            final Object reference;
            if (URL.class.equals(type)) {
                reference = new URLReference(referenceInfo.resourceID);
            } else if (type.isAnnotationPresent(ManagedBean.class)) {
                final ManagedBean managed = type.getAnnotation(ManagedBean.class);
                final String name = managed.value().length() == 0 ? type.getSimpleName() : managed.value();
                reference = new LinkRef("module/" + name);
            } else if (referenceInfo.resourceID != null) {
                final String jndiName = "openejb/Resource/" + referenceInfo.resourceID;
                reference = new IntraVmJndiReference(jndiName);
            } else {
                final String jndiName = "openejb/Resource/" + referenceInfo.referenceName;
                reference = new IntraVmJndiReference(jndiName);
            }
            bindings.put(normalize(referenceInfo.referenceName), reference);
        } else {
            final Class<?> type = getType(referenceInfo.referenceType, referenceInfo);
            final Object reference;
            if (Request.class.equals(type)) {
                reference = new ObjectReference(ThreadLocalContextManager.REQUEST);
            } else if (HttpServletRequest.class.equals(type)) {
                reference = new ObjectReference(ThreadLocalContextManager.HTTP_SERVLET_REQUEST);
            } else if (ServletRequest.class.equals(type)) {
                reference = new ObjectReference(ThreadLocalContextManager.SERVLET_REQUEST);
            } else if (UriInfo.class.equals(type)) {
                reference = new ObjectReference(ThreadLocalContextManager.URI_INFO);
            } else if (HttpHeaders.class.equals(type)) {
                reference = new ObjectReference(ThreadLocalContextManager.HTTP_HEADERS);
            } else if (SecurityContext.class.equals(type)) {
                reference = new ObjectReference(ThreadLocalContextManager.SECURITY_CONTEXT);
            } else if (ContextResolver.class.equals(type)) {
                reference = new ObjectReference(ThreadLocalContextManager.CONTEXT_RESOLVER);
            } else if (Providers.class.equals(type)) {
                reference = new ObjectReference(ThreadLocalContextManager.PROVIDERS);
            } else if (ServletConfig.class.equals(type)) {
                reference = new ObjectReference(ThreadLocalContextManager.SERVLET_CONFIG);
            } else if (ServletContext.class.equals(type)) {
                reference = new ObjectReference(ThreadLocalContextManager.SERVLET_CONTEXT);
            } else if (HttpServletResponse.class.equals(type)) {
                reference = new ObjectReference(ThreadLocalContextManager.HTTP_SERVLET_RESPONSE);
            } else if (jakarta.ws.rs.container.ResourceInfo.class.equals(type)) {
                reference = new ObjectReference(ThreadLocalContextManager.RESOURCE_INFO);
            } else if (ResourceContext.class.equals(type)) {
                reference = new ObjectReference(ThreadLocalContextManager.RESOURCE_CONTEXT);
            } else if (Configuration.class.equals(type)) {
                reference = new ObjectReference(ThreadLocalContextManager.CONFIGURATION);
            } else if (Application.class.equals(type)) {
                reference = new ObjectReference(ThreadLocalContextManager.APPLICATION);
            } else {
                reference = new MapObjectReference(ThreadLocalContextManager.OTHERS, referenceInfo.referenceType);
            }
            bindings.put(normalize(referenceInfo.referenceName), reference);
        }
    }
    for (final ResourceEnvReferenceInfo referenceInfo : jndiEnc.resourceEnvRefs) {
        if (referenceInfo.location != null) {
            final Reference reference = buildReferenceLocation(referenceInfo.location);
            bindings.put(normalize(referenceInfo.referenceName), reference);
            continue;
        }
        final Class<?> type = getType(referenceInfo.resourceEnvRefType, referenceInfo);
        final Object reference;
        if (EJBContext.class.isAssignableFrom(type)) {
            final String jndiName = "comp/EJBContext";
            reference = new LinkRef(jndiName);
            // Let the container bind this into JNDI
            if (jndiName.equals(referenceInfo.referenceName)) {
                continue;
            }
        } else if (Validator.class.equals(type)) {
            final String jndiName = "comp/Validator";
            reference = new LinkRef(jndiName);
        } else if (ValidatorFactory.class.equals(type)) {
            final String jndiName = "comp/ValidatorFactory";
            reference = new LinkRef(jndiName);
        } else if (WebServiceContext.class.equals(type)) {
            final String jndiName = "comp/WebServiceContext";
            reference = new LinkRef(jndiName);
        } else if (TimerService.class.equals(type)) {
            final String jndiName = "comp/TimerService";
            reference = new LinkRef(jndiName);
        } else if (BeanManager.class.equals(type)) {
            reference = new LazyObjectReference<>(new BeanManagerLazyReference());
        } else if (UserTransaction.class.equals(type)) {
            reference = new IntraVmJndiReference("comp/UserTransaction");
        } else if (referenceInfo.resourceID != null) {
            final String jndiName = "openejb/Resource/" + referenceInfo.resourceID;
            reference = new IntraVmJndiReference(jndiName);
        } else {
            final String jndiName = "openejb/Resource/" + referenceInfo.referenceName;
            reference = new IntraVmJndiReference(jndiName);
        }
        bindings.put(normalize(referenceInfo.referenceName), reference);
    }
    for (final PersistenceUnitReferenceInfo referenceInfo : jndiEnc.persistenceUnitRefs) {
        if (referenceInfo.location != null) {
            final Reference reference = buildReferenceLocation(referenceInfo.location);
            bindings.put(normalize(referenceInfo.referenceName), reference);
            continue;
        }
        final String jndiName = PersistenceBuilder.getOpenEJBJndiName(referenceInfo.unitId);
        final Reference reference = new IntraVmJndiReference(jndiName);
        bindings.put(normalize(referenceInfo.referenceName), reference);
    }
    for (final PersistenceContextReferenceInfo contextInfo : jndiEnc.persistenceContextRefs) {
        if (contextInfo.location != null) {
            final Reference reference = buildReferenceLocation(contextInfo.location);
            bindings.put(normalize(contextInfo.referenceName), reference);
            continue;
        }
        final Context context = SystemInstance.get().getComponent(ContainerSystem.class).getJNDIContext();
        final EntityManagerFactory factory;
        try {
            final String jndiName = PersistenceBuilder.getOpenEJBJndiName(contextInfo.unitId);
            factory = (EntityManagerFactory) context.lookup(jndiName);
        } catch (final NamingException e) {
            throw new OpenEJBException("PersistenceUnit '" + contextInfo.unitId + "' not found for EXTENDED ref '" + contextInfo.referenceName + "'");
        }
        final JtaEntityManager jtaEntityManager = new JtaEntityManager(contextInfo.persistenceUnitName, jtaEntityManagerRegistry, factory, contextInfo.properties, contextInfo.extended, contextInfo.synchronizationType);
        final Reference reference = new PersistenceContextReference(jtaEntityManager);
        bindings.put(normalize(contextInfo.referenceName), reference);
    }
    for (final ServiceReferenceInfo referenceInfo : jndiEnc.serviceRefs) {
        if (referenceInfo.location != null) {
            final Reference reference = buildReferenceLocation(referenceInfo.location);
            bindings.put(normalize(referenceInfo.referenceName), reference);
            continue;
        }
        // load service class which is used to construct the port
        Class<? extends Service> serviceClass = Service.class;
        if (referenceInfo.serviceType != null) {
            try {
                serviceClass = classLoader.loadClass(referenceInfo.serviceType).asSubclass(Service.class);
            } catch (final Exception e) {
                throw new OpenEJBException("Could not load service type class " + referenceInfo.serviceType, e);
            }
        }
        // load the reference class which is the ultimate type of the port
        Class<?> referenceClass = null;
        if (referenceInfo.referenceType != null) {
            try {
                referenceClass = classLoader.loadClass(referenceInfo.referenceType);
            } catch (final Exception e) {
                throw new OpenEJBException("Could not load reference type class " + referenceInfo.referenceType, e);
            }
        }
        // if ref class is a subclass of Service, use it for the service class
        if (referenceClass != null && Service.class.isAssignableFrom(referenceClass)) {
            serviceClass = referenceClass.asSubclass(Service.class);
        }
        // determine the location of the wsdl file
        URL wsdlUrl = null;
        if (referenceInfo.wsdlFile != null) {
            try {
                wsdlUrl = new URL(referenceInfo.wsdlFile);
            } catch (final MalformedURLException e) {
                wsdlUrl = classLoader.getResource(referenceInfo.wsdlFile);
                if (wsdlUrl == null) {
                    logger.warning("Error obtaining WSDL: " + referenceInfo.wsdlFile, e);
                }
            }
        }
        // port refs
        final List<PortRefData> portRefs = new ArrayList<>(referenceInfo.portRefs.size());
        for (final PortRefInfo portRefInfo : referenceInfo.portRefs) {
            final PortRefData portRef = new PortRefData();
            portRef.setQName(portRefInfo.qname);
            portRef.setServiceEndpointInterface(portRefInfo.serviceEndpointInterface);
            portRef.setEnableMtom(portRefInfo.enableMtom);
            portRef.getProperties().putAll(portRefInfo.properties);
            portRefs.add(portRef);
        }
        // create the handle chains
        List<HandlerChainData> handlerChains = null;
        if (!referenceInfo.handlerChains.isEmpty()) {
            handlerChains = WsBuilder.toHandlerChainData(referenceInfo.handlerChains, classLoader);
        }
        if (!client) {
            final Reference reference = new JaxWsServiceReference(referenceInfo.id, referenceInfo.serviceQName, serviceClass, referenceInfo.portQName, referenceClass, wsdlUrl, portRefs, handlerChains, injections, properties);
            bindings.put(normalize(referenceInfo.referenceName), reference);
        } else {
            final ServiceRefData serviceRefData = new ServiceRefData(referenceInfo.id, referenceInfo.serviceQName, serviceClass, referenceInfo.portQName, referenceClass, wsdlUrl, handlerChains, portRefs);
            bindings.put(normalize(referenceInfo.referenceName), serviceRefData);
        }
    }
    final OpenEjbConfiguration config = SystemInstance.get().getComponent(OpenEjbConfiguration.class);
    if (config != null) {
        for (final ResourceInfo resource : config.facilities.resources) {
            final String jndiName = resource.jndiName;
            if (jndiName != null && !jndiName.isEmpty() && isNotGobalOrIsHoldByThisApp(resource, scope)) {
                final String refName = "openejb/Resource/" + resource.id;
                final Object reference = new IntraVmJndiReference(refName);
                final String boundName = normalize(jndiName);
                bindings.put(boundName, reference);
            }
        }
    }
    return bindings;
}
Also used : ContainerSystem(org.apache.openejb.spi.ContainerSystem) OpenEJBException(org.apache.openejb.OpenEJBException) HandlerChainData(org.apache.openejb.core.webservices.HandlerChainData) MalformedURLException(java.net.MalformedURLException) Configuration(jakarta.ws.rs.core.Configuration) ArrayList(java.util.ArrayList) CrossClassLoaderJndiReference(org.apache.openejb.core.ivm.naming.CrossClassLoaderJndiReference) HttpServletRequest(jakarta.servlet.http.HttpServletRequest) JaxWsServiceReference(org.apache.openejb.core.ivm.naming.JaxWsServiceReference) IntraVmJndiReference(org.apache.openejb.core.ivm.naming.IntraVmJndiReference) JtaEntityManagerRegistry(org.apache.openejb.persistence.JtaEntityManagerRegistry) NamingException(javax.naming.NamingException) InjectableBeanManager(org.apache.webbeans.container.InjectableBeanManager) BeanManager(jakarta.enterprise.inject.spi.BeanManager) PersistenceContextReference(org.apache.openejb.core.ivm.naming.PersistenceContextReference) LazyObjectReference(org.apache.openejb.core.ivm.naming.LazyObjectReference) JtaEntityManager(org.apache.openejb.persistence.JtaEntityManager) EntityManagerFactory(jakarta.persistence.EntityManagerFactory) ManagedBean(jakarta.annotation.ManagedBean) HttpHeaders(jakarta.ws.rs.core.HttpHeaders) Providers(jakarta.ws.rs.ext.Providers) Providers(jakarta.ws.rs.ext.Providers) WebServiceContext(jakarta.xml.ws.WebServiceContext) URL(java.net.URL) ObjectReference(org.apache.openejb.core.ivm.naming.ObjectReference) MapObjectReference(org.apache.openejb.core.ivm.naming.MapObjectReference) LazyObjectReference(org.apache.openejb.core.ivm.naming.LazyObjectReference) ServletContext(jakarta.servlet.ServletContext) PortRefData(org.apache.openejb.core.webservices.PortRefData) LinkRef(javax.naming.LinkRef) SecurityContext(jakarta.ws.rs.core.SecurityContext) WebServiceContext(jakarta.xml.ws.WebServiceContext) WebBeansContext(org.apache.webbeans.config.WebBeansContext) ResourceContext(jakarta.ws.rs.container.ResourceContext) ServletContext(jakarta.servlet.ServletContext) EJBContext(jakarta.ejb.EJBContext) Context(javax.naming.Context) URLReference(org.apache.openejb.core.ivm.naming.URLReference) ObjectReference(org.apache.openejb.core.ivm.naming.ObjectReference) MapObjectReference(org.apache.openejb.core.ivm.naming.MapObjectReference) JndiReference(org.apache.openejb.core.ivm.naming.JndiReference) PersistenceContextReference(org.apache.openejb.core.ivm.naming.PersistenceContextReference) Reference(org.apache.openejb.core.ivm.naming.Reference) IntraVmJndiReference(org.apache.openejb.core.ivm.naming.IntraVmJndiReference) URLReference(org.apache.openejb.core.ivm.naming.URLReference) ClassReference(org.apache.openejb.core.ivm.naming.ClassReference) CrossClassLoaderJndiReference(org.apache.openejb.core.ivm.naming.CrossClassLoaderJndiReference) SystemComponentReference(org.apache.openejb.core.ivm.naming.SystemComponentReference) LazyObjectReference(org.apache.openejb.core.ivm.naming.LazyObjectReference) JndiUrlReference(org.apache.openejb.core.ivm.naming.JndiUrlReference) JaxWsServiceReference(org.apache.openejb.core.ivm.naming.JaxWsServiceReference) TimerService(jakarta.ejb.TimerService) Service(jakarta.xml.ws.Service) ServiceRefData(org.apache.openejb.core.webservices.ServiceRefData) TreeMap(java.util.TreeMap) NamingException(javax.naming.NamingException) OpenEJBException(org.apache.openejb.OpenEJBException) SystemException(org.apache.openejb.SystemException) MalformedURLException(java.net.MalformedURLException) LinkRef(javax.naming.LinkRef) SecurityContext(jakarta.ws.rs.core.SecurityContext) MapObjectReference(org.apache.openejb.core.ivm.naming.MapObjectReference) ClassReference(org.apache.openejb.core.ivm.naming.ClassReference) UriInfo(jakarta.ws.rs.core.UriInfo) Validator(jakarta.validation.Validator)

Example 2 with WebServiceContext

use of jakarta.xml.ws.WebServiceContext in project tomee by apache.

the class SingletonInstanceManager method deploy.

public void deploy(final BeanContext beanContext) throws OpenEJBException {
    final Data data = new Data(beanContext);
    beanContext.setContainerData(data);
    beanContext.set(EJBContext.class, this.sessionContext);
    // Create stats interceptor
    if (StatsInterceptor.isStatsActivated()) {
        final StatsInterceptor stats = new StatsInterceptor(beanContext.getBeanClass());
        beanContext.addFirstSystemInterceptor(stats);
        final ObjectNameBuilder jmxName = new ObjectNameBuilder("openejb.management");
        jmxName.set("J2EEServer", "openejb");
        jmxName.set("J2EEApplication", null);
        jmxName.set("EJBModule", beanContext.getModuleID());
        jmxName.set("SingletonSessionBean", beanContext.getEjbName());
        jmxName.set("name", beanContext.getEjbName());
        jmxName.set("j2eeType", "Invocations");
        // register the invocation stats interceptor
        final MBeanServer server = LocalMBeanServer.get();
        try {
            final ObjectName objectName = jmxName.build();
            if (server.isRegistered(objectName)) {
                server.unregisterMBean(objectName);
            }
            server.registerMBean(new ManagedMBean(stats), objectName);
            data.add(objectName);
        } catch (final Exception e) {
            logger.error("Unable to register MBean ", e);
        }
    }
    try {
        final Context context = beanContext.getJndiEnc();
        context.bind("comp/EJBContext", sessionContext);
        context.bind("comp/WebServiceContext", webServiceContext);
        context.bind("comp/TimerService", new TimerServiceWrapper());
    } catch (final NamingException e) {
        throw new OpenEJBException("Failed to bind EJBContext/WebServiceContext/TimerService", e);
    }
}
Also used : BeanContext(org.apache.openejb.BeanContext) EJBContext(jakarta.ejb.EJBContext) Context(javax.naming.Context) WebServiceContext(jakarta.xml.ws.WebServiceContext) InstanceContext(org.apache.openejb.core.InstanceContext) ThreadContext(org.apache.openejb.core.ThreadContext) ObjectNameBuilder(org.apache.openejb.monitoring.ObjectNameBuilder) TimerServiceWrapper(org.apache.openejb.core.timer.TimerServiceWrapper) OpenEJBException(org.apache.openejb.OpenEJBException) StatsInterceptor(org.apache.openejb.monitoring.StatsInterceptor) InterceptorData(org.apache.openejb.core.interceptor.InterceptorData) NamingException(javax.naming.NamingException) ManagedMBean(org.apache.openejb.monitoring.ManagedMBean) NamingException(javax.naming.NamingException) NoSuchEJBException(jakarta.ejb.NoSuchEJBException) ApplicationException(org.apache.openejb.ApplicationException) OpenEJBException(org.apache.openejb.OpenEJBException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ExecutionException(java.util.concurrent.ExecutionException) MBeanServer(javax.management.MBeanServer) LocalMBeanServer(org.apache.openejb.monitoring.LocalMBeanServer) ObjectName(javax.management.ObjectName)

Example 3 with WebServiceContext

use of jakarta.xml.ws.WebServiceContext in project tomee by apache.

the class JavaLookupScopesTest method test.

public void test() throws Exception {
    final AppContext app;
    {
        final ConfigurationFactory config = new ConfigurationFactory();
        final Assembler assembler = new Assembler();
        assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
        assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
        // Setup the descriptor information
        final EjbJar ejbJar = new EjbJar("testmodule");
        ejbJar.addEnterpriseBean(new SingletonBean(Bean.class));
        // Deploy the bean a second time to simulate situations
        // where the same java:module java:app java:global names
        // are re-declared in a compatible way
        ejbJar.addEnterpriseBean(new SingletonBean("Other", Bean.class));
        final EjbModule ejbModule = new EjbModule(ejbJar);
        final AppModule module = new AppModule(ejbModule);
        app = assembler.createApplication(config.configureApplication(module));
    }
    final BeanContext bean = app.getBeanContexts().get(0);
    final ModuleContext module = bean.getModuleContext();
    {
        // app context lookups
        final Context context = app.getAppJndiContext();
        assertTrue(context.lookup("app") instanceof Context);
        assertTrue(context.lookup("app/AppName") instanceof String);
        assertTrue(context.lookup("app/green") instanceof DataSource);
        assertTrue(context.lookup("app/testmodule") instanceof Context);
        assertTrue(context.lookup("app/testmodule/Bean") instanceof Bean);
        assertTrue(context.lookup("app/testmodule/Bean!" + Bean.class.getName()) instanceof Bean);
        assertTrue(context.lookup("app/testmodule/Other") instanceof Bean);
        assertTrue(context.lookup("app/testmodule/Other!" + Bean.class.getName()) instanceof Bean);
        assertEquals("testmodule", context.lookup("app/AppName"));
    }
    {
        // module context lookups
        final Context context = module.getModuleJndiContext();
        assertTrue(context.lookup("module") instanceof Context);
        assertTrue(context.lookup("module/ModuleName") instanceof String);
        assertTrue(context.lookup("module/blue") instanceof DataSource);
        assertTrue(context.lookup("module/Bean") instanceof Bean);
        assertTrue(context.lookup("module/Bean!" + Bean.class.getName()) instanceof Bean);
        assertEquals("testmodule", context.lookup("module/ModuleName"));
    // TODO the Module JNDI context *should* be able to see the App context
    }
    {
        final Context context = bean.getJndiContext();
        assertTrue(context.lookup("comp") instanceof Context);
        assertTrue(context.lookup("comp/EJBContext") instanceof EJBContext);
        assertTrue(context.lookup("comp/TimerService") instanceof TimerService);
        assertTrue(context.lookup("comp/TransactionManager") instanceof TransactionManager);
        assertTrue(context.lookup("comp/TransactionSynchronizationRegistry") instanceof TransactionSynchronizationRegistry);
        assertTrue(context.lookup("comp/WebServiceContext") instanceof WebServiceContext);
        assertTrue(context.lookup("comp/env") instanceof Context);
        assertTrue(context.lookup("comp/env") instanceof Context);
        assertTrue(context.lookup("comp/env/orange") instanceof DataSource);
        assertTrue(context.lookup("comp/env/" + Bean.class.getName()) instanceof Context);
        assertTrue(context.lookup("comp/env/" + Bean.class.getName() + "/red") instanceof DataSource);
        assertTrue(context.lookup("module") instanceof Context);
        assertTrue(context.lookup("module/ModuleName") instanceof String);
        assertTrue(context.lookup("module/blue") instanceof DataSource);
        assertTrue(context.lookup("module/Bean") instanceof Bean);
        assertTrue(context.lookup("module/Bean!" + Bean.class.getName()) instanceof Bean);
        assertTrue(context.lookup("module/Other") instanceof Bean);
        assertTrue(context.lookup("module/Other!" + Bean.class.getName()) instanceof Bean);
        assertTrue(context.lookup("app") instanceof Context);
        assertTrue(context.lookup("app/AppName") instanceof String);
        assertTrue(context.lookup("app/green") instanceof DataSource);
        assertTrue(context.lookup("app/testmodule") instanceof Context);
        assertTrue(context.lookup("app/testmodule/Bean") instanceof Bean);
        assertTrue(context.lookup("app/testmodule/Bean!" + Bean.class.getName()) instanceof Bean);
        assertTrue(context.lookup("app/testmodule/Other") instanceof Bean);
        assertTrue(context.lookup("app/testmodule/Other!" + Bean.class.getName()) instanceof Bean);
        assertTrue(context.lookup("global") instanceof Context);
        assertTrue(context.lookup("global/yellow") instanceof DataSource);
        assertTrue(context.lookup("global/testmodule") instanceof Context);
        assertTrue(context.lookup("global/testmodule/Bean") instanceof Bean);
        assertTrue(context.lookup("global/testmodule/Bean!" + Bean.class.getName()) instanceof Bean);
        assertTrue(context.lookup("global/testmodule/Other") instanceof Bean);
        assertTrue(context.lookup("global/testmodule/Other!" + Bean.class.getName()) instanceof Bean);
        assertEquals("testmodule", context.lookup("app/AppName"));
        assertEquals("testmodule", context.lookup("module/ModuleName"));
    }
}
Also used : InitialContext(javax.naming.InitialContext) BeanContext(org.apache.openejb.BeanContext) EJBContext(jakarta.ejb.EJBContext) ModuleContext(org.apache.openejb.ModuleContext) AppContext(org.apache.openejb.AppContext) Context(javax.naming.Context) WebServiceContext(jakarta.xml.ws.WebServiceContext) EJBContext(jakarta.ejb.EJBContext) AppModule(org.apache.openejb.config.AppModule) AppContext(org.apache.openejb.AppContext) EjbModule(org.apache.openejb.config.EjbModule) WebServiceContext(jakarta.xml.ws.WebServiceContext) TimerService(jakarta.ejb.TimerService) DataSource(javax.sql.DataSource) SingletonBean(org.apache.openejb.jee.SingletonBean) BeanContext(org.apache.openejb.BeanContext) SingletonBean(org.apache.openejb.jee.SingletonBean) TransactionManager(jakarta.transaction.TransactionManager) TransactionSynchronizationRegistry(jakarta.transaction.TransactionSynchronizationRegistry) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) ModuleContext(org.apache.openejb.ModuleContext) Assembler(org.apache.openejb.assembler.classic.Assembler) EjbJar(org.apache.openejb.jee.EjbJar)

Example 4 with WebServiceContext

use of jakarta.xml.ws.WebServiceContext in project metro-jax-ws by eclipse-ee4j.

the class ProviderImpl method printContext.

private void printContext() {
    WebServiceContext wsContext = getContext();
    MessageContext ctxt = wsContext.getMessageContext();
    /*
        TODO: WSDL_DESCRIPTION's value type is not specified correctly in spec
        InputSource source = (InputSource)ctxt.getProperty(JAXRPCContext.WSDL_DESCRIPTION);
        verifySource(source);
*/
    QName expService = new QName("urn:test", "Hello");
    QName expPort = new QName("urn:test", "HelloPort");
    QName gotService = (QName) ctxt.get(MessageContext.WSDL_SERVICE);
    QName gotPort = (QName) ctxt.get(MessageContext.WSDL_PORT);
    if (!expService.equals(gotService)) {
        System.out.println("WSDL_SERVICE expected=" + expService + " Got=" + gotService);
        throw new WebServiceException("WSDL_SERVICE expected=" + expService + " Got=" + gotService);
    }
    if (!expPort.equals(gotPort)) {
        System.out.println("WSDL_PORT expected=" + expPort + " Got=" + gotPort);
        throw new WebServiceException("WSDL_PORT expected=" + expPort + " Got=" + gotPort);
    }
    // Get a property from context
    String gotProp = (String) ctxt.get("foo");
    if (!gotProp.equals("bar")) {
        System.out.println("foo property: expected=bar Got=" + gotProp);
        throw new WebServiceException("foo property: expected=bar Got=" + gotProp);
    }
    // Modify the same property in the context
    ctxt.put("foo", "return-bar");
    // Set a property in the context
    ctxt.put("return-foo", "return-bar");
}
Also used : WebServiceException(jakarta.xml.ws.WebServiceException) QName(javax.xml.namespace.QName) MessageContext(jakarta.xml.ws.handler.MessageContext) WebServiceContext(jakarta.xml.ws.WebServiceContext)

Aggregations

WebServiceContext (jakarta.xml.ws.WebServiceContext)4 EJBContext (jakarta.ejb.EJBContext)3 Context (javax.naming.Context)3 TimerService (jakarta.ejb.TimerService)2 NamingException (javax.naming.NamingException)2 BeanContext (org.apache.openejb.BeanContext)2 OpenEJBException (org.apache.openejb.OpenEJBException)2 ManagedBean (jakarta.annotation.ManagedBean)1 NoSuchEJBException (jakarta.ejb.NoSuchEJBException)1 BeanManager (jakarta.enterprise.inject.spi.BeanManager)1 EntityManagerFactory (jakarta.persistence.EntityManagerFactory)1 ServletContext (jakarta.servlet.ServletContext)1 HttpServletRequest (jakarta.servlet.http.HttpServletRequest)1 TransactionManager (jakarta.transaction.TransactionManager)1 TransactionSynchronizationRegistry (jakarta.transaction.TransactionSynchronizationRegistry)1 Validator (jakarta.validation.Validator)1 ResourceContext (jakarta.ws.rs.container.ResourceContext)1 Configuration (jakarta.ws.rs.core.Configuration)1 HttpHeaders (jakarta.ws.rs.core.HttpHeaders)1 SecurityContext (jakarta.ws.rs.core.SecurityContext)1