Search in sources :

Example 76 with OpenEJBException

use of org.apache.openejb.OpenEJBException in project tomee by apache.

the class AutoConfigPersistenceUnitsTest method testJtaRefToContrarilyConfiguredDataSource2.

/**
 * Existing data source "OrangeOne", not jta managed
 * <p/>
 * Persistence xml like so:
 * <p/>
 * <persistence-unit name="orange-unit">
 * <jta-data-source>OrangeOne</jta-data-source>
 * </persistence-unit>
 * <p/>
 * This configuration should be rejected
 *
 * @throws Exception
 */
public void testJtaRefToContrarilyConfiguredDataSource2() throws Exception {
    final ResourceInfo jta = addDataSource("OrangeOne", OrangeDriver.class, "jdbc:orange:some:stuff", false);
    assertSame(jta, resources.get(0));
    try {
        addPersistenceUnit("orange-unit", "orangeOne", null);
        fail("Configuration should be rejected");
    } catch (final OpenEJBException e) {
    // pass
    }
}
Also used : ResourceInfo(org.apache.openejb.assembler.classic.ResourceInfo) OpenEJBException(org.apache.openejb.OpenEJBException)

Example 77 with OpenEJBException

use of org.apache.openejb.OpenEJBException in project tomee by apache.

the class AutoConfigPersistenceUnitsTest method testNonJtaRefToContrarilyConfiguredDataSource2.

/**
 * Existing data source "OrangeOne", jta managed
 * <p/>
 * Persistence xml like so:
 * <p/>
 * <persistence-unit name="orange-unit">
 * <non-jta-data-source>OrangeOne</non-jta-data-source>
 * </persistence-unit>
 * <p/>
 * This configuration should be rejected
 *
 * @throws Exception
 */
public void testNonJtaRefToContrarilyConfiguredDataSource2() throws Exception {
    final ResourceInfo jta = addDataSource("OrangeOne", OrangeDriver.class, "jdbc:orange:some:stuff", true);
    assertSame(jta, resources.get(0));
    try {
        addPersistenceUnit("orange-unit", null, "orangeOne");
        fail("Configuration should be rejected");
    } catch (final OpenEJBException e) {
    // pass
    }
}
Also used : ResourceInfo(org.apache.openejb.assembler.classic.ResourceInfo) OpenEJBException(org.apache.openejb.OpenEJBException)

Example 78 with OpenEJBException

use of org.apache.openejb.OpenEJBException in project tomee by apache.

the class NoServiceJarTest method testInvalid.

public void testInvalid() throws Exception {
    final ConfigurationFactory factory = new ConfigurationFactory();
    final Resource orange = new Resource("Orange");
    orange.getProperties().setProperty("red", "255");
    orange.getProperties().setProperty("green", "200");
    orange.getProperties().setProperty("blue", "0");
    try {
        factory.configureService(orange, ResourceInfo.class);
        fail("OpenEJBException should have been thrown");
    } catch (final OpenEJBException e) {
    // pass
    }
}
Also used : OpenEJBException(org.apache.openejb.OpenEJBException) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory)

Example 79 with OpenEJBException

use of org.apache.openejb.OpenEJBException in project tomee by apache.

the class NoServiceJarTest method testInvalidJustType.

public void testInvalidJustType() throws Exception {
    final ConfigurationFactory factory = new ConfigurationFactory();
    final Resource orange = new Resource("Orange");
    orange.setType(Color.class.getName());
    orange.getProperties().setProperty("red", "255");
    orange.getProperties().setProperty("green", "200");
    orange.getProperties().setProperty("blue", "0");
    try {
        factory.configureService(orange, ResourceInfo.class);
        fail("OpenEJBException should have been thrown");
    } catch (final OpenEJBException e) {
    // pass
    }
}
Also used : OpenEJBException(org.apache.openejb.OpenEJBException) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory)

Example 80 with OpenEJBException

use of org.apache.openejb.OpenEJBException in project tomee by apache.

the class AbstractTomEEMojo method ensureAppsFolderExistAndIsConfiguredByDefault.

private void ensureAppsFolderExistAndIsConfiguredByDefault(final File file) throws IOException {
    if ("openejb".equals(container.toLowerCase(Locale.ENGLISH)) || (file.exists() && ((apps != null && !apps.isEmpty()) || (!"pom".equals(packaging) && !"war".equals(packaging))))) {
        // webapps doesn't need apps folder in tomee
        final String rootTag = container.toLowerCase(Locale.ENGLISH);
        if (file.isFile()) {
            // can be not existing since we dont always deploy tomee but shouldn't since then apps/ is not guaranteed to work
            try {
                final Openejb jaxb = JaxbOpenejb.readConfig(file.getAbsolutePath());
                boolean needAdd = true;
                for (final Deployments d : jaxb.getDeployments()) {
                    if ("apps".equals(d.getDir())) {
                        needAdd = false;
                        break;
                    }
                }
                if (needAdd) {
                    final String content = IO.slurp(file);
                    final FileWriter writer = new FileWriter(file);
                    final String end = "</" + rootTag + ">";
                    writer.write(content.replace(end, "  <Deployments dir=\"apps\" />\n" + end));
                    writer.close();
                }
            } catch (final OpenEJBException e) {
                throw new IllegalStateException("illegal tomee.xml:\n" + IO.slurp(file), e);
            }
        } else {
            final FileWriter writer = new FileWriter(file);
            writer.write("<?xml version=\"1.0\"?>\n" + "<" + rootTag + ">\n" + "  <Deployments dir=\"apps\" />\n" + "</" + rootTag + ">\n");
            writer.close();
        }
        final File appsFolder = new File(catalinaBase, "apps");
        if (!appsFolder.exists() && !appsFolder.mkdirs()) {
            throw new RuntimeException("Failed to create: " + appsFolder);
        }
    }
}
Also used : OpenEJBException(org.apache.openejb.OpenEJBException) OpenEJBRuntimeException(org.apache.openejb.OpenEJBRuntimeException) FileWriter(java.io.FileWriter) Deployments(org.apache.openejb.config.sys.Deployments) ZipFile(java.util.zip.ZipFile) File(java.io.File) Openejb(org.apache.openejb.config.sys.Openejb) JaxbOpenejb(org.apache.openejb.config.sys.JaxbOpenejb)

Aggregations

OpenEJBException (org.apache.openejb.OpenEJBException)187 IOException (java.io.IOException)55 NamingException (javax.naming.NamingException)34 URL (java.net.URL)31 MalformedURLException (java.net.MalformedURLException)30 ApplicationException (org.apache.openejb.ApplicationException)29 BeanContext (org.apache.openejb.BeanContext)29 File (java.io.File)26 ArrayList (java.util.ArrayList)26 OpenEJBRuntimeException (org.apache.openejb.OpenEJBRuntimeException)23 SystemException (org.apache.openejb.SystemException)22 Method (java.lang.reflect.Method)20 HashMap (java.util.HashMap)18 ThreadContext (org.apache.openejb.core.ThreadContext)17 InterceptorData (org.apache.openejb.core.interceptor.InterceptorData)15 RemoteException (java.rmi.RemoteException)14 EJBException (javax.ejb.EJBException)14 EjbTransactionUtil.handleApplicationException (org.apache.openejb.core.transaction.EjbTransactionUtil.handleApplicationException)14 HashSet (java.util.HashSet)13 Properties (java.util.Properties)13