use of org.apache.openejb.OpenEJBException in project tomee by apache.
the class ReadDescriptors method deploy.
@SuppressWarnings({ "unchecked" })
public AppModule deploy(final AppModule appModule) throws OpenEJBException {
for (final EjbModule ejbModule : appModule.getEjbModules()) {
if (ejbModule.getEjbJar() == null) {
readEjbJar(ejbModule, appModule);
}
if (ejbModule.getOpenejbJar() == null) {
readOpenejbJar(ejbModule);
}
if (ejbModule.getBeans() == null) {
readBeans(ejbModule);
}
readValidationConfigType(ejbModule);
readCmpOrm(ejbModule);
readResourcesXml(ejbModule);
}
for (final ClientModule clientModule : appModule.getClientModules()) {
readAppClient(clientModule, appModule);
readValidationConfigType(clientModule);
readResourcesXml(clientModule);
}
for (final ConnectorModule connectorModule : appModule.getConnectorModules()) {
readConnector(connectorModule, appModule);
readValidationConfigType(connectorModule);
readResourcesXml(connectorModule);
}
for (final WebModule webModule : appModule.getWebModules()) {
readWebApp(webModule, appModule);
readValidationConfigType(webModule);
readResourcesXml(webModule);
}
final List<Object> persistenceUrls = (List<Object>) appModule.getAltDDs().get("persistence.xml");
if (persistenceUrls != null) {
for (final Object persistenceUrl : persistenceUrls) {
final boolean url = persistenceUrl instanceof URL;
final Source source = getSource(persistenceUrl);
final String moduleName;
final String path;
final String rootUrl;
if (url) {
final URL pUrl = (URL) persistenceUrl;
File file = URLs.toFile(pUrl);
path = file.getAbsolutePath();
if (file.getName().endsWith("persistence.xml")) {
final File parentFile = file.getParentFile();
final String parent = parentFile.getName();
if (parent.equalsIgnoreCase("WEB-INF") || parent.equalsIgnoreCase("META-INF")) {
file = parentFile.getParentFile();
} else {
// we don't really know so simply go back (users will often put persistence.xml in root resource folder with arquillian)
file = file.getParentFile();
}
}
moduleName = file.toURI().toString();
String tmpRootUrl = moduleName;
final String extForm = pUrl.toExternalForm();
if (extForm.contains("WEB-INF/classes/META-INF/")) {
if (!ROOT_URL_FROM_WEBINF) {
tmpRootUrl = extForm.substring(0, extForm.indexOf("/META-INF"));
} else {
tmpRootUrl = extForm.substring(0, extForm.indexOf("/classes/META-INF"));
}
}
if (tmpRootUrl.endsWith(".war")) {
tmpRootUrl = tmpRootUrl.substring(0, tmpRootUrl.length() - ".war".length());
}
rootUrl = tmpRootUrl;
} else {
moduleName = "";
rootUrl = "";
path = null;
}
try {
final Persistence persistence = JaxbPersistenceFactory.getPersistence(Persistence.class, source.get());
final PersistenceModule persistenceModule = new PersistenceModule(appModule, rootUrl, persistence);
persistenceModule.getWatchedResources().add(moduleName);
if (url && "file".equals(((URL) persistenceUrl).getProtocol())) {
persistenceModule.getWatchedResources().add(path);
}
appModule.addPersistenceModule(persistenceModule);
} catch (final Exception e1) {
DeploymentLoader.LOGGER.error("Unable to load Persistence Unit from EAR: " + appModule.getJarLocation() + ", module: " + moduleName + ". Exception: " + e1.getMessage(), e1);
}
}
}
final List<URL> persistenceFragmentUrls = (List<URL>) appModule.getAltDDs().get("persistence-fragment.xml");
if (persistenceFragmentUrls != null) {
for (final URL persistenceFragmentUrl : persistenceFragmentUrls) {
try {
final PersistenceFragment persistenceFragment = JaxbPersistenceFactory.getPersistence(PersistenceFragment.class, persistenceFragmentUrl);
// merging
for (final PersistenceUnitFragment fragmentUnit : persistenceFragment.getPersistenceUnitFragment()) {
for (final PersistenceModule persistenceModule : appModule.getPersistenceModules()) {
final Persistence persistence = persistenceModule.getPersistence();
for (final PersistenceUnit unit : persistence.getPersistenceUnit()) {
if (!fragmentUnit.getName().equals(unit.getName())) {
continue;
}
if (!persistenceFragment.getVersion().equals(persistence.getVersion())) {
logger.error("persistence unit version and fragment version are different, fragment will be ignored");
continue;
}
if ("file".equals(persistenceFragmentUrl.getProtocol())) {
persistenceModule.getWatchedResources().add(URLs.toFile(persistenceFragmentUrl).getAbsolutePath());
}
for (final String clazz : fragmentUnit.getClazz()) {
if (!unit.getClazz().contains(clazz)) {
logger.info("Adding class " + clazz + " to persistence unit " + fragmentUnit.getName());
unit.getClazz().add(clazz);
}
}
for (final String mappingFile : fragmentUnit.getMappingFile()) {
if (!unit.getMappingFile().contains(mappingFile)) {
logger.info("Adding mapping file " + mappingFile + " to persistence unit " + fragmentUnit.getName());
unit.getMappingFile().add(mappingFile);
}
}
for (final String jarFile : fragmentUnit.getJarFile()) {
if (!unit.getJarFile().contains(jarFile)) {
logger.info("Adding jar file " + jarFile + " to persistence unit " + fragmentUnit.getName());
unit.getJarFile().add(jarFile);
}
}
if (fragmentUnit.isExcludeUnlistedClasses()) {
unit.setExcludeUnlistedClasses(true);
logger.info("Excluding unlisted classes for persistence unit " + fragmentUnit.getName());
}
// else let the main persistence unit decide
}
}
}
} catch (final Exception e1) {
DeploymentLoader.LOGGER.error("Unable to load Persistence Unit Fragment from EAR: " + appModule.getJarLocation() + ", fragment: " + persistenceFragmentUrl.toString() + ". Exception: " + e1.getMessage(), e1);
}
}
}
return appModule;
}
use of org.apache.openejb.OpenEJBException in project tomee by apache.
the class ReadDescriptors method readCmpOrm.
// package scoped for testing
void readCmpOrm(final EjbModule ejbModule) throws OpenEJBException {
final Object data = ejbModule.getAltDDs().get("openejb-cmp-orm.xml");
if (data != null && !(data instanceof EntityMappings)) {
if (data instanceof URL) {
final URL url = (URL) data;
try {
final EntityMappings entitymappings = (EntityMappings) JaxbJavaee.unmarshal(EntityMappings.class, IO.read(url));
ejbModule.getAltDDs().put("openejb-cmp-orm.xml", entitymappings);
} catch (final SAXException e) {
throw new OpenEJBException("Cannot parse the openejb-cmp-orm.xml file: " + url.toExternalForm(), e);
} catch (final JAXBException e) {
throw new OpenEJBException("Cannot unmarshall the openejb-cmp-orm.xml file: " + url.toExternalForm(), e);
} catch (final IOException e) {
throw new OpenEJBException("Cannot read the openejb-cmp-orm.xml file: " + url.toExternalForm(), e);
} catch (final Exception e) {
throw new OpenEJBException("Encountered unknown error parsing the openejb-cmp-orm.xml file: " + url.toExternalForm(), e);
}
}
}
}
use of org.apache.openejb.OpenEJBException in project tomee by apache.
the class ReadDescriptors method readFacesConfig.
public static FacesConfig readFacesConfig(final URL url) throws OpenEJBException {
try {
final Source src = getSource(url);
if (src == null) {
return new FacesConfig();
}
final String content = IO.slurp(src.get());
if (isEmpty(new ByteArrayInputStream(content.getBytes()), "faces-config")) {
return new FacesConfig();
}
return FacesConfigXml.unmarshal(new ByteArrayInputStream(content.getBytes()));
} catch (final SAXException e) {
throw new OpenEJBException("Cannot parse the faces configuration file: " + url.toExternalForm(), e);
} catch (final JAXBException e) {
throw new OpenEJBException("Cannot unmarshall the faces configuration file: " + url.toExternalForm(), e);
} catch (final IOException e) {
throw new OpenEJBException("Cannot read the faces configuration file: " + url.toExternalForm(), e);
} catch (final Exception e) {
throw new OpenEJBException("Encountered unknown error parsing the faces configuration file: " + url.toExternalForm(), e);
}
}
use of org.apache.openejb.OpenEJBException in project tomee by apache.
the class ReadDescriptors method readTldTaglib.
public static TldTaglib readTldTaglib(final URL url) throws OpenEJBException {
// TOMEE-164 Optimization on reading built-in tld files
if (url.getPath().contains("jstl-1.2.jar") || ((url.getPath().contains("taglibs-standard-") || url.getPath().contains("taglibs-shade-") && url.getPath().contains(".jar!")))) {
return SKIP_TAGLIB;
}
if (url.getPath().contains("myfaces-impl")) {
// we should return SKIP_TAGLIB too
final TldTaglib taglib = new TldTaglib();
final Listener listener = new Listener();
listener.setListenerClass("org.apache.myfaces.webapp.StartupServletContextListener");
taglib.getListener().add(listener);
return taglib;
}
try {
return TldTaglibXml.unmarshal(url);
} catch (final SAXException e) {
final String message = "Cannot parse the JSP tag library definition file: " + url.toExternalForm();
logger.warning(message);
logger.debug(message, e);
} catch (final JAXBException e) {
final String message = "Cannot unmarshall the JSP tag library definition file: " + url.toExternalForm();
logger.warning(message);
logger.debug(message, e);
} catch (final IOException e) {
final String message = "Cannot read the JSP tag library definition file: " + url.toExternalForm();
logger.warning(message);
logger.debug(message, e);
} catch (final Exception e) {
final String message = "Encountered unknown error parsing the JSP tag library definition file: " + url.toExternalForm();
logger.warning(message);
logger.debug(message, e);
}
return SKIP_TAGLIB;
}
use of org.apache.openejb.OpenEJBException in project tomee by apache.
the class ServiceUtils method hasServiceProvider.
public static boolean hasServiceProvider(final String id) {
try {
final ProviderInfo info = getProviderInfo(id);
final List<ServiceProvider> services = getServiceProviders(info.getPackageName());
for (final ServiceProvider service : services) {
if (service.getId().equals(id)) {
return true;
}
}
} catch (final OpenEJBException | IllegalStateException ignored) {
// someone else will load the file and get the exception
}
return false;
}
Aggregations