Search in sources :

Example 96 with OpenEJBException

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

the class VmDeploymentManager method deploy.

private ProgressObject deploy(final Target[] targetList, final Properties properties) {
    if (targetList == null) {
        return new ProgressObjectImpl(CommandType.DISTRIBUTE, new NullPointerException("targetList is null"));
    }
    if (!containsDefaultTarget(targetList)) {
        return new ProgressObjectImpl(CommandType.DISTRIBUTE, Collections.<TargetModuleID>emptySet());
    }
    try {
        final AppInfo appInfo = getDeployer().deploy(properties);
        final TargetModuleID targetModuleId = toTargetModuleId(appInfo, null);
        return new ProgressObjectImpl(CommandType.DISTRIBUTE, Collections.singleton(targetModuleId));
    } catch (ValidationFailedException e) {
        final String s = JavaSecurityManagers.getSystemProperty(ReportValidationResults.VALIDATION_LEVEL, "3");
        final int level = Integer.parseInt(s);
        final ByteArrayOutputStream baos = new ByteArrayOutputStream();
        final PrintStream out = new PrintStream(baos);
        out.println(e.getMessage());
        print(e.getErrors(), out, level);
        print(e.getFailures(), out, level);
        print(e.getWarnings(), out, level);
        out.close();
        e = new ValidationFailedException(new String(baos.toByteArray()), e);
        return new ProgressObjectImpl(CommandType.DISTRIBUTE, e);
    } catch (final OpenEJBException e) {
        return new ProgressObjectImpl(CommandType.DISTRIBUTE, e);
    }
}
Also used : PrintStream(java.io.PrintStream) OpenEJBException(org.apache.openejb.OpenEJBException) TargetModuleID(javax.enterprise.deploy.spi.TargetModuleID) ByteArrayOutputStream(java.io.ByteArrayOutputStream) WebAppInfo(org.apache.openejb.assembler.classic.WebAppInfo) AppInfo(org.apache.openejb.assembler.classic.AppInfo)

Example 97 with OpenEJBException

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

the class ReadDescriptors method readBeans.

public static Beans readBeans(final InputStream inputStream) throws OpenEJBException {
    try {
        final String content = IO.slurp(inputStream).trim();
        if (content.length() == 0) {
            // otherwise we want to read <beans /> attributes
            final Beans beans = new Beans();
            // backward compatibility
            beans.setBeanDiscoveryMode("ALL");
            return beans;
        }
        return (Beans) JaxbJavaee.unmarshalJavaee(Beans.class, new ByteArrayInputStream(content.getBytes()));
    } catch (final SAXException e) {
        // file: " + url.toExternalForm(), e);
        throw new OpenEJBException("Cannot parse the beans.xml", e);
    } catch (final JAXBException e) {
        e.printStackTrace();
        // file: " + url.toExternalForm(), e);
        throw new OpenEJBException("Cannot unmarshall the beans.xml", e);
    } catch (final IOException e) {
        // file: " + url.toExternalForm(), e);
        throw new OpenEJBException("Cannot read the beans.xml", e);
    } catch (final Exception e) {
        // file: " + url.toExternalForm(), e);
        throw new OpenEJBException("Encountered unknown error parsing the beans.xml", e);
    }
}
Also used : OpenEJBException(org.apache.openejb.OpenEJBException) CompositeBeans(org.apache.openejb.cdi.CompositeBeans) Beans(org.apache.openejb.jee.Beans) ByteArrayInputStream(java.io.ByteArrayInputStream) JAXBException(javax.xml.bind.JAXBException) IOException(java.io.IOException) OpenEJBException(org.apache.openejb.OpenEJBException) JAXBException(javax.xml.bind.JAXBException) SAXException(org.xml.sax.SAXException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException)

Example 98 with OpenEJBException

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

the class ReadDescriptors method readValidationConfigType.

