OMElement namePart = messageContext.getEnvelope().getBody().getFirstElement().getFirstElement();
OMElement zipPart = (OMElement) namePart.getNextOMSibling();
OMElement zip = zipPart.getFirstElement();
if (!zipPart.getQName().getLocalPart().equals("package") ||
!zip.getQName().getLocalPart().equals("zip"))
throw new OdeFault("Your message should contain a part named 'package' with a zip element");
OMText binaryNode = (OMText) zip.getFirstOMChild();
if (binaryNode == null) {
throw new OdeFault("Empty binary node under <zip> element");
}
binaryNode.setOptimize(true);
try {
// We're going to create a directory under the deployment root and put
// files in there. The poller shouldn't pick them up so we're asking
// it to hold on for a while.
_poller.hold();
File dest = new File(_deployPath, namePart.getText() + "-" + _store.getCurrentVersion());
dest.mkdir();
unzip(dest, (DataHandler) binaryNode.getDataHandler());
// Check that we have a deploy.xml
File deployXml = new File(dest, "deploy.xml");
if (!deployXml.exists())
throw new OdeFault("The deployment doesn't appear to contain a deployment " +
"descriptor in its root directory named deploy.xml, aborting.");
Collection<QName> deployed = _store.deploy(dest);
File deployedMarker = new File(_deployPath, dest.getName() + ".deployed");
deployedMarker.createNewFile();
// Telling the poller what we deployed so that it doesn't try to deploy it again
_poller.markAsDeployed(dest);
__log.info("Deployment of artifact " + dest.getName() + " successful.");
OMElement response = factory.createOMElement("response", null);
if (__log.isDebugEnabled()) __log.debug("Deployed package: "+dest.getName());
OMElement d = factory.createOMElement("name", null);
d.setText(dest.getName());
response.addChild(d);
for (QName pid : deployed) {
if (__log.isDebugEnabled()) __log.debug("Deployed PID: "+pid);
d = factory.createOMElement("id", null);
d.setText(pid);
response.addChild(d);
}
sendResponse(factory, messageContext, "deployResponse", response);
} finally {
_poller.release();
}
} else if (operation.equals("undeploy")) {
OMElement part = messageContext.getEnvelope().getBody().getFirstElement().getFirstElement();
String pkg = part.getText();
File deploymentDir = new File(_deployPath, pkg);
if (!deploymentDir.exists())
throw new OdeFault("Couldn't find deployment package " + pkg + " in directory " + _deployPath);
try {
// We're going to create a directory under the deployment root and put
// files in there. The poller shouldn't pick them up so we're asking
// it to hold on for a while.
_poller.hold();
Collection<QName> undeployed = _store.undeploy(deploymentDir);
File deployedMarker = new File(_deployPath, pkg + ".deployed");
deployedMarker.delete();
FileUtils.deepDelete(new File(_deployPath, pkg));
OMElement response = factory.createOMElement("response", null);
response.setText("" + (undeployed.size() > 0));
sendResponse(factory, messageContext, "undeployResponse", response);
_poller.markAsUndeployed(deploymentDir);
} finally {
_poller.release();
}
} else if (operation.equals("listDeployedPackages")) {
Collection<String> packageNames = _store.getPackages();
OMElement response = factory.createOMElement("deployedPackages", null);
for (String name : packageNames) {
OMElement nameElmt = factory.createOMElement("name", null);
nameElmt.setText(name);
response.addChild(nameElmt);
}
sendResponse(factory, messageContext, "listDeployedPackagesResponse", response);
} else if (operation.equals("listProcesses")) {
OMElement namePart = messageContext.getEnvelope().getBody().getFirstElement().getFirstElement();
List<QName> processIds = _store.listProcesses(namePart.getText());
OMElement response = factory.createOMElement("processIds", null);
for (QName qname : processIds) {
OMElement nameElmt = factory.createOMElement("id", null);
nameElmt.setText(qname);
response.addChild(nameElmt);
}
sendResponse(factory, messageContext, "listProcessResponse", response);
} else if (operation.equals("getProcessPackage")) {
OMElement qnamePart = messageContext.getEnvelope().getBody().getFirstElement().getFirstElement();
ProcessConf process = _store.getProcessConfiguration(OMUtils.getTextAsQName(qnamePart));
if (process == null) {
throw new OdeFault("Could not find process: " + qnamePart.getTextAsQName());
}
String packageName = _store.getProcessConfiguration(OMUtils.getTextAsQName(qnamePart)).getPackage();
OMElement response = factory.createOMElement("packageName", null);
response.setText(packageName);
sendResponse(factory, messageContext, "getProcessPackageResponse", response);
} else unknown = true;
} catch (Throwable t) {
// Trying to extract a meaningful message
Throwable source = t;
while (source.getCause() != null && source.getCause() != source) source = source.getCause();
__log.warn("Invocation of operation " + operation + " failed", t);
throw new OdeFault("Invocation of operation " + operation + " failed: " + source.toString(), t);
}
if (unknown) throw new OdeFault("Unknown operation: '"
+ messageContext.getAxisOperation().getName() + "'");
}