Search in sources :

Example 1 with ResourceInfo

use of org.apache.openejb.assembler.classic.ResourceInfo in project tomee by apache.

the class EffectiveTomEEXml method main.

public static void main(final String[] args) throws Exception {
    final CommandLine line = parseCommand(args);
    if (line == null) {
        return;
    }
    final Openejb openejb = JaxbOpenejb.readConfig(findXml(line).getCanonicalPath());
    final ConfigurationFactory configFact = new ConfigurationFactory();
    for (final Resource r : openejb.getResource()) {
        final ResourceInfo ri = configFact.configureService(r, ResourceInfo.class);
        if (!ri.properties.containsKey("SkipImplicitAttributes")) {
            ri.properties.put("SkipImplicitAttributes", "false");
        }
        r.getProperties().clear();
        r.getProperties().putAll(ri.properties);
    }
    // TODO: others
    final Marshaller marshaller = JaxbOpenejb.getContext(Openejb.class).createMarshaller();
    marshaller.setProperty("jaxb.formatted.output", true);
    marshaller.marshal(openejb, System.out);
}
Also used : ResourceInfo(org.apache.openejb.assembler.classic.ResourceInfo) CommandLine(org.apache.commons.cli.CommandLine) Marshaller(javax.xml.bind.Marshaller) Resource(org.apache.openejb.config.sys.Resource) Openejb(org.apache.openejb.config.sys.Openejb) JaxbOpenejb(org.apache.openejb.config.sys.JaxbOpenejb)

Example 2 with ResourceInfo

use of org.apache.openejb.assembler.classic.ResourceInfo in project tomee by apache.

the class JMSConnectionFactoryTest method checkConnectionFactoryIsThere.

@Test
public void checkConnectionFactoryIsThere() throws NamingException {
    // auto created
    assertNotNull(SystemInstance.get().getComponent(ContainerSystem.class).getContainer("Default Managed Container"));
    final List<ResourceInfo> resources = SystemInstance.get().getComponent(OpenEjbConfiguration.class).facilities.resources;
    boolean found = false;
    for (final ResourceInfo r : resources) {
        if (r.id.equals("JMSConnectionFactoryTest/testConnectionFactory")) {
            // prefixed with app name
            found = true;
            break;
        }
    }
    assertTrue(found);
    // these lookup must pass
    final Context jndiContext = SystemInstance.get().getComponent(ContainerSystem.class).getJNDIContext();
    final Object directLookup = jndiContext.lookup("openejb:Resource/testConnectionFactory");
    assertNotNull(directLookup);
    final Object appLookup = jndiContext.lookup("openejb:Resource/JMSConnectionFactoryTest/testConnectionFactory");
    assertNotNull(appLookup);
    // facade are not the same but the underlying connection factory should be
    assertEquals(Reflections.get(directLookup, "factory"), Reflections.get(appLookup, "factory"));
}
Also used : Context(javax.naming.Context) ContainerSystem(org.apache.openejb.spi.ContainerSystem) ResourceInfo(org.apache.openejb.assembler.classic.ResourceInfo) Test(org.junit.Test)

Example 3 with ResourceInfo

use of org.apache.openejb.assembler.classic.ResourceInfo in project tomee by apache.

the class DataSourceInitialSizeAdjustingTest method checkNonJtaPoolSizeWasCorrected.

@Test
public void checkNonJtaPoolSizeWasCorrected() {
    final String prefix = getClass().getSimpleName();
    for (final ResourceInfo info : SystemInstance.get().getComponent(OpenEjbConfiguration.class).facilities.resources) {
        if ((prefix + "NonJta").equals(info.id)) {
            assertEquals("5", info.properties.getProperty("InitialSize"));
            return;
        }
    }
    fail("DataSource not found");
}
Also used : ResourceInfo(org.apache.openejb.assembler.classic.ResourceInfo) Test(org.junit.Test)

Example 4 with ResourceInfo

use of org.apache.openejb.assembler.classic.ResourceInfo in project tomee by apache.

the class IgnoreDefaultTest method createWithoutDefaultDs.

