use of org.glassfish.embeddable.archive.ScatteredArchive in project Payara by payara.
the class BasicCDITest method test.
@Test
public void test() throws Exception {
GlassFishProperties props = new GlassFishProperties();
BootstrapProperties bootstrapProperties = new BootstrapProperties();
props.setPort("http-listener", 8080);
GlassFish glassfish = GlassFishRuntime.bootstrap(bootstrapProperties).newGlassFish(props);
glassfish.start();
// Test Scattered Web Archive
ScatteredArchive sa = new ScatteredArchive("cdi_ejb_jpa", ScatteredArchive.Type.WAR, new File("src/main/webapp"));
sa.addClassPath(new File("target/classes"));
sa.addClassPath(new File("src/main/resources"));
URI warURI = sa.toURI();
printContents(warURI);
// Deploy archive
Deployer deployer = glassfish.getDeployer();
String appname = deployer.deploy(warURI);
System.out.println("Deployed [" + appname + "]");
Assert.assertEquals(appname, "cdi_ejb_jpa");
// Now create a http listener and access the app.
WebContainer webcontainer = glassfish.getService(WebContainer.class);
HttpListener listener = new HttpListener();
listener.setId("my-listener");
listener.setPort(9090);
webcontainer.addWebListener(listener);
get("http://localhost:8080/cdi_ejb_jpa/BasicCDITestServlet", "All CDI beans have been injected.");
deployer.undeploy(appname);
glassfish.dispose();
}
use of org.glassfish.embeddable.archive.ScatteredArchive in project Payara by payara.
the class BasicCDITest method test.
@Test
public void test() throws Exception {
GlassFishProperties props = new GlassFishProperties();
props.setPort("http-listener", 8080);
GlassFish glassfish = GlassFishRuntime.bootstrap().newGlassFish(props);
glassfish.start();
// Test Scattered Web Archive
ScatteredArchive sa = new ScatteredArchive("cdi_basic", ScatteredArchive.Type.WAR, new File("src/main/webapp"));
sa.addClassPath(new File("target/classes"));
sa.addClassPath(new File("src/main/resources"));
URI warURI = sa.toURI();
printContents(warURI);
// Deploy archive
Deployer deployer = glassfish.getDeployer();
String appname = deployer.deploy(warURI);
System.out.println("Deployed [" + appname + "]");
Assert.assertEquals(appname, "cdi_basic");
// Now create a http listener and access the app.
WebContainer webcontainer = glassfish.getService(WebContainer.class);
HttpListener listener = new HttpListener();
listener.setId("my-listener");
listener.setPort(9090);
webcontainer.addWebListener(listener);
get("http://localhost:8080/cdi_basic/BasicCDITestServlet", "All CDI beans have been injected.");
deployer.undeploy(appname);
glassfish.dispose();
}
use of org.glassfish.embeddable.archive.ScatteredArchive in project Payara by payara.
the class DeploymentElement method getOrCreateApplication.
/**
* Create deployable application from a Set of DeploymentElements.
* @param modules the Set of DeploymentElements.
* @return deployable application.
*/
public static ResultApplication getOrCreateApplication(Set<DeploymentElement> modules, String appName) throws EJBException, IOException {
Object result = null;
boolean deleteOnExit = false;
if (modules == null || modules.size() == 0 || !DeploymentElement.hasEJBModule(modules)) {
_logger.severe("[DeploymentElement] No modules found");
} else if (appName == null && DeploymentElement.countEJBModules(modules) == 1) {
// Use the single component as-is
if (modules.size() == 1) {
// Single EJB module
result = modules.iterator().next().getElement();
} else if (DeploymentElement.countEJBModules(modules) == 1 && DeploymentElement.hasWar(modules)) {
// A WAR file with an EJB
result = DeploymentElement.getWar(modules).getElement();
} else {
// EJB molule with libraries - create ScatteredArchive
ScatteredArchive sa = null;
for (DeploymentElement m : modules) {
if (m.isEJBModule) {
// XXX Work around GLASSFISH-16618
// The name was already calculated when DeploymentElement was created
sa = new ScatteredArchive(m.mname, ScatteredArchive.Type.JAR);
if (_logger.isLoggable(Level.INFO)) {
_logger.info("[DeploymentElement] adding EJB module to ScatteredArchive " + m.mname);
}
sa.addClassPath(m.element);
break;
}
}
if (sa != null) {
for (DeploymentElement m : modules) {
if (!m.isEJBModule) {
if (_logger.isLoggable(Level.INFO)) {
_logger.info("[DeploymentElement] adding library to ScatteredArchive " + m.element.getName());
}
sa.addClassPath(m.element);
}
}
result = sa;
}
}
} else {
// Create an ear if appName is set or if there is more than 1 EJB module
// Create a temp dir by creating a temp file first, then
// delete the file and create a directory in its place.
File resultFile = File.createTempFile("ejb-app", "");
File lib = null;
if (resultFile.delete() && resultFile.mkdirs()) {
if (_logger.isLoggable(Level.FINE)) {
_logger.fine("[DeploymentElement] temp dir created at " + resultFile.getAbsolutePath());
}
// Create lib dir if there are library entries
if (DeploymentElement.hasLibrary(modules)) {
if (_logger.isLoggable(Level.FINE)) {
_logger.fine("[DeploymentElement] lib dir added ... ");
}
lib = new File(resultFile, "lib");
}
} else {
throw new EJBException("Not able to create temp dir " + resultFile.getAbsolutePath());
}
// Copy module directories and explode module jars
int duplicate_dir_counter = 0;
for (DeploymentElement m : modules) {
File f = m.element;
if (_logger.isLoggable(Level.INFO)) {
_logger.info("[DeploymentElement] adding " + f.getName() + " to exploded ear " + " isEJBModule? " + m.isEJBModule + " isWebApp? " + m.isWebApp);
}
String filename = f.toURI().getSchemeSpecificPart();
if (filename.endsWith(File.separator) || filename.endsWith("/")) {
int length = filename.length();
filename = filename.substring(0, length - 1);
}
int lastpart = filename.lastIndexOf(File.separatorChar);
if (lastpart == -1) {
lastpart = filename.lastIndexOf('/');
}
String name = filename.substring(lastpart + 1);
if (_logger.isLoggable(Level.FINE)) {
_logger.fine("[DeploymentElement] Converted file name: " + filename + " to " + name);
}
File base = (m.isEJBModule) ? resultFile : lib;
if (!f.isDirectory() && m.isEJBModule) {
File out = new File(base, FileUtils.makeFriendlyFilename(name));
if (_logger.isLoggable(Level.FINE)) {
_logger.fine("[DeploymentElement] Exploding jar to: " + out);
}
ModuleExploder.explodeJar(f, out);
} else {
if (f.isDirectory()) {
name = name + (m.isWebApp ? "_war" : (m.isEJBModule ? "_jar" : ".jar"));
}
File out = new File(base, name);
if (out.exists()) {
out = new File(base, "d__" + ++duplicate_dir_counter + "__" + name);
}
if (_logger.isLoggable(Level.FINE)) {
_logger.fine("[DeploymentElement] Copying element to: " + out);
}
FileUtils.copy(f, out);
}
}
// Check if the archive should not be deleted at the end
deleteOnExit = !Boolean.getBoolean(EJBContainerProviderImpl.KEEP_TEMPORARY_FILES);
if (appName == null) {
appName = "ejb-app";
}
result = resultFile;
}
return new ResultApplication(result, appName, deleteOnExit);
}
use of org.glassfish.embeddable.archive.ScatteredArchive in project Payara by payara.
the class ScatteredArchiveTest method test.
@Test
public void test() throws Exception {
GlassFishProperties props = new GlassFishProperties();
props.setPort("http-listener", 8080);
GlassFish glassfish = GlassFishRuntime.bootstrap().newGlassFish(props);
glassfish.start();
// Test Scattered Web Archive
ScatteredArchive sa = new ScatteredArchive("scatteredarchive", ScatteredArchive.Type.WAR, new File("src/main/webapp"));
sa.addClassPath(new File("target/classes"));
sa.addClassPath(new File("src/main/resources"));
URI warURI = sa.toURI();
printContents(warURI);
// Deploy archive
Deployer deployer = glassfish.getDeployer();
String appname = deployer.deploy(warURI);
System.out.println("Deployed [" + appname + "]");
Assert.assertEquals(appname, "scatteredarchive");
// Now create a http listener and access the app.
WebContainer webcontainer = glassfish.getService(WebContainer.class);
HttpListener listener = new HttpListener();
listener.setId("my-listener");
listener.setPort(9090);
webcontainer.addWebListener(listener);
get("http://localhost:9090/satest", "Hi, my name is Bhavani. What's yours?");
get("http://localhost:9090/satest/ScatteredArchiveTestServlet", "Hi from ScatteredArchiveTestServlet");
get("http://localhost:8080/satest/ScatteredArchiveTestServlet", "Hi from ScatteredArchiveTestServlet");
deployer.undeploy(appname);
// Test Scattered RA
ScatteredArchive rar = new ScatteredArchive("scatteredra", ScatteredArchive.Type.RAR);
rar.addClassPath(new File("target/classes"));
rar.addMetadata(new File("src/main/config/ra.xml"));
URI rarURI = rar.toURI();
printContents(rarURI);
appname = deployer.deploy(rarURI);
System.out.println("Deployed RAR [" + appname + "]");
Assert.assertEquals(appname, "scatteredra");
// Test Scattered Enterprise Archive.
ScatteredEnterpriseArchive ear = new ScatteredEnterpriseArchive("sear");
ear.addArchive(warURI, "sa.war");
ear.addArchive(rarURI);
ear.addMetadata(new File("src/main/config/application.xml"));
URI earURI = ear.toURI();
printContents(earURI);
appname = deployer.deploy(earURI);
System.out.println("Deployed [" + appname + "]");
Assert.assertEquals(appname, "sear");
get("http://localhost:9090/satest", "Hi, my name is Bhavani. What's yours?");
get("http://localhost:9090/satest/ScatteredArchiveTestServlet", "Hi from ScatteredArchiveTestServlet");
get("http://localhost:8080/satest/ScatteredArchiveTestServlet", "Hi from ScatteredArchiveTestServlet");
glassfish.dispose();
}
use of org.glassfish.embeddable.archive.ScatteredArchive in project Payara by payara.
the class EJBContainerImpl method deploy.
/**
* Construct new EJBContainerImpl instance and deploy found modules.
*/
void deploy(Map<?, ?> properties, Set<DeploymentElement> modules) throws EJBException {
try {
String appName = (properties == null) ? null : (String) properties.get(EJBContainer.APP_NAME);
res_app = DeploymentElement.getOrCreateApplication(modules, appName);
Object app = res_app.getApplication();
if (app == null) {
throw new EJBException("Invalid set of modules to deploy - see log for details");
}
if (_logger.isLoggable(Level.INFO)) {
_logger.info("[EJBContainerImpl] Deploying app: " + app);
}
// Check if appName was set by application creation code
appName = res_app.getAppName();
String[] params;
if (appName != null) {
params = new String[] { "--name", appName };
} else {
params = new String[] {};
}
_logger.info("[EJBContainerImpl] GlassFish status: " + server.getStatus());
if (app instanceof ScatteredArchive) {
_logger.info("[EJBContainerImpl] Deploying as a ScatteredArchive");
deployedAppName = deployer.deploy(((ScatteredArchive) app).toURI(), params);
} else {
_logger.info("[EJBContainerImpl] Deploying as a File");
deployedAppName = deployer.deploy((File) app, params);
}
} catch (Exception e) {
throw new EJBException("Failed to deploy EJB modules", e);
}
if (deployedAppName == null) {
throw new EJBException("Failed to deploy EJB modules - see log for details");
}
}
Aggregations