Web Scripts:

- addition of extension paths for web script customisations
- updated "delete ticket" web script to return appropriate response on success

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@5867 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
David Caruana
2007-06-06 11:57:42 +00:00
parent c89bce7bda
commit 3d86571cda
9 changed files with 127 additions and 62 deletions

View File

@@ -1,2 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ticket>${ticket}</ticket>

View File

@@ -1,6 +1,6 @@
<webscript> <webscript>
<shortname>Login Ticket</shortname> <shortname>Get Login Ticket</shortname>
<description>Login Ticket</description> <description>Get Login Ticket</description>
<url format="xml" template="/login/ticket/{ticket}"/> <url format="xml" template="/login/ticket/{ticket}"/>
<authentication>user</authentication> <authentication>user</authentication>
<transaction>required</transaction> <transaction>required</transaction>

View File

@@ -2,9 +2,49 @@
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'> <!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>
<beans> <beans>
<!-- -->
<!-- Web Script Storage -->
<!-- -->
<bean id="webscripts.repostore" class="org.alfresco.web.scripts.RepoStore" abstract="true">
<property name="transactionHelper" ref="retryingTransactionHelper" />
<property name="nodeService" ref="nodeService" />
<property name="namespaceService" ref="namespaceService" />
<property name="contentService" ref="contentService" />
<property name="searchService" ref="SearchService" />
</bean>
<bean id="webscripts.classpathstore" class="org.alfresco.web.scripts.ClassPathStore" abstract="true" />
<bean parent="webscripts.repostore">
<property name="store"><value>workspace://SpacesStore</value></property>
<property name="path"><value>/${spaces.company_home.childname}/${spaces.dictionary.childname}/cm:extensionwebscripts</value></property>
</bean>
<bean parent="webscripts.repostore">
<property name="mustExist"><value>true</value></property>
<property name="store"><value>workspace://SpacesStore</value></property>
<property name="path"><value>/${spaces.company_home.childname}/${spaces.dictionary.childname}/cm:webscripts</value></property>
</bean>
<bean parent="webscripts.classpathstore">
<property name="classPath"><value>alfresco/extension/templates/webscripts</value></property>
</bean>
<bean parent="webscripts.classpathstore">
<property name="mustExist"><value>true</value></property>
<property name="classPath"><value>alfresco/templates/webscripts</value></property>
</bean>
<bean id="webscripts.storage" class="org.alfresco.web.scripts.WebScriptStorage">
<property name="templateProcessor" ref="webscripts.templateprocessor" />
<property name="scriptProcessor" ref="webscripts.scriptprocessor" />
</bean>
<!-- --> <!-- -->
<!-- Web Script Resource Bundles --> <!-- Web Script Context -->
<!-- --> <!-- -->
<bean id="webscripts.resources" class="org.alfresco.i18n.ResourceBundleBootstrapComponent"> <bean id="webscripts.resources" class="org.alfresco.i18n.ResourceBundleBootstrapComponent">
@@ -15,11 +55,6 @@
</property> </property>
</bean> </bean>
<!-- -->
<!-- API Definition & Implementation Storage -->
<!-- -->
<bean id="webscripts.context" class="org.alfresco.web.scripts.WebScriptContext"> <bean id="webscripts.context" class="org.alfresco.web.scripts.WebScriptContext">
<property name="transactionService" ref="transactionComponent" /> <property name="transactionService" ref="transactionComponent" />
<property name="namespaceService" ref="namespaceService" /> <property name="namespaceService" ref="namespaceService" />
@@ -30,14 +65,9 @@
<property name="companyHomePath"><value>/${spaces.company_home.childname}</value></property> <property name="companyHomePath"><value>/${spaces.company_home.childname}</value></property>
</bean> </bean>
<bean id="webscripts.storage" class="org.alfresco.web.scripts.WebScriptStorage">
<property name="templateProcessor" ref="webscripts.templateprocessor" />
<property name="scriptProcessor" ref="webscripts.scriptprocessor" />
</bean>
<bean id="webscripts.templateprocessor" class="org.alfresco.web.scripts.TemplateProcessor"> <bean id="webscripts.templateprocessor" class="org.alfresco.web.scripts.TemplateProcessor">
<property name="freeMarkerProcessor" ref="freeMarkerProcessor" /> <property name="freeMarkerProcessor" ref="freeMarkerProcessor" />
<property name="serviceRegistry" ref="ServiceRegistry" /> <property name="serviceRegistry" ref="ServiceRegistry" />
<!-- <property name="defaultEncoding"><value>UTF-8</value></property> --> <!-- <property name="defaultEncoding"><value>UTF-8</value></property> -->
</bean> </bean>
@@ -45,33 +75,9 @@
<property name="scriptService" ref="ScriptService" /> <property name="scriptService" ref="ScriptService" />
</bean> </bean>
<bean id="webscripts.repostore" class="org.alfresco.web.scripts.RepoStore" abstract="true">
<property name="transactionHelper" ref="retryingTransactionHelper" />
<property name="nodeService" ref="nodeService" />
<property name="namespaceService" ref="namespaceService" />
<property name="contentService" ref="contentService" />
<property name="searchService" ref="SearchService" />
</bean>
<bean id="webscripts.classpathstore" class="org.alfresco.web.scripts.ClassPathStore" abstract="true" />
<!-- -->
<!-- Web Script Search Paths -->
<!-- -->
<bean parent="webscripts.repostore">
<property name="store"><value>workspace://SpacesStore</value></property>
<property name="path"><value>/${spaces.company_home.childname}/${spaces.dictionary.childname}/cm:webscripts</value></property>
</bean>
<bean parent="webscripts.classpathstore">
<property name="classPath"><value>alfresco/templates/webscripts</value></property>
</bean>
<!-- --> <!-- -->
<!-- API Service Registry --> <!-- Web Script Registry -->
<!-- --> <!-- -->
<bean id="webscripts.registry" class="org.alfresco.web.scripts.DeclarativeWebScriptRegistry"> <bean id="webscripts.registry" class="org.alfresco.web.scripts.DeclarativeWebScriptRegistry">
@@ -93,11 +99,10 @@
<property name="scriptContext" ref="webscripts.context" /> <property name="scriptContext" ref="webscripts.context" />
<property name="authenticationService" ref="AuthenticationService" /> <property name="authenticationService" ref="AuthenticationService" />
</bean> </bean>
<!-- --> <!-- -->
<!-- API Response Formats --> <!-- Response Formats -->
<!-- --> <!-- -->
<!-- Format Registry --> <!-- Format Registry -->
@@ -138,7 +143,7 @@
<!-- --> <!-- -->
<!-- API Configuration --> <!-- Web Script Configuration -->
<!-- --> <!-- -->
<bean id="webscripts.configsource" class="org.alfresco.config.source.UrlConfigSource"> <bean id="webscripts.configsource" class="org.alfresco.config.source.UrlConfigSource">
@@ -159,7 +164,7 @@
<!-- --> <!-- -->
<!-- Base implementations of a Web API Backing Bean --> <!-- Base implementations of a Web Script Backing Bean -->
<!-- --> <!-- -->
<!-- Abstract API Service --> <!-- Abstract API Service -->
@@ -174,7 +179,7 @@
<!-- --> <!-- -->
<!-- Custom Java Web API Backing Beans --> <!-- Custom Java Web Script Backing Beans -->
<!-- --> <!-- -->
<!-- List of available Web APIs --> <!-- List of available Web APIs -->

