cancel
Showing results for 
Search instead for 
Did you mean: 

Java-backed: Web Scripts Samples

tegel
Champ in-the-making
Champ in-the-making
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
2 REPLIES 2

jbarmash
Champ in-the-making
Champ in-the-making
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...

tegel
Champ in-the-making
Champ in-the-making
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