Fix AR-1536: Customer raised issue where broken webscript caused repo to fail at startup

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@6086 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
David Caruana
2007-06-25 10:11:41 +00:00
parent 62ecfb6733
commit 4417106b53

View File

@@ -207,6 +207,8 @@ public class DeclarativeWebScriptRegistry extends AbstractLifecycleBean
String[] serviceDescPaths = apiStore.getDescriptionDocumentPaths();
for (String serviceDescPath : serviceDescPaths)
{
try
{
// build service description
WebScriptDescription serviceDesc = null;
@@ -315,6 +317,26 @@ public class DeclarativeWebScriptRegistry extends AbstractLifecycleBean
registerPackage(serviceImpl);
registerURIs(serviceImpl);
}
catch(WebScriptException e)
{
if (logger.isWarnEnabled())
{
Throwable c = e;
String cause = c.getMessage();
while (c.getCause() != null && !c.getCause().equals(c))
{
c = c.getCause();
cause += " ; " + c.getMessage();
}
String msg = "Unable to register script " + apiStore.getBasePath() + "/" + serviceDescPath + " due to error: " + cause;
logger.warn(msg);
}
else
{
throw e;
}
}
}
}
}
@@ -385,13 +407,6 @@ public class DeclarativeWebScriptRegistry extends AbstractLifecycleBean
SAXReader reader = new SAXReader();
try
{
Document document = reader.read(serviceDoc);
Element rootElement = document.getRootElement();
if (!rootElement.getName().equals("webscript"))
{
throw new WebScriptException("Expected <webscript> root element - found <" + rootElement.getName() + ">");
}
// retrieve script path
int iPathIdx = serviceDescPath.lastIndexOf('/');
String scriptPath = serviceDescPath.substring(0, iPathIdx == -1 ? 0 : iPathIdx);
@@ -401,11 +416,19 @@ public class DeclarativeWebScriptRegistry extends AbstractLifecycleBean
// retrieve http method
int methodIdx = id.lastIndexOf('.');
if (methodIdx == id.length() - 1)
if (methodIdx == -1 || (methodIdx == id.length() - 1))
{
throw new WebScriptException("Unable to establish HTTP Method from web script description: naming convention must be <name>.<method>.desc.xml");
}
String method = id.substring(id.lastIndexOf('.') + 1).toUpperCase();
String method = id.substring(methodIdx + 1).toUpperCase();
// parse description document
Document document = reader.read(serviceDoc);
Element rootElement = document.getRootElement();
if (!rootElement.getName().equals("webscript"))
{
throw new WebScriptException("Expected <webscript> root element - found <" + rootElement.getName() + ">");
}
// retrieve short name
Element shortNameElement = rootElement.element("shortname");