@Test
public void createWithoutDefaultDs() throws OpenEJBException, NamingException {
    final Resource resource = new Resource(IgnoreDefaultTest.class.getName() + "#without-default");
    resource.setType(DataSource.class.getName());
    resource.getProperties().setProperty("IgnoreDefaultValues", "true");
    resource.getProperties().setProperty("JdbcDriver", jdbcDriver.class.getName());
    final ResourceInfo info = configurationFactory.configureService(resource, ResourceInfo.class);
    assembler.createResource(info);
    check(resource.getId(), null, null);
}
Also used : ResourceInfo(org.apache.openejb.assembler.classic.ResourceInfo) org.hsqldb.jdbcDriver(org.hsqldb.jdbcDriver) Resource(org.apache.openejb.config.sys.Resource) DataSource(javax.sql.DataSource) Test(org.junit.Test)

Example 5 with ResourceInfo

use of org.apache.openejb.assembler.classic.ResourceInfo in project tomee by apache.

the class ConfigurationFactory method configureService.

/**
     * This is the major piece of code that configures services.
     * It merges the data from the <ServiceProvider> declaration
     * with the data from the openejb.xml file (say <Resource>)
     * <p/>
     * The end result is a canonical (i.e. flattened) ServiceInfo
     * The ServiceInfo will be of a specific type (ContainerInfo, ResourceInfo, etc)
     *
     * @param service  Service
     * @param infoType Class
     * @param <T>      infoType
     * @return ServiceInfo
     * @throws OpenEJBException On error
     */
