org.apache.openejb.loader.SystemInstance Java Examples
The following examples show how to use
org.apache.openejb.loader.SystemInstance.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CxfRsHttpListener.java From tomee with Apache License 2.0 | 6 votes |
private void addMandatoryProviders(final Collection<Object> instances, final ServiceConfiguration serviceConfiguration) { if (SystemInstance.get().getProperty("openejb.jaxrs.jsonProviders") == null) { if (!shouldSkipProvider(WadlDocumentMessageBodyWriter.class.getName())) { instances.add(new WadlDocumentMessageBodyWriter()); } } if (!shouldSkipProvider(EJBExceptionMapper.class.getName())) { instances.add(new EJBExceptionMapper()); } if (!shouldSkipProvider(ValidationExceptionMapper.class.getName())) { instances.add(new ValidationExceptionMapper()); final String level = SystemInstance.get() .getProperty( "openejb.cxf.rs.bval.log.level", serviceConfiguration.getProperties().getProperty(CXF_JAXRS_PREFIX + "bval.log.level")); if (level != null) { try { LogUtils.getL7dLogger(ValidationExceptionMapper.class).setLevel(Level.parse(level)); } catch (final UnsupportedOperationException uoe) { LOGGER.warning("Can't set level " + level + " on " + "org.apache.cxf.jaxrs.validation.ValidationExceptionMapper logger, " + "please configure it in your logging framework."); } } } }
Example #2
Source File: UserTransactionFactory.java From tomee with Apache License 2.0 | 6 votes |
@Override public Object getObjectInstance(final Object object, final Name name, final Context context, final Hashtable environment) throws Exception { // get the transaction manager final TransactionManager transactionManager = SystemInstance.get().getComponent(TransactionManager.class); if (transactionManager == null) { throw new NamingException("transaction manager not found"); } // if transaction manager implements user transaction we are done if (transactionManager instanceof UserTransaction) { return transactionManager; } // wrap transaction manager with user transaction return new CoreUserTransaction(transactionManager); }
Example #3
Source File: ConfigurationFactoryTest.java From tomee with Apache License 2.0 | 6 votes |
@Test public void testConfigureApplicationWebModule() throws OpenEJBException { SystemInstance.get().setProperty("openejb.environment.default", "false"); final String moduleId = "testConfigureApplicationWebModule"; final String fileSeparator = System.getProperty("file.separator"); SystemInstance.get().setProperty(ConfigurationFactory.VALIDATION_SKIP_PROPERTY, "false"); SystemInstance.get().setProperty(DeploymentsResolver.SEARCH_CLASSPATH_FOR_DEPLOYMENTS_PROPERTY, "false"); final ConfigurationFactory factory = new ConfigurationFactory(); final WebApp webApp = new WebApp(); // no real classes engaged so disable metadata (annotation) processing webApp.setMetadataComplete(true); final WebModule webModule = new WebModule(webApp, null, null, fileSeparator + "some" + fileSeparator + "where.war", moduleId); final WebAppInfo info = factory.configureApplication(webModule); assertEquals(moduleId, info.moduleId); SystemInstance.get().getProperties().remove("openejb.environment.default"); }
Example #4
Source File: DynamicDataSourceTest.java From tomee with Apache License 2.0 | 6 votes |
/** * lookup datasource in openejb resources */ private void init() { dataSources = new ConcurrentHashMap<>(); for (final String ds : dataSourceNames.split(" ")) { final ContainerSystem containerSystem = SystemInstance.get().getComponent(ContainerSystem.class); Object o = null; final Context ctx = containerSystem.getJNDIContext(); try { o = ctx.lookup("openejb:Resource/" + ds); if (o instanceof DataSource) { dataSources.put(ds, (DataSource) o); } } catch (final NamingException e) { } } }
Example #5
Source File: InheritedAppExceptionTest.java From tomee with Apache License 2.0 | 6 votes |
@Test public void testRollback() throws Exception { SystemInstance.init(new Properties()); final BeanContext cdi = new BeanContext("foo", null, new ModuleContext("foo", null, "bar", new AppContext("foo", SystemInstance.get(), null, null, null, false), null, null), Object.class, null, new HashMap<>()); cdi.addApplicationException(AE1.class, true, true); cdi.addApplicationException(AE3.class, true, false); cdi.addApplicationException(AE6.class, false, true); assertEquals(ExceptionType.APPLICATION_ROLLBACK, cdi.getExceptionType(new AE1())); assertEquals(ExceptionType.APPLICATION_ROLLBACK, cdi.getExceptionType(new AE2())); assertEquals(ExceptionType.APPLICATION_ROLLBACK, cdi.getExceptionType(new AE3())); assertEquals(ExceptionType.SYSTEM, cdi.getExceptionType(new AE4())); assertEquals(ExceptionType.SYSTEM, cdi.getExceptionType(new AE5())); assertEquals(ExceptionType.APPLICATION, cdi.getExceptionType(new AE6())); assertEquals(ExceptionType.APPLICATION, cdi.getExceptionType(new AE7())); }
Example #6
Source File: SingleInstanceRunnerTest.java From tomee with Apache License 2.0 | 6 votes |
@Test public void run() { assertNotNull(SystemInstance.get().getComponent(Assembler.class)); assertEquals("val", SystemInstance.get().getProperty("simple")); assertEquals("set", SystemInstance.get().getProperty("t")); assertEquals("p", SystemInstance.get().getProperty("prog")); assertEquals("128463", SystemInstance.get().getProperty("my.server.port")); assertEquals("true", SystemInstance.get().getProperty("configurer")); assertNotEquals(8080, app.port); assertTrue(app.base.toExternalForm().endsWith("/app")); assertEquals(app.port, port); assertNotNull(app.task); assertNotNull(app.tasks); assertEquals(1, app.tasks.size()); assertEquals(app.task, app.tasks.iterator().next()); assertEquals(app.task, MyTask.instance); assertNotNull(app.custom); }
Example #7
Source File: TomEEWebappClassLoader.java From tomee with Apache License 2.0 | 6 votes |
public synchronized void initAdditionalRepos() { if (additionalRepos != null) { return; } if (CONTEXT.get() != null) { additionalRepos = new LinkedList<>(); final String contextPath = CONTEXT.get().getServletContext().getContextPath(); final String name = contextPath.isEmpty() ? "ROOT" : contextPath.substring(1); final String externalRepositories = SystemInstance.get().getProperty("tomee." + name + ".externalRepositories"); if (externalRepositories != null) { for (final String additional : externalRepositories.split(",")) { final String trim = additional.trim(); if (!trim.isEmpty()) { final File file = new File(trim); additionalRepos.add(file); } } } } }
Example #8
Source File: InitContextFactory.java From tomee with Apache License 2.0 | 6 votes |
@SuppressWarnings("UseOfObsoleteCollectionType") private void initializeOpenEJB(final Hashtable env) throws javax.naming.NamingException { try { final Properties props = new Properties(); /* DMB: We should get the defaults from the functionality * Alan is working on. This is temporary. * When that logic is finished, this block should * probably just be deleted. */ props.put(EnvProps.ASSEMBLER, "org.apache.openejb.assembler.classic.Assembler"); props.put(EnvProps.CONFIGURATION_FACTORY, "org.apache.openejb.config.ConfigurationFactory"); props.put(EnvProps.CONFIGURATION, "conf/default.openejb.conf"); props.putAll(SystemInstance.get().getProperties()); props.putAll(env); OpenEJB.init(props); } catch (final Exception e) { throw new NamingException("Cannot initailize OpenEJB", e); } }
Example #9
Source File: SingletonInstanceManager.java From tomee with Apache License 2.0 | 6 votes |
private void initializeDependencies(final BeanContext beanContext) throws OpenEJBException { final SystemInstance systemInstance = SystemInstance.get(); final ContainerSystem containerSystem = systemInstance.getComponent(ContainerSystem.class); for (final String dependencyId : beanContext.getDependsOn()) { final BeanContext dependencyContext = containerSystem.getBeanContext(dependencyId); if (dependencyContext == null) { throw new OpenEJBException("Deployment does not exist. Deployment(id='" + dependencyContext + "')"); } final Object containerData = dependencyContext.getContainerData(); // Bean may not be a singleton or may be a singleton // managed by a different container implementation if (containerData instanceof Data) { final Data data = (Data) containerData; data.initialize(); } } }
Example #10
Source File: TomcatWebAppBuilder.java From tomee with Apache License 2.0 | 6 votes |
private void manageCluster(final Cluster cluster) { if (cluster == null || cluster instanceof SimpleTomEETcpCluster) { return; } Cluster current = cluster; if (cluster instanceof SimpleTcpCluster) { final Container container = cluster.getContainer(); current = new SimpleTomEETcpCluster((SimpleTcpCluster) cluster); container.setCluster(current); } if (current instanceof CatalinaCluster) { final CatalinaCluster haCluster = (CatalinaCluster) current; TomEEClusterListener listener = SystemInstance.get().getComponent(TomEEClusterListener.class); if (listener == null) { listener = new TomEEClusterListener(); SystemInstance.get().setComponent(TomEEClusterListener.class, listener); } haCluster.addClusterListener(listener); // better to be a singleton clusters.add(haCluster); } }
Example #11
Source File: ConfUtils.java From tomee with Apache License 2.0 | 6 votes |
private static URL select(final Enumeration<URL> enumeration) { if (enumeration == null) { return null; } final ArrayList<URL> urls = Collections.list(enumeration); if (urls.size() == 0) { return null; } if (urls.size() == 1) { return urls.get(0); } // Sort so that the URL closest to openejb.base is first urls.sort(new UrlComparator(SystemInstance.get().getBase().getDirectory())); return urls.get(0); }
Example #12
Source File: AuthentWithRequestTest.java From tomee with Apache License 2.0 | 6 votes |
@Override public boolean login() throws LoginException { assertNull(SystemInstance.get().getComponent(SecurityService.class).currentState()); // check the user was not logged at lookup() final NameCallback nameCallback = new NameCallback("name?", "dummy"); try { callbackHandler.handle(new Callback[]{nameCallback}); } catch (final Exception e) { throw new LoginException(e.getMessage()); } if (!"foo".equals(nameCallback.getName())) { throw new IllegalArgumentException("Not an Error/assert cause in java 9 jaas doesnt capture it anymore"); } RemoteWithSecurity.name.set(nameCallback.getName()); return true; }
Example #13
Source File: OpenEJBContextConfig.java From tomee with Apache License 2.0 | 6 votes |
private Set<Class<?>> getJsfClasses(final Context context) { final WebAppBuilder builder = SystemInstance.get().getComponent(WebAppBuilder.class); final ClassLoader cl = context.getLoader().getClassLoader(); final Map<String, Set<String>> scanned = builder.getJsfClasses().get(cl); if (scanned == null || scanned.isEmpty()) { return null; } final Set<Class<?>> classes = new HashSet<>(); for (final Set<String> entry : scanned.values()) { for (final String name : entry) { try { classes.add(cl.loadClass(name)); } catch (final ClassNotFoundException ignored) { logger.warning("class '" + name + "' was found but can't be loaded as a JSF class"); } } } return classes; }
Example #14
Source File: JMS2CDIExtension.java From tomee with Apache License 2.0 | 6 votes |
private String findAnyConnectionFactory() { final OpenEjbConfiguration component = SystemInstance.get().getComponent(OpenEjbConfiguration.class); if (component != null && component.facilities != null) { for (final ResourceInfo ri : component.facilities.resources) { if (ri.types.contains("javax.jms.ConnectionFactory")) { return ri.id; } } // try the default one return "DefaultJMSConnectionFactory"; } // something is wrong, just fail throw new IllegalArgumentException( "No connection factory found, either use @JMSConnectionFactory JMSContext or define a connection factory"); }
Example #15
Source File: EjbModuleIdTest.java From tomee with Apache License 2.0 | 6 votes |
/** * OPENEJB-1555 * * @throws Exception */ @Test public void testSystemProperty() throws Exception { final Map<String, String> map = new HashMap<>(); map.put("META-INF/ejb-jar.xml", "<ejb-jar id=\"orangeId\"><module-name>orangeName</module-name></ejb-jar>"); final File file = Archives.jarArchive(map, "test", OrangeBean.class); final Assembler assembler = new Assembler(); final ConfigurationFactory factory = new ConfigurationFactory(); SystemInstance.get().setProperty(file.getName() + ".moduleId", "orangeSystem"); final AppInfo appInfo = factory.configureApplication(file); final EjbJarInfo ejbJarInfo = appInfo.ejbJars.get(0); assertEquals("orangeSystem", ejbJarInfo.moduleName); }
Example #16
Source File: Resolver.java From tomee with Apache License 2.0 | 6 votes |
public InputStream resolve(final String rawLocation) { final boolean initialized = SystemInstance.isInitialized(); final String MVN_JNDI_PREFIX = "mvn:"; if (!initialized) { SystemInstance.get().setComponent(ProvisioningResolver.class, new ProvisioningResolver()); } try { if (rawLocation.startsWith(MVN_JNDI_PREFIX) && rawLocation.length() > MVN_JNDI_PREFIX.length()) { try { return new FileInputStream(ShrinkwrapBridge.resolve(rawLocation)); } catch (final Throwable th) { // try aether if not in a mvn build th.printStackTrace(); } } return super.resolve(rawLocation); } finally { if (!initialized) { SystemInstance.reset(); } } }
Example #17
Source File: LightweightWebAppBuilder.java From tomee with Apache License 2.0 | 6 votes |
private void switchServletContextIfNeeded(final ServletContext sc, final Runnable runnable) { if (sc == null) { runnable.run(); return; } final SystemInstance systemInstance = SystemInstance.get(); final ServletContext old = systemInstance.getComponent(ServletContext.class); systemInstance.setComponent(ServletContext.class, sc); try { runnable.run(); } finally { if (old == null) { systemInstance.removeComponent(ServletContext.class); } else { systemInstance.setComponent(ServletContext.class, old); } } }
Example #18
Source File: EarModuleNamesTest.java From tomee with Apache License 2.0 | 5 votes |
@BeforeClass public static void preventDefaults() { System.setProperty("openejb.environment.default", "false"); SystemInstance.reset(); // we use it in a bunch of other tests but not here NewLoaderLogic.setExclusions( Stream.concat(Stream.of(ORIGINAL_EXCLUSIONS), Stream.of("openejb-itest", "failover-ejb")) .toArray(String[]::new)); }
Example #19
Source File: DataSourceFactory.java From tomee with Apache License 2.0 | 5 votes |
private static boolean usePool(final Properties properties) { String property = properties.getProperty(POOL_PROPERTY, SystemInstance.get().getProperty(POOL_PROPERTY)); if (property != null) { properties.remove(POOL_PROPERTY); } else { // defined from @DataSourceDefinition and doesn't need pooling final String initialPoolSize = properties.getProperty("initialPoolSize"); final String maxPoolSize = properties.getProperty("maxPoolSize"); if ((null == initialPoolSize || "-1".equals(initialPoolSize)) && ("-1".equals(maxPoolSize) || maxPoolSize == null)) { property = "false"; } } return "true".equalsIgnoreCase(property) || null == property; }
Example #20
Source File: ServerSideResolver.java From tomee with Apache License 2.0 | 5 votes |
@Override public Object resolve(final EJBObjectHandler handler) { try { final EJBMetaDataImpl ejb = handler.getEjb(); final InterfaceType interfaceType = (ejb.getRemoteInterfaceClass() == null) ? InterfaceType.BUSINESS_REMOTE_HOME : InterfaceType.EJB_HOME; final ArrayList<Class> interfaces = new ArrayList<>(); if (interfaceType.isBusiness()) { interfaces.addAll(ejb.getBusinessClasses()); } else { interfaces.add(ejb.getRemoteInterfaceClass()); } final ContainerSystem containerSystem = SystemInstance.get().getComponent(ContainerSystem.class); final BeanContext beanContext = containerSystem.getBeanContext(ejb.getDeploymentID()); return EjbObjectProxyHandler.createProxy(beanContext, handler.getPrimaryKey(), interfaceType, interfaces, ejb.getMainInterface()); } catch (Exception e) { Logger.getInstance(LogCategory.OPENEJB_SERVER_REMOTE, "org.apache.openejb.server.util.resources") .error("ServerSideResolver.resolve() failed, falling back to ClientSideResolver: " + e.getClass().getName() + ": " + e.getMessage(), e); return new EJBObjectProxyHandle.ClientSideResovler().resolve(handler); } }
Example #21
Source File: JndiEncInfoBuilder.java From tomee with Apache License 2.0 | 5 votes |
public JndiEncInfoBuilder(final AppInfo appInfo) { this.appInfo = appInfo; // Global-scoped EJB Resolver final EjbResolver globalResolver = SystemInstance.get().getComponent(EjbResolver.class); // EAR-scoped EJB Resolver this.earResolver = new EjbResolver(globalResolver, EAR, appInfo.ejbJars); // EJBJAR-scoped EJB Resolver(s) for (final EjbJarInfo ejbJarInfo : appInfo.ejbJars) { final EjbResolver ejbJarResolver = new EjbResolver(earResolver, EJBJAR, ejbJarInfo); this.ejbJarResolvers.put(ejbJarInfo.moduleName, ejbJarResolver); } }
Example #22
Source File: JndiRequestHandler.java From tomee with Apache License 2.0 | 5 votes |
JndiRequestHandler(final EjbDaemon daemon) throws Exception { super(daemon); final ContainerSystem containerSystem = SystemInstance.get().getComponent(ContainerSystem.class); containerSystem.getJNDIContext().lookup("openejb/remote"); containerSystem.getJNDIContext().lookup("openejb/Deployment"); containerSystem.getJNDIContext().lookup("openejb/global"); rootContext = containerSystem.getJNDIContext(); try { clientJndiTree = (Context) containerSystem.getJNDIContext().lookup("openejb/client"); } catch (NamingException ignore) { } clusterableRequestHandler = newClusterableRequestHandler(); }
Example #23
Source File: BeanPropertiesTest.java From tomee with Apache License 2.0 | 5 votes |
public void testOverrideFromModuleProperties() throws Exception { final ConfigurationFactory config = new ConfigurationFactory(); final Assembler assembler = new Assembler(); { // setup the system assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class)); assembler.createSecurityService(config.configureService(SecurityServiceInfo.class)); } { final Map<String, String> map = new HashMap<>(); map.put("META-INF/openejb-jar.xml", "<openejb-jar>\n" + " <ejb-deployment ejb-name=\"WidgetBean\">\n" + " <properties>\n" + " color=white\n" + " </properties>\n" + " </ejb-deployment>\n" + "</openejb-jar>"); map.put("META-INF/module.properties", "WidgetBean.color=orange"); final File app = Archives.fileArchive(map, WidgetBean.class); assembler.createApplication(config.configureApplication(app)); } final ContainerSystem containerSystem = SystemInstance.get().getComponent(ContainerSystem.class); assertContexts(containerSystem); }
Example #24
Source File: UnenhancedTest.java From tomee with Apache License 2.0 | 5 votes |
public void setUp() throws Exception { super.setUp(); // setup tx mgr transactionManager = new GeronimoTransactionManager(); SystemInstance.get().setComponent(TransactionSynchronizationRegistry.class, transactionManager); // Put tx mgr into SystemInstance so OpenJPA can find it SystemInstance.get().setComponent(TransactionManager.class, transactionManager); // init databases jtaDs = createJtaDataSource(transactionManager); nonJtaDs = createNonJtaDataSource(); }
Example #25
Source File: SystemComponentReference.java From tomee with Apache License 2.0 | 5 votes |
public Object getObject() throws NamingException { final Object component = SystemInstance.get().getComponent(type); if (component == null) { throw new NameNotFoundException("No " + type.getSimpleName() + " registered with the OpenEJB system"); } return component; }
Example #26
Source File: IvmContext.java From tomee with Apache License 2.0 | 5 votes |
protected boolean checkReadOnly() throws OperationNotSupportedException { if (readOnly) { //alignment with tomcat behavior if("true".equals(SystemInstance.get().getProperty(JNDI_EXCEPTION_ON_FAILED_WRITE,"true"))) { throw new OperationNotSupportedException(); } return true; } return false; }
Example #27
Source File: DeploymentContextOptionsTest.java From tomee with Apache License 2.0 | 5 votes |
@Override protected void setUp() throws Exception { SystemInstance.reset(); try { // hack for buildbot new ConfigurationImpl(null, null); } catch (final ValidationException ve) { // no-op } }
Example #28
Source File: BasicPolicyConfiguration.java From tomee with Apache License 2.0 | 5 votes |
public boolean implies(final ProtectionDomain domain, final Permission permission) { if (excluded != null && excluded.implies(permission)) { return false; } if (unchecked != null && unchecked.implies(permission)) { return true; } final Principal[] principals = domain.getPrincipals(); if (principals.length == 0) { return false; } final RoleResolver roleResolver = SystemInstance.get().getComponent(RoleResolver.class); final Set<String> roles = roleResolver.getLogicalRoles(principals, rolePermissionsMap.keySet()); for (final String role : roles) { final PermissionCollection permissions = rolePermissionsMap.get(role); if (permissions != null && permissions.implies(permission)) { return true; } } return false; }
Example #29
Source File: TomEESecurityContext.java From tomee with Apache License 2.0 | 5 votes |
public static void registerContainerAboutLogin(final Principal principal, final Set<String> groups) { final SecurityService securityService = SystemInstance.get().getComponent(SecurityService.class); if (TomcatSecurityService.class.isInstance(securityService)) { final TomcatSecurityService tomcatSecurityService = (TomcatSecurityService) securityService; final Request request = OpenEJBSecurityListener.requests.get(); final GenericPrincipal genericPrincipal = new GenericPrincipal(principal.getName(), null, new ArrayList<>(groups), principal); tomcatSecurityService.enterWebApp(request.getWrapper().getRealm(), genericPrincipal, request.getWrapper().getRunAs()); } }
Example #30
Source File: SWClassLoader.java From tomee with Apache License 2.0 | 5 votes |
@Override public Enumeration<URL> getResources(final String name) throws IOException { if (name == null) { return super.getResources(null); } final boolean cdiExtensions = name.startsWith("META-INF/services/" + Extension.class.getName()); if (cdiExtensions || !name.contains("META-INF/services/javax")) { final List<Archive<?>> node = findNodes(name); if (!node.isEmpty()) { final List<URL> urls = new ArrayList<>(); for (final Archive<?> i : node) { urls.add(new URL(null, "archive:" + i.getName() + (!name.startsWith("/") ? "/" : "") + name, new ArchiveStreamHandler())); } if (cdiExtensions && !"true".equalsIgnoreCase(SystemInstance.get().getProperty("openejb.arquillian.cdi.extension.skip-externals", "false"))) { addContainerExtensions(name, urls); } return enumerator(urls); } if (cdiExtensions) { if ("true".equalsIgnoreCase(SystemInstance.get().getProperty("openejb.arquillian.cdi.extension.skip-externals", "false"))) { return enumerator(Collections.<URL>emptyList()); } return enumerator(addContainerExtensions(name, new ArrayList<URL>(2))); } } return super.getResources(name); }