Issue Details (XML | Word | Printable)

Key: OSGI-800
Type: Improvement Improvement
Status: Open Open
Priority: Major Major
Assignee: Costin Leau
Reporter: Christian Baranowski
Votes: 0
Watchers: 2
Operations

If you were logged in you would be able to see more operations.
Spring OSGi

TomcatWarDeoployer with Hot Deployment Mode

Created: 30/Jan/10 07:03 AM   Updated: 30/Jan/10 07:16 AM
Component/s: WEB
Affects Version/s: 1.2.1
Fix Version/s: None

Time Tracking:
Not Specified

File Attachments: 1. Java Source File TomcatWarDeployer.java (10 kB)



 Description  « Hide
For developing web application in eclipse with spring dynamic modules (spring OSGi) there is no mode in which the web resource like JSP etc. will be refresh automatically in the tomcat container. At the moment I must restart a war bundle when a resource changed and the war bundle will be redeployed by spring web bundle. The restart (redeploy) can be done in eclipse automatic when a resource in the eclipse project change with the STS features, see my previous post about STS (Spring Tool Suite). This is nice for Java classes but not for web resources like JSPs, CSS, etc.

At the development time e.g. in eclipse, normally I have no archive war or jar, I have a eclipse projects, with a war directory structure. So my idea was to patch the TomcatWarDeployer from the Spring Web bundle and put a hot deployment mode into it. In the hot deployment mode the war must installed from a directory (not as jar or war archive) in the OSGi container (in my case the eclipse project folder). The TomcatWarDeploy then do not deploy the files in temp folder the deployer runs the webapp in the project folder e.g. in the eclipse project.

So I patched the TomcatWarDeploy with follow code to get a Hot Deployment Mode for web ressource:
private String createDocBase(Bundle bundle, String contextPath) throws IOException {
try
{
String hotdeployMode = System.getProperty(TOMCAT_HOTDEPLOY);
if(hotdeployMode != null && hotdeployMode.toLowerCase().equals("true")){
if (log.isDebugEnabled())
log.debug("HOT Deployment mode is active. Use this feature only for developing!");
String workspace = System.getProperty(TOMCAT_WORKSPACE);
if(workspace != null){
if (log.isDebugEnabled())
log.debug("HOT Deployment workspace is set to: " + workspace);
File workspaceFile = new File(workspace);
if(workspaceFile.exists()){
String projectName = bundle.getSymbolicName();
if (log.isDebugEnabled())
log.debug("HOT Deployment project name is: " + projectName);
File projectFile = new File(workspaceFile, projectName);
if(projectFile.exists() && projectFile.isDirectory()){
if (log.isDebugEnabled())
log.debug("HOT Deployment project path is: " + projectFile.getCanonicalPath());
return projectFile.getCanonicalPath();
}else{
if (log.isDebugEnabled())
log.debug("HOT Deployment project does not exists!");
}
}
else{
if (log.isDebugEnabled())
log.debug("HOT Deployment workspace does not exists!");
}
}
else{
if (log.isDebugEnabled())
log.debug("HOT Deployment workspace path is not set, please set system property " + TOMCAT_WORKSPACE);
}
}
} catch(Exception exp) {
if (log.isDebugEnabled()){
log.debug("Error initializing HOT Deployment!");
log.debug(exp);
}
}

if (log.isDebugEnabled())
log.debug("Use the normal spring deploymode with temp directory.");

File tmpFile = File.createTempFile("tomcat-" + contextPath.substring(1), ".osgi");
tmpFile.delete();
tmpFile.mkdir();

String path = tmpFile.getCanonicalPath();
if (log.isDebugEnabled())
log.debug("Unpacking bundle [" + OsgiStringUtils.nullSafeNameAndSymName(bundle) + "] to folder [" + path
+ "]...");

Utils.unpackBundle(bundle, tmpFile);

return path;
}

Works for me it not very nice but it works, the class is also attached to the ticket. But I think to develop webapps we node such a mode, I don't know if Hot Depkloyment is the correct name for this kind of feature.

Best Regards

Christian