protected void doDeploy( DeploymentEvent event ) throws DeploymentException
{
InputStream portletXmlStream = null;
try
{
DeploymentObject deploymentObj = event.getDeploymentObject();
portletXmlStream = deploymentObj.getConfiguration("WEB-INF/portlet.xml");
if (portletXmlStream == null)
{
return;
}
String fileName = deploymentObj.getName();
boolean isLocal = fileName.startsWith("jetspeed-");
log.info("Loading portlet application from web archive " + deploymentObj.getPath());
SAXBuilder builder = new SAXBuilder();
Document portletXml = builder.build(portletXmlStream);
Element portletApp = portletXml.getRootElement();
String id = portletApp.getAttributeValue("id");
if (id == null)
{
String warFileName = fileName;
int extensionIdx = warFileName.lastIndexOf(".war");
id = warFileName.substring(0, extensionIdx);
log.info("Application id not defined in portlet.xml so using war name " + id);
}
PortletApplicationWar paWar = new PortletApplicationWar(deploymentObj.getFileObject(), id, "/" + id );
if (registry.getPortletApplicationByIdentifier(id) != null
&& !event.getEventType().equals(DeploymentEvent.EVENT_TYPE_REDEPLOY))
{
log.info("Portlet application \"" + id + "\""
+ " already been registered. Skipping initial deployment.");
// still need to register the filename to the app name so
// undeploy works correctly
appNameToFile.put(deploymentObj.getPath(), id);
if (isLocal)
{
portletFactory.addClassLoader(
registry.getPortletApplicationByIdentifier(id).getId().toString(),
paWar.createClassloader(getClass().getClassLoader()));
}
else
{
try
{
ClassLoader classloader = createPortletClassloader(getClass().getClassLoader(), id);
if (classloader != null)
{
portletFactory.addClassLoader(
registry.getPortletApplicationByIdentifier(id).getId().toString(),
classloader);
}
}
catch (IOException e1)
{
log.info("Could not add Portlet Class Loader: " + id);
}
}
return;
}
log.info("Preparing to (re) deploy portlet app \"" + id + "\"");
if (event.getEventType().equals(DeploymentEvent.EVENT_TYPE_DEPLOY))
{
if (isLocal)
{
log.info(fileName + " will be registered as a local portlet applicaiton.");
pam.register(paWar);
MutablePortletApplication mpa = registry.getPortletApplicationByIdentifier(id);
if (mpa != null)
{
portletFactory.addClassLoader(
mpa.getId().toString(),
paWar.createClassloader(getClass().getClassLoader()));
}
}
else
{
log.info("Deploying portlet applicaion WAR " + fileName);
pam.deploy(paWar);
try
{
ClassLoader classloader = createPortletClassloader(getClass().getClassLoader(), id);
if (classloader != null)
{
MutablePortletApplication mpa = registry.getPortletApplicationByIdentifier(id);
if (mpa != null)
{
portletFactory.addClassLoader(mpa.getId().toString(), classloader);
}
}
}
catch (IOException e1)
{
log.info("Could not add Portlet Class Loader: " + id);
}
}
}
else if (event.getEventType().equals(DeploymentEvent.EVENT_TYPE_REDEPLOY))
{
if (isLocal)
{
//TODO: get this working
}
else
{
log.info("Re-deploying portlet applicaion WAR " + fileName);
pam.redeploy(paWar);
}
}
appNameToFile.put(deploymentObj.getPath(), id);
log.info("Portlet app \"" + id + "\" " + "successfuly (re)deployed.");
}
catch (Exception e)
{
String msg = "Error (re)deploying portlet app: " + e.toString();