private void readValidationConfigType(final Module module) throws OpenEJBException {
    if (module.getValidationConfig() != null) {
        return;
    }
    final Source value = getSource(module.getAltDDs().get("validation.xml"));
    if (value != null) {
        try {
            final ValidationConfigType validationConfigType = JaxbOpenejb.unmarshal(ValidationConfigType.class, value.get(), false);
            module.setValidationConfig(validationConfigType);
        } catch (final Exception e) {
            logger.warning("can't read validation.xml to construct a validation factory, it will be ignored");
        }
    }
}
Also used : ValidationConfigType(org.apache.openejb.jee.bval.ValidationConfigType) InputSource(org.xml.sax.InputSource) OpenEJBException(org.apache.openejb.OpenEJBException) JAXBException(javax.xml.bind.JAXBException) SAXException(org.xml.sax.SAXException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 99 with OpenEJBException

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

the class ReadDescriptors method readBeans.

private void readBeans(final EjbModule ejbModule) throws OpenEJBException {
    if (ejbModule.getBeans() != null) {
        return;
    }
    final Object raw = ejbModule.getAltDDs().get("beans.xml");
    final Source data = getSource(raw);
    if (data != null) {
        try {
            final Beans beans = readBeans(data.get());
            checkDuplicatedByBeansXml(beans, beans);
            if (UrlSource.class.isInstance(data)) {
                beans.setUri(UrlSource.class.cast(data).getUrl().toExternalForm());
            } else {
                beans.setUri("jar:file://" + ejbModule.getModuleId() + "!/META-INF/beans.xml");
            }
            ejbModule.setBeans(beans);
        } catch (final IOException e) {
            throw new OpenEJBException(e);
        }
    } else if (raw instanceof Beans) {
        ejbModule.setBeans((Beans) raw);
    } else if (List.class.isInstance(raw)) {
        final CompositeBeans compositeBeans = new CompositeBeans();
        final List list = List.class.cast(raw);
        if (!list.isEmpty()) {
            for (final Object o : list) {
                try {
                    final UrlSource urlSource = UrlSource.class.cast(o);
                    mergeBeansXml(compositeBeans, readBeans(urlSource.get()), urlSource.getUrl());
                } catch (final IOException e) {
                    throw new OpenEJBException(e);
                }
            }
            ejbModule.setBeans(compositeBeans);
        }
    }
}
Also used : CompositeBeans(org.apache.openejb.cdi.CompositeBeans) OpenEJBException(org.apache.openejb.OpenEJBException) CompositeBeans(org.apache.openejb.cdi.CompositeBeans) Beans(org.apache.openejb.jee.Beans) List(java.util.List) IOException(java.io.IOException) InputSource(org.xml.sax.InputSource)

Example 100 with OpenEJBException

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

the class ReadDescriptors method readEjbJar.

public void readEjbJar(final EjbModule ejbModule, final AppModule appModule) throws OpenEJBException {
    if (ejbModule.getEjbJar() != null) {
        return;
    }
    final Source data = getSource(ejbModule.getAltDDs().get("ejb-jar.xml"));
    if (data != null) {
        try {
            final EjbJar ejbJar = readEjbJar(data.get());
            ejbModule.setEjbJar(ejbJar);
        } catch (final IOException e) {
            throw new OpenEJBException(e);
        }
    } else {
        DeploymentLoader.logger.debug("No ejb-jar.xml found assuming annotated beans present: " + appModule.getJarLocation() + ", module: " + ejbModule.getModuleId());
        ejbModule.setEjbJar(new EjbJar());
    }
}
Also used : OpenEJBException(org.apache.openejb.OpenEJBException) IOException(java.io.IOException) InputSource(org.xml.sax.InputSource) EjbJar(org.apache.openejb.jee.EjbJar)

Aggregations

OpenEJBException (org.apache.openejb.OpenEJBException)179 IOException (java.io.IOException)54 NamingException (javax.naming.NamingException)32 URL (java.net.URL)31 MalformedURLException (java.net.MalformedURLException)30 BeanContext (org.apache.openejb.BeanContext)27 File (java.io.File)26 ArrayList (java.util.ArrayList)26 ApplicationException (org.apache.openejb.ApplicationException)23 OpenEJBRuntimeException (org.apache.openejb.OpenEJBRuntimeException)23 Method (java.lang.reflect.Method)19 HashMap (java.util.HashMap)18 SystemException (org.apache.openejb.SystemException)16 EJBException (javax.ejb.EJBException)14 RemoteException (java.rmi.RemoteException)13 HashSet (java.util.HashSet)13 Properties (java.util.Properties)13 EJBAccessException (javax.ejb.EJBAccessException)13 ThreadContext (org.apache.openejb.core.ThreadContext)13 Context (javax.naming.Context)12