use of org.apache.openejb.OpenEJBException in project tomee by apache.
the class JaxRpcServiceInfoBuilder method getMethodMappingForOperation.
private ServiceEndpointMethodMapping getMethodMappingForOperation(String operationName, Class serviceEndpointInterface) throws OpenEJBException {
// get mapping for service endpoint interface
ServiceEndpointInterfaceMapping interfaceMapping = javaWsdlMapping.getServiceEndpointInterfaceMappingMap().get(serviceEndpointInterface.getName());
if (interfaceMapping == null) {
throw new OpenEJBException("No java-wsdl mapping found for the service interface " + serviceEndpointInterface);
}
// match by operation name
for (ServiceEndpointMethodMapping methodMapping : interfaceMapping.getServiceEndpointMethodMapping()) {
if (operationName.equals(methodMapping.getWsdlOperation())) {
return methodMapping;
}
}
// failed - throw nice exception message
StringBuffer availOps = new StringBuffer(128);
for (ServiceEndpointMethodMapping methodMapping : interfaceMapping.getServiceEndpointMethodMapping()) {
if (availOps.length() > 0)
availOps.append(",");
availOps.append(methodMapping.getWsdlOperation());
}
throw new OpenEJBException("No method found for operation named '" + operationName + "'. Available operations: " + availOps);
}
use of org.apache.openejb.OpenEJBException in project tomee by apache.
the class DeployerEjb method deploy.
@Override
public AppInfo deploy(final String inLocation, Properties properties) throws OpenEJBException {
String rawLocation = inLocation;
if (rawLocation == null && properties == null) {
throw new NullPointerException("location and properties are null");
}
if (rawLocation == null) {
rawLocation = properties.getProperty(FILENAME);
}
if (properties == null) {
properties = new Properties();
}
AppModule appModule = null;
final File file;
if ("true".equalsIgnoreCase(properties.getProperty(OPENEJB_USE_BINARIES, "false"))) {
file = copyBinaries(properties);
} else {
file = new File(realLocation(rawLocation).iterator().next());
}
final boolean autoDeploy = Boolean.parseBoolean(properties.getProperty(OPENEJB_APP_AUTODEPLOY, "false"));
final String host = properties.getProperty(OPENEJB_DEPLOYER_HOST, null);
if (WebAppDeployer.Helper.isWebApp(file) && !oldWarDeployer) {
AUTO_DEPLOY.set(autoDeploy);
try {
final AppInfo appInfo = SystemInstance.get().getComponent(WebAppDeployer.class).deploy(host, contextRoot(properties, file.getAbsolutePath()), file);
if (appInfo != null) {
saveIfNeeded(properties, file, appInfo);
return appInfo;
}
throw new OpenEJBException("can't deploy " + file.getAbsolutePath());
} finally {
AUTO_DEPLOY.remove();
}
}
AppInfo appInfo = null;
try {
appModule = deploymentLoader.load(file, null);
// Add any alternate deployment descriptors to the modules
final Map<String, DeploymentModule> modules = new TreeMap<>();
for (final DeploymentModule module : appModule.getEjbModules()) {
modules.put(module.getModuleId(), module);
}
for (final DeploymentModule module : appModule.getClientModules()) {
modules.put(module.getModuleId(), module);
}
for (final WebModule module : appModule.getWebModules()) {
final String contextRoot = contextRoot(properties, module.getJarLocation());
if (contextRoot != null) {
module.setContextRoot(contextRoot);
module.setHost(host);
}
modules.put(module.getModuleId(), module);
}
for (final DeploymentModule module : appModule.getConnectorModules()) {
modules.put(module.getModuleId(), module);
}
for (final Map.Entry<Object, Object> entry : properties.entrySet()) {
String name = (String) entry.getKey();
if (name.startsWith(ALT_DD + "/")) {
name = name.substring(ALT_DD.length() + 1);
final DeploymentModule module;
final int slash = name.indexOf('/');
if (slash > 0) {
final String moduleId = name.substring(0, slash);
name = name.substring(slash + 1);
module = modules.get(moduleId);
} else {
module = appModule;
}
if (module != null) {
final String value = (String) entry.getValue();
final File dd = new File(value);
if (dd.canRead()) {
module.getAltDDs().put(name, dd.toURI().toURL());
} else {
module.getAltDDs().put(name, value);
}
}
}
}
final OpenEjbConfiguration configuration = new OpenEjbConfiguration();
configuration.containerSystem = new ContainerSystemInfo();
configuration.facilities = new FacilitiesInfo();
final ConfigurationFactory configurationFactory = new ConfigurationFactory(false, configuration);
appInfo = configurationFactory.configureApplication(appModule);
appInfo.autoDeploy = autoDeploy;
if (properties != null && properties.containsKey(OPENEJB_DEPLOYER_FORCED_APP_ID_PROP)) {
appInfo.appId = properties.getProperty(OPENEJB_DEPLOYER_FORCED_APP_ID_PROP);
}
if (!appInfo.webApps.isEmpty()) {
appInfo.properties.setProperty("tomcat.unpackWar", "false");
}
// create any resources and containers defined in the application itself
if (!appInfo.webApps.isEmpty()) {
appInfo.properties.setProperty("tomcat.unpackWar", "false");
}
final ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
final ClassLoader appClassLoader = assembler.createAppClassLoader(appInfo);
try {
Thread.currentThread().setContextClassLoader(appClassLoader);
for (final ResourceInfo resource : configuration.facilities.resources) {
assembler.createResource(resource);
}
for (final ContainerInfo container : configuration.containerSystem.containers) {
assembler.createContainer(container);
}
} finally {
Thread.currentThread().setContextClassLoader(oldCl);
}
assembler.createApplication(appInfo, appClassLoader);
saveIfNeeded(properties, file, appInfo);
return appInfo;
} catch (final Throwable e) {
// destroy the class loader for the failed application
if (appModule != null) {
ClassLoaderUtil.destroyClassLoader(appModule.getJarLocation());
}
if (null != appInfo) {
ClassLoaderUtil.destroyClassLoader(appInfo.appId, appInfo.path);
}
LOGGER.error("Can't deploy " + inLocation, e);
if (e instanceof ValidationException) {
throw (ValidationException) e;
}
final Throwable ex;
final DeploymentExceptionManager dem = SystemInstance.get().getComponent(DeploymentExceptionManager.class);
if (dem != null) {
if (dem.hasDeploymentFailed()) {
ex = dem.getLastException();
} else {
ex = e;
}
if (appInfo != null) {
dem.clearLastException(appInfo);
}
} else {
ex = e;
}
if (ex instanceof OpenEJBException) {
if (ex.getCause() instanceof ValidationException) {
throw (ValidationException) ex.getCause();
}
throw (OpenEJBException) ex;
}
throw new OpenEJBException(ex);
}
}
use of org.apache.openejb.OpenEJBException in project tomee by apache.
the class DeployerEjb method copyBinaries.
private synchronized File copyBinaries(final Properties props) throws OpenEJBException {
final File dump = ProvisioningResolver.cacheFile(props.getProperty(OPENEJB_PATH_BINARIES, "dump.war"));
if (dump.exists()) {
Files.delete(dump);
final String name = dump.getName();
if (name.endsWith("ar") && name.length() > 4) {
final File exploded = new File(dump.getParentFile(), name.substring(0, name.length() - 4));
if (exploded.exists()) {
Files.delete(exploded);
}
}
}
try {
IO.copy(byte[].class.cast(props.get(OPENEJB_VALUE_BINARIES)), dump);
} catch (final IOException e) {
throw new OpenEJBException(e);
}
return dump;
}
use of org.apache.openejb.OpenEJBException in project tomee by apache.
the class TomEEContainer method deploy.
@Override
public ProtocolMetaData deploy(final Archive<?> archive) throws DeploymentException {
try {
final Dump dump = dumpFile(archive);
final File file = dump.getFile();
final String fileName = file.getName();
if (dump.isCreated() && (fileName.endsWith(".war") || fileName.endsWith(".ear"))) {
// extracted folder, TODO: openejb work dir is ignored here
Files.deleteOnExit(new File(file.getParentFile(), fileName.substring(0, fileName.length() - 4)));
}
final AppInfo appInfo;
final String archiveName = archive.getName();
try {
if (dump.isCreated() || !configuration.isSingleDeploymentByArchiveName(archiveName)) {
appInfo = doDeploy(archive, file);
if (appInfo != null) {
moduleIds.put(archiveName, new DeployedApp(appInfo.path, file));
// "i" folder
Files.deleteOnExit(file);
}
} else {
final String path = moduleIds.get(archiveName).path;
AppInfo selected = null;
for (final AppInfo info : getDeployedApps()) {
if (path.equals(info.path)) {
selected = info;
break;
}
}
appInfo = selected;
}
if (appInfo == null) {
LOGGER.severe("appInfo was not found for " + file.getPath() + ", available are: " + apps());
throw new OpenEJBException("can't get appInfo");
}
} catch (final OpenEJBException re) {
// clean up in undeploy needs it
moduleIds.put(archiveName, new DeployedApp(file.getPath(), file));
throw re;
}
if (options.get("tomee.appinfo.output", false)) {
Info.marshal(appInfo);
}
final HTTPContext httpContext = new HTTPContext(configuration.getHost(), configuration.getHttpPort());
addArquillianServlet(archive, appInfo, archiveName, httpContext);
addServlets(httpContext, appInfo);
return new ProtocolMetaData().addContext(httpContext);
} catch (final Exception e) {
throw new DeploymentException("Unable to deploy", e);
}
}
use of org.apache.openejb.OpenEJBException in project tomee by apache.
the class TomcatWebAppBuilder method loadApplication.
/**
* Creates an openejb {@link AppModule} instance
* from given tomcat context.
*
* @param standardContext tomcat context instance
* @return a openejb application module
*/
private AppModule loadApplication(final StandardContext standardContext) {
// don't use getId since the app id shouldnt get the host (jndi)
// final TomcatDeploymentLoader tomcatDeploymentLoader = new TomcatDeploymentLoader(standardContext, getId(standardContext));
String id = standardContext.getName();
if (id.startsWith("/")) {
id = id.substring(1);
}
final TomcatDeploymentLoader tomcatDeploymentLoader = new TomcatDeploymentLoader(standardContext, id);
final AppModule appModule;
try {
appModule = tomcatDeploymentLoader.load(Contexts.warPath(standardContext), configuredClasspath(standardContext));
} catch (final OpenEJBException e) {
throw new TomEERuntimeException(e);
}
// create the web module
loadWebModule(appModule, standardContext);
return appModule;
}
Aggregations