Java-backed: Web Scripts Samples

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2008 10:47 AM
Hello,
I am trying to build a java web script based on the information of the doc located at http://wiki.alfresco.com/wiki/Java-back … ts_Samples.
For the First example it return some error because the value of the property "Default Format" is "Determined at run-time". Where is the problem ?
I am using alfresco 2.9
Thanks in advance,
Tegel
I am trying to build a java web script based on the information of the doc located at http://wiki.alfresco.com/wiki/Java-back … ts_Samples.
For the First example it return some error because the value of the property "Default Format" is "Determined at run-time". Where is the problem ?
I am using alfresco 2.9
Thanks in advance,
Tegel
Labels:
- Labels:
-
Archive
2 REPLIES 2

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2008 02:24 AM
I wonder if it's referring to you having to set the format to some kind of default. in web script descriptor, set the default so something valid, i.e. html, xml, etc.
<format default="html">argument</format>
Also, there are several samples of java-backed web scripts here:
http://community.alfresco.com/alfresco/n/browse/workspace/SpacesStore/e354c653-1acb-11dd-9ff0-952206...
<format default="html">argument</format>
Also, there are several samples of java-backed web scripts here:
http://community.alfresco.com/alfresco/n/browse/workspace/SpacesStore/e354c653-1acb-11dd-9ff0-952206...

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2008 06:00 AM
thanks, the first and second examples works fine.
For now my workaround is to hard code authentication into the source code of the second example (RandomSelectWebScript.java).
the modifs are:
private TransactionService transactionService;
private Logger logger = Logger.getLogger(RandomSelectWebScript.class);
public void execute(WebScriptRequest req, WebScriptResponse res)
throws IOException
{
boolean switchUser = false;
String currentUser = AuthenticationUtil.getCurrentUserName();
if (!currentUser.equals("admin")) {
//logger.debug("Current user is not admin so switching to admin");
AuthenticationUtil.setCurrentUser("admin");
switchUser = true;
}
UserTransaction txn = transactionService.getUserTransaction();
try {
txn.begin();
// get the referenced incoming node
NodeRef rootNodeRef = getNodeRef(req);
// draw a random child
NodeRef childNodeRef = randomChild(rootNodeRef);
// stream child back
output(res, childNodeRef);
} catch(Throwable e) {
try {
if (txn.getStatus() == Status.STATUS_ACTIVE) txn.rollback();
} catch (Throwable ee) {
e.printStackTrace();
}
}
if (switchUser) AuthenticationUtil.setCurrentUser(currentUser);
}
I changed also the description of the WS to :
<webscript>
<shortname>Streams a random content item</shortname>
<description>Streams a random content item</description>
<url>/demo/random?path={path}</url>
<authentication>guest</authentication>
<transaction>none</transaction>
<format default="">argument</format>
</webscript>
But it doesn't work ?!
Thanks in advance,
Tegel
For now my workaround is to hard code authentication into the source code of the second example (RandomSelectWebScript.java).
the modifs are:
private TransactionService transactionService;
private Logger logger = Logger.getLogger(RandomSelectWebScript.class);
public void execute(WebScriptRequest req, WebScriptResponse res)
throws IOException
{
boolean switchUser = false;
String currentUser = AuthenticationUtil.getCurrentUserName();
if (!currentUser.equals("admin")) {
//logger.debug("Current user is not admin so switching to admin");
AuthenticationUtil.setCurrentUser("admin");
switchUser = true;
}
UserTransaction txn = transactionService.getUserTransaction();
try {
txn.begin();
// get the referenced incoming node
NodeRef rootNodeRef = getNodeRef(req);
// draw a random child
NodeRef childNodeRef = randomChild(rootNodeRef);
// stream child back
output(res, childNodeRef);
} catch(Throwable e) {
try {
if (txn.getStatus() == Status.STATUS_ACTIVE) txn.rollback();
} catch (Throwable ee) {
e.printStackTrace();
}
}
if (switchUser) AuthenticationUtil.setCurrentUser(currentUser);
}
I changed also the description of the WS to :
<webscript>
<shortname>Streams a random content item</shortname>
<description>Streams a random content item</description>
<url>/demo/random?path={path}</url>
<authentication>guest</authentication>
<transaction>none</transaction>
<format default="">argument</format>
</webscript>
But it doesn't work ?!
Thanks in advance,
Tegel
