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);
}
}
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);
}
}
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");
}
}
}
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);
}
}
}
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());
}
}
Aggregations