View File

@@ -53,10 +53,24 @@ import freemarker.cache.TemplateLoader;
public class ClassPathStore implements WebScriptStore, InitializingBean public class ClassPathStore implements WebScriptStore, InitializingBean
{ {
PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
protected boolean mustExist = false;
protected String classPath; protected String classPath;
protected File fileDir; protected File fileDir;
/**
* Sets whether the class path must exist
*
* If it must exist, but it doesn't exist, an exception is thrown
* on initialisation of the store
*
* @param mustExist
*/
public void setMustExist(boolean mustExist)
{
this.mustExist = mustExist;
}
/** /**
* Sets the class path * Sets the class path
* *
@@ -74,7 +88,22 @@ public class ClassPathStore implements WebScriptStore, InitializingBean
throws Exception throws Exception
{ {
ClassPathResource resource = new ClassPathResource(classPath); ClassPathResource resource = new ClassPathResource(classPath);
fileDir = resource.getFile(); if (resource.exists())
{
fileDir = resource.getFile();
}
else if (mustExist)
{
throw new WebScriptException("Web Script Store classpath:" + classPath + " must exist; it was not found");
}
}
/* (non-Javadoc)
* @see org.alfresco.web.scripts.WebScriptStore#exists()
*/
public boolean exists()
{
return (fileDir != null);
} }
/* (non-Javadoc) /* (non-Javadoc)

View File

@@ -63,6 +63,7 @@ import freemarker.cache.TemplateLoader;
public class RepoStore implements WebScriptStore, ApplicationContextAware, ApplicationListener public class RepoStore implements WebScriptStore, ApplicationContextAware, ApplicationListener
{ {
private ProcessorLifecycle lifecycle = new ProcessorLifecycle(); private ProcessorLifecycle lifecycle = new ProcessorLifecycle();
protected boolean mustExist = false;
protected StoreRef repoStore; protected StoreRef repoStore;
protected String repoPath; protected String repoPath;
protected NodeRef baseNodeRef; protected NodeRef baseNodeRef;
@@ -116,6 +117,16 @@ public class RepoStore implements WebScriptStore, ApplicationContextAware, Appli
this.namespaceService = namespaceService; this.namespaceService = namespaceService;
} }
/**
* Sets whether the repo store must exist
*
* @param mustExist
*/
public void setMustExist(boolean mustExist)
{
this.mustExist = mustExist;
}
/** /**
* Sets the repo store * Sets the repo store
*/ */
@@ -182,23 +193,30 @@ public class RepoStore implements WebScriptStore, ApplicationContextAware, Appli
{ {
String query = "PATH:\"" + repoPath + "\""; String query = "PATH:\"" + repoPath + "\"";
ResultSet resultSet = searchService.query(repoStore, SearchService.LANGUAGE_LUCENE, query); ResultSet resultSet = searchService.query(repoStore, SearchService.LANGUAGE_LUCENE, query);
if (resultSet.length() == 0) if (resultSet.length() == 1)
{ {
throw new WebScriptException("Unable to locate repository path " + repoStore.toString() + repoPath); baseNodeRef = resultSet.getNodeRef(0);
baseDir = getPath(baseNodeRef);
} }
if (resultSet.length() > 1) else if (mustExist)
{ {
throw new WebScriptException("Multiple repository paths found for " + repoStore.toString() + repoPath); throw new WebScriptException("Web Script Store " + repoStore.toString() + repoPath + " must exist; it was not found");
} }
baseNodeRef = resultSet.getNodeRef(0);
baseDir = getPath(baseNodeRef);
return null; return null;
} }
}); });
} }
}, AuthenticationUtil.getSystemUserName()); }, AuthenticationUtil.getSystemUserName());
} }
/* (non-Javadoc)
* @see org.alfresco.web.scripts.WebScriptStore#exists()
*/
public boolean exists()
{
return (baseNodeRef != null);
}
/* (non-Javadoc) /* (non-Javadoc)
* @see org.alfresco.web.scripts.WebScriptStore#getBasePath() * @see org.alfresco.web.scripts.WebScriptStore#getBasePath()
*/ */