public <T extends ServiceInfo> T configureService(org.apache.openejb.config.Service service, final Class<? extends T> infoType) throws OpenEJBException {
    try {
        if (infoType == null) {
            throw new NullPointerException("type");
        }
        if (service == null) {
            service = getDefaultService(infoType);
            if (service == null) {
                throw new OpenEJBException(messages.format("configureService.noDefaultService", infoType.getName()));
            }
        }
        {
            String template = service.getTemplate();
            if (template == null) {
                template = SystemInstance.get().getProperty(Template.class.getName());
            }
            if (template != null) {
                template = unaliasPropertiesProvider(template);
                // don't trim them, user wants to handle it himself, let him do it
                final ObjectRecipe recipe = newObjectRecipe(template);
                recipe.setProperty("serviceId", service.getId());
                // note: we can also use reflection if needed to limit the dependency
                Template.class.cast(recipe.create()).configure(service);
            }
        }
        final ServiceProvider provider = getServiceProvider(service, infoType);
        if (service.getId() == null) {
            service.setId(provider.getId());
        }
        final Properties overrides = trim(getSystemProperties(overrideKey(service), provider.getService()));
        final Properties serviceProperties = service.getProperties();
        trim(serviceProperties);
        trim(provider.getProperties());
        logger.info("configureService.configuring", service.getId(), provider.getService(), provider.getId());
        if (logger.isDebugEnabled()) {
            for (final Map.Entry<Object, Object> entry : serviceProperties.entrySet()) {
                final Object key = entry.getKey();
                Object value = entry.getValue();
                if (key instanceof String && "password".equalsIgnoreCase((String) key)) {
                    value = "<hidden>";
                }
                logger.debug("[" + key + "=" + value + "]");
            }
            for (final Map.Entry<Object, Object> entry : overrides.entrySet()) {
                final Object key = entry.getKey();
                Object value = entry.getValue();
                if (key instanceof String && "password".equalsIgnoreCase((String) key)) {
                    value = "<hidden>";
                }
                logger.debug("Override [" + key + "=" + value + "]");
            }
        }
        final Properties props = new SuperProperties().caseInsensitive(true);
        // weird hack but sometimes we don't want default values when we want null for instance
        if (serviceProperties == null || "false".equals(serviceProperties.getProperty(IGNORE_DEFAULT_VALUES_PROP, "false"))) {
            props.putAll(provider.getProperties());
        }
        if (serviceProperties != null) {
            props.putAll(serviceProperties);
        }
        props.putAll(overrides);
        {
            // force user properties last
            String propertiesProvider = service.getPropertiesProvider();
            if (propertiesProvider == null) {
                propertiesProvider = SystemInstance.get().getProperty(PropertiesResourceProvider.class.getName());
            }
            if (propertiesProvider != null) {
                propertiesProvider = unaliasPropertiesProvider(propertiesProvider);
                // don't trim them, user wants to handle it himself, let him do it
                final ObjectRecipe recipe = newObjectRecipe(propertiesProvider);
                recipe.setFactoryMethod("provides");
                recipe.setProperty("serviceId", service.getId());
                recipe.setProperties(props);
                // let user get all config
                recipe.setProperty("properties", props);
                final Properties p = Properties.class.cast(recipe.create());
                props.putAll(p);
            }
        }
        props.remove(IGNORE_DEFAULT_VALUES_PROP);
        final T info;
        try {
            info = infoType.newInstance();
        } catch (final Exception e) {
            throw new OpenEJBException(messages.format("configureService.cannotInstantiateClass", infoType.getName()), e);
        }
        // some jndi adjustment
        if (service.getId().startsWith("java:/")) {
            service.setId(service.getId().substring("java:/".length()));
        }
        info.service = provider.getService();
        info.types.addAll(provider.getTypes());
        info.description = provider.getDescription();
        info.displayName = provider.getDisplayName();
        info.className = provider.getClassName();
        info.factoryMethod = provider.getFactoryName();
        info.id = service.getId();
        info.properties = props;
        info.constructorArgs.addAll(parseConstructorArgs(provider));
        if (info instanceof ResourceInfo && service instanceof Resource) {
            final ResourceInfo ri = ResourceInfo.class.cast(info);
            final Resource resource = Resource.class.cast(service);
            ri.jndiName = resource.getJndi();
            ri.postConstruct = resource.getPostConstruct();
            ri.preDestroy = resource.getPreDestroy();
            ri.aliases.addAll(resource.getAliases());
            ri.dependsOn.addAll(resource.getDependsOn());
        }
        if (service.getClasspath() != null && service.getClasspath().length() > 0) {
            info.classpath = resolveClasspath(service.getClasspath());
        }
        info.classpathAPI = service.getClasspathAPI();
        specialProcessing(info);
        return info;
    } catch (final NoSuchProviderException e) {
        final String message = logger.fatal("configureService.failed", e, (null != service ? service.getId() : ""));
        throw new OpenEJBException(message + ": " + e.getMessage());
    } catch (final Throwable e) {
        final String message = logger.fatal("configureService.failed", e, (null != service ? service.getId() : ""));
        throw new OpenEJBException(message, e);
    }
}
Also used : OpenEJBException(org.apache.openejb.OpenEJBException) ResourceInfo(org.apache.openejb.assembler.classic.ResourceInfo) Resource(org.apache.openejb.config.sys.Resource) Properties(java.util.Properties) SuperProperties(org.apache.openejb.util.SuperProperties) SuperProperties(org.apache.openejb.util.SuperProperties) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) OpenEJBException(org.apache.openejb.OpenEJBException) MalformedURLException(java.net.MalformedURLException) Template(org.apache.openejb.api.resource.Template) ObjectRecipe(org.apache.xbean.recipe.ObjectRecipe) ServiceProvider(org.apache.openejb.config.sys.ServiceProvider) PropertiesResourceProvider(org.apache.openejb.api.resource.PropertiesResourceProvider) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

ResourceInfo (org.apache.openejb.assembler.classic.ResourceInfo)66 PersistenceUnitInfo (org.apache.openejb.assembler.classic.PersistenceUnitInfo)31 Resource (org.apache.openejb.config.sys.Resource)14 OpenEJBException (org.apache.openejb.OpenEJBException)12 Properties (java.util.Properties)8 AppInfo (org.apache.openejb.assembler.classic.AppInfo)8 Persistence (org.apache.openejb.jee.jpa.unit.Persistence)8 PersistenceUnit (org.apache.openejb.jee.jpa.unit.PersistenceUnit)8 ArrayList (java.util.ArrayList)6 Assembler (org.apache.openejb.assembler.classic.Assembler)6 WebApp (org.apache.openejb.jee.WebApp)6 SuperProperties (org.apache.openejb.util.SuperProperties)6 Test (org.junit.Test)6 SecurityServiceInfo (org.apache.openejb.assembler.classic.SecurityServiceInfo)5 TransactionServiceInfo (org.apache.openejb.assembler.classic.TransactionServiceInfo)5 File (java.io.File)4 DataSource (javax.sql.DataSource)4 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 AppContext (org.apache.openejb.AppContext)3