View File

@@ -217,7 +217,7 @@ public abstract class WebScriptRuntime
templatePath = "/status.ftl"; templatePath = "/status.ftl";
if (!registry.getTemplateProcessor().hasTemplate(templatePath)) if (!registry.getTemplateProcessor().hasTemplate(templatePath))
{ {
throw new WebScriptException("Failed to find status template " + status + " (format: " + WebScriptResponse.HTML_FORMAT + ")"); throw new WebScriptException("Failed to find status template " + templatePath + " (format: " + WebScriptResponse.HTML_FORMAT + ")");
} }
} }

View File

@@ -97,7 +97,16 @@ public class WebScriptStorage implements ApplicationContextAware, ApplicationLis
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public Collection<WebScriptStore> getStores() public Collection<WebScriptStore> getStores()
{ {
return applicationContext.getBeansOfType(WebScriptStore.class, false, false).values(); Collection<WebScriptStore> allstores = applicationContext.getBeansOfType(WebScriptStore.class, false, false).values();
Collection<WebScriptStore> stores = new ArrayList<WebScriptStore>();
for (WebScriptStore store : allstores)
{
if (store.exists())
{
stores.add(store);
}
}
return stores;
} }
/** /**

View File

@@ -37,7 +37,13 @@ import freemarker.cache.TemplateLoader;
*/ */
public interface WebScriptStore public interface WebScriptStore
{ {
/**
* Determines whether the store actually exists
*
* @return true => it does exist
*/
public boolean exists();
/** /**
* Gets the base path of the store * Gets the base path of the store
* *

View File

@@ -83,7 +83,7 @@ public class LoginTicketDelete extends DeclarativeWebScript
// construct model for ticket // construct model for ticket
Map<String, Object> model = new HashMap<String, Object>(7, 1.0f); Map<String, Object> model = new HashMap<String, Object>(7, 1.0f);
model.put("ticket", ticket); model.put("ticket", ticket);
try try
{ {
String ticketUser = ticketComponent.validateTicket(ticket); String ticketUser = ticketComponent.validateTicket(ticket);
@@ -91,7 +91,6 @@ public class LoginTicketDelete extends DeclarativeWebScript
// do not go any further if tickets are different // do not go any further if tickets are different
if (!AuthenticationUtil.getCurrentUserName().equals(ticketUser)) if (!AuthenticationUtil.getCurrentUserName().equals(ticketUser))
{ {
status.setRedirect(true);
status.setCode(HttpServletResponse.SC_NOT_FOUND); status.setCode(HttpServletResponse.SC_NOT_FOUND);
status.setMessage("Ticket not found"); status.setMessage("Ticket not found");
} }
@@ -99,15 +98,16 @@ public class LoginTicketDelete extends DeclarativeWebScript
{ {
// delete the ticket // delete the ticket
authenticationService.invalidateTicket(ticket); authenticationService.invalidateTicket(ticket);
status.setMessage("Deleted Ticket " + ticket);
} }
} }
catch(AuthenticationException e) catch(AuthenticationException e)
{ {
status.setRedirect(true);
status.setCode(HttpServletResponse.SC_NOT_FOUND); status.setCode(HttpServletResponse.SC_NOT_FOUND);
status.setMessage("Ticket not found"); status.setMessage("Ticket not found");
} }
status.setRedirect(true);
return model; return model;
} }