AnsweredAssumed Answered

webscript uploading exception

Question asked by mialfresco on Jun 30, 2009
Latest reply on Jul 2, 2009 by mialfresco
Hi i'm trying to upload a file using simple webscripts followed @  http://wiki.alfresco.com/wiki/Web_Scripts_Examples#Folder_Browse.2FRSS_Feed

every thing working fine. Now i want to integrate this script with a sample application.
Here my functionality is, there is  a link for uploading a file. when the user clicks on this it will display a popup box with browse,title,description options. And after clicking on this i'm getting the following exception.
404 Description:    Requested resource is not available.

Message:   Script url /simpleui/document/$action="/alfresco/service/simpleui/document/upload does not map to a Web Script.
   
Exception:   org.alfresco.web.scripts.WebScriptException - Script url /simpleui/document/$action="/alfresco/service/simpleui/document/upload does not map to a Web Script.
   
   org.alfresco.web.scripts.AbstractRuntime.executeScript(AbstractRuntime.java:106)
   org.alfresco.web.scripts.servlet.WebScriptServlet.service(WebScriptServlet.java:116)
   javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
   org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
   org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
   org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
   org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
   org.apache.catalina.core.


here my code is, DocumentList.get.html.ftl



var dlg,previewdlg,removedlg,sdlg,udlg;
      function init(e) {
         dlg        = dojo.widget.byId("DialogContent");
         previewdlg = dojo.widget.byId("DialogPreview");
         removedlg  = dojo.widget.byId("DialogRemove");
         sdlg        = dojo.widget.byId("SpaceDialog");
         udlg        = dojo.widget.byId("UploadDialog");


      }



      function uploadFile() {
         document.getElementById("upload_label").innerHTML='Upload a File';
         document.forms['upload_new'].action = '$action="${url.serviceContext}/simpleui/document/upload';
         udlg.show();
      }



Upload a file
   <img src="${url.context}/images/icons/add.gif" onClick="uploadFile();"/></b>
   </tr>

<div dojoType="dialog" id="UploadDialog" bgColor="gray" bgOpacity="0.5" toggle="fade" toggleDuration="250" closeOnBackgroundClick="true">
<form name="upload_new" action="" method="post">

   <table>
   <tbody>
      <tr>
         <th colspan="2"><b><div id="upload_label"></div></b></th>
      </tr>
          <tr><td>File:<td><input type="file" name="file">
          <tr><td>Title:<td><input name="title">
          <tr><td>Description:<td><input name="desc">
          <tr><td><td>
          <tr>
         <td colspan="2" align="center">
            
            <input type="submit" name="submit" value="Upload">
            <input type="button" id="hider2" value="Cancel" onClick="udlg.hide()"></td>
         </tr>


   </tbody>
   </table>
</form>


and my upload.post.desc.xml is
<webscript>
  <shortname>File Upload Form Sample</shortname>
  <description>Form for uploading file content and meta-data into Repository</description>
  <url>/simpleui/document/upload</url>
  <authentication>user</authentication>
</webscript>

and my  upload.post.js   is

var filename = null;
var content = null;
var title = "";
var description = "";

// locate file attributes
for each (field in formdata.fields)
{
  if (field.name == "title")
  {
    title = field.value;
  }
  else if (field.name == "desc")
  {
    description = field.value;
  }
  else if (field.name == "file" && field.isFile)
  {
    filename = field.filename;
    content = field.content;
  }
}

// ensure mandatory file attributes have been located
if (filename == undefined || content == undefined)
{
  status.code = 400;
  status.message = "Uploaded file cannot be located in request";
  status.redirect = true;
}
else
{
  // create document in company home for uploaded file
  upload = companyhome.createFile("upload" + companyhome.children.length + "_" + filename) ;
  upload.properties.content.write(content);
  upload.properties.encoding = "UTF-8";
  upload.properties.title = title;
  upload.properties.description = description;
  upload.save();

  // setup model for response template
  model.upload = upload;
}

and my upload.post.html.ftl is
<META 
     HTTP-EQUIV="Refresh"
     CONTENT="1; URL=${url.serviceContext}/simpleui/document/list.html">

<html>
<head>
   <title>Upload Web Script Sample</title>
   <link rel="stylesheet" href="${url.context}/css/main.css" TYPE="text/css">
</head>
<body>
   <table>
    
     <tr><td><td>Alfresco ${server.edition} v${server.version}
     <tr><td><td>
     <tr><td><td>Uploaded <a href="${url.serviceContext}/sample/folder${upload.displayPath}">${upload.name}</a> of size ${upload.properties.content.size}.
     <tr>
       <td><a href="${url.serviceContext}/simpleui/document/list.html">Back to list page</a>
     </tr>

   </table>
</body>
</html>

the complete DocumentList.get.html.ftl is  (this is a home page,,, here only i'm having various links for creating folder,uploading document, creating a text file etc)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
   <title>Alfresco Simple UI</title>
   <script type="text/javascript">
      var djConfig = {
         isDebug: true
         ,debugAtAllCosts: true
      };
   </script>
   <script type="text/javascript" src="${url.context}/scripts/ajax/dojo/dojo.js"></script>
   <script type="text/javascript">
      dojo.require("dojo.widget.FilteringTable");
      dojo.require("dojo.widget.InlineEditBox");
      dojo.require("dojo.widget.Dialog");
      dojo.require("dojo.event.*");
      dojo.hostenv.writeIncludes();
      
      var dlg,previewdlg,removedlg,sdlg,udlg;
      function init(e) {
         dlg        = dojo.widget.byId("DialogContent");
         previewdlg = dojo.widget.byId("DialogPreview");
         removedlg  = dojo.widget.byId("DialogRemove");
         sdlg        = dojo.widget.byId("SpaceDialog");
         udlg        = dojo.widget.byId("UploadDialog");


      }
      dojo.addOnLoad(init);
      
      function populate(id,noderef) {
         document.getElementById("file_label").innerHTML='Edit File';
         document.forms['edit_new_form'].action = '${url.serviceContext}/simpleui/document/save';
         document.getElementById("file_name").value=document.getElementById("name_"+id).innerHTML;
         document.getElementById("file_description").value=document.getElementById("desc_"+id).innerHTML;
         document.getElementById("file_body").value=document.getElementById("body_"+id).innerHTML;
         document.getElementById("file_noderef").value=noderef;
         dlg.show();
      }

      function populatepreview(id) {
         document.getElementById("preview_name").innerHTML=document.getElementById("name_"+id).innerHTML;
         document.getElementById("preview_body").innerHTML=document.getElementById("body_"+id).innerHTML;
         previewdlg.show();
      }
      
      function populateremove(id,noderef) {
         document.getElementById("remove_name").value=document.getElementById("name_"+id).innerHTML;
         document.getElementById("remove_noderef").value=noderef;
         removedlg.show();
      }

      function create() {
         document.getElementById("file_label").innerHTML='Create File';
         document.forms['edit_new_form'].action = '${url.serviceContext}/simpleui/document/create';
         dlg.show();
      }


      function createSpace() {
         document.getElementById("space_label").innerHTML='Create Space';
         document.forms['space_new'].action = '${url.serviceContext}/simpleui/document/createSpace';
         sdlg.show();
      }


      function uploadFile() {
         document.getElementById("upload_label").innerHTML='Upload a File';
         document.forms['upload_new'].action = '$action="${url.serviceContext}/simpleui/document/upload';
         udlg.show();
      }




   </script>
   <style type="text/css">
      /***
         The following is just an example of how to use the table.
         You can override any class names to be used if you wish.
      ***/
      table {
         font-family:Lucida Grande, Verdana;
         font-size:0.8em;
         width:100%;
         border:1px solid #ccc;
         border-collapse:collapse;
         cursor:default;
      }
      table td,
      table th{
         padding:2px;
         font-weight:normal;
      }
      table thead td, table thead th {
         background-image:url(${url.context}/images/dojo/ft-head.gif);
         background-repeat:no-repeat;
         background-position:top right;
      }
      table thead td.selectedUp, table thead th.selectedUp {
         background-image:url(${url.context}/images/dojo/ft-headup.gif);
      }
      table thead td.selectedDown, table thead th.selectedDown {
         background-image:url(${url.context}/images/dojo/ft-headdown.gif);
      }
         
      table tbody tr td{
         border-bottom:1px solid #ddd;
      }
      table tbody tr.alt td{
         background: #e3edfa;
      }
      table tbody tr.selected td{
         background: yellow;
      }
      table tbody tr:hover td{
         background: #a6c2e7;
      }
      table tbody tr.selected:hover td{
         background:#ff9;
      }

      #inputArea{
         margin:1em 0;
         padding:1em;
         background-color:#eef;
      }
      #updateTestInput{
         border:1px solid #ccc;
         width:100%;
         height:80px;
         font-family:serif;
         font-size:0.9em;
         overflow:auto;
      }
      
      .bar a img {
         border:0;
         vertical-align: middle;
      }
      
      .dojoDialog {
         background : #eee;
         border : 1px solid #999;
         -moz-border-radius : 5px;
         padding : 4px;
         width: 80%
      }
      

      .footer {
         text-align: center;
         position:absolute;
         font-family:Lucida Grande, Verdana;
         font-size:0.8em;
         bottom:10px;
         left: 35%
      }

   </style>

</head>
<body>
   <div dojoType="dialog" id="DialogPreview" bgColor="gray" bgOpacity="0.5" toggle="fade" toggleDuration="250" closeOnBackgroundClick="true">
      <table>
         <tbody>
            <tr>
               <th><b>Previw File </b><div id="preview_name"></div></th>
            </tr>
            <tr>
               <td><div id="preview_body"></div></td>               
            </tr>
            <tr>
               <td align="center"><input type="button" id="hide3" value="Close" onClick="previewdlg.hide()"></td></td>               
            </tr>
         </tbody>
      </table>   
   </div>
   <div dojoType="dialog" id="DialogRemove" bgColor="gray" bgOpacity="0.5" toggle="fade" toggleDuration="250" closeOnBackgroundClick="true">
   <form name="remove_form" action="${url.serviceContext}/simpleui/document/remove" method="post">   
      <table>
         <tbody>
            <tr>
               <th><b>Remove File </b><INPUT type="text" id="remove_name" name="name" value="" disabled/></th>
            </tr>
            <tr>
               <td>Do you really really really want to delete this file?</td>               
            </tr>
            <tr>
               <td align="center">
               <INPUT type="hidden" id="remove_noderef" name="noderef" value=""/>
               <INPUT type="hidden" id="remove_name" name="name" value=""/>
               <input type="submit" value="Ok"/>
               <input type="button" id="hide3" value="Cancel" onClick="removedlg.hide()"></td></td>               
            </tr>
         </tbody>
      </table>
   </form>   
   </div>
   <div dojoType="dialog" id="DialogContent" bgColor="gray" bgOpacity="0.5" toggle="fade" toggleDuration="250" closeOnBackgroundClick="true">
   <form name="edit_new_form" action="" method="post">
      <table>
         <tbody>
            <tr>
               <th colspan="2"><b><div id="file_label"></div></b></th>
            </tr>
            <tr>
               <td>Name</td>
               <td><input id="file_name" name="name" type="text"></td>
            </tr>
            <tr>
               <td>Description</td>
               <td><input id="file_description" name="desc" type="text" size="60"></td>
            </tr>
            <tr>
               <td valign="top">Body</td>
               <td><textarea id="file_body" name="body" rows="10" cols="60"></textarea></td>
            </tr>
            <tr>
               <td colspan="2" align="center">
                  <INPUT type="hidden" id="file_noderef" name="noderef" value=""/>
                  <INPUT type="submit" value="Save">
                  <input type="button" id="hider2" value="Cancel" onClick="dlg.hide()"></td>
            </tr>
         </tbody>
      </table>
   </form>
   </div>









<div dojoType="dialog" id="SpaceDialog" bgColor="gray" bgOpacity="0.5" toggle="fade" toggleDuration="250" closeOnBackgroundClick="true">
   <form name="space_new" action="" method="post">
      <table>
         <tbody>
            <tr>
               <th colspan="2"><b><div id="space_label"></div></b></th>
            </tr>
            <tr>
               <td>Name</td>
               <td><input id="space_name" name="sn" type="text"></td>
            </tr>

            <tr>
               <td>Title</td>
               <td><input id="space_title" name="st" type="text"></td>
            </tr>

            <tr>
               <td>Description</td>
               <td><input id="space_description" name="sd" type="text" size="60"></td>
            </tr>
            
            <tr>
               <td colspan="2" align="center">
                  <INPUT type="hidden" id="file_noderef" name="noderef" value=""/>
                  <INPUT type="submit" value="Create">
                  <input type="button" id="hider2" value="Cancel" onClick="sdlg.hide()"></td>
            </tr>
         </tbody>
      </table>
   </form>
   </div>




<div dojoType="dialog" id="UploadDialog" bgColor="gray" bgOpacity="0.5" toggle="fade" toggleDuration="250" closeOnBackgroundClick="true">
<form name="upload_new" action="" method="post">

   <table>
   <tbody>
      <tr>
         <th colspan="2"><b><div id="upload_label"></div></b></th>
      </tr>
          <tr><td>File:<td><input type="file" name="file">
          <tr><td>Title:<td><input name="title">
          <tr><td>Description:<td><input name="desc">
          <tr><td><td>
          <tr>
         <td colspan="2" align="center">
            
            <input type="submit" name="submit" value="Upload">
            <input type="button" id="hider2" value="Cancel" onClick="udlg.hide()"></td>
         </tr>


   </tbody>
   </table>
</form>

</div>















   <h3>Simple Alfresco User Interface</h3>
   <h4>Hello ${person.properties.firstName}!</h4>
   <tr>   <b>Create a File
   <img src="${url.context}/images/icons/add.gif" onClick="create();"/>
   Create a Space
   <img src="${url.context}/images/icons/folder.gif" onClick="createSpace();"/></b>

   Upload a file
   <img src="${url.context}/images/icons/add.gif" onClick="uploadFile();"/></b>
   </tr>




   <table dojoType="filteringTable" id="documentList" alternateRows="true" maxSortable="2"

         cellpadding="0" cellspacing="0" border="0">
         
   <thead>

      <tr>
         <th field="Name" dataType="String" sort="asc" valign="top">Name</th>
         <th field="DateAdded" dataType="DateTime" align="center" valign="top">Created</th>
         <th field="DateModified" dataType="DateTime" align="center" valign="top">Modified</th>
         <th dataType="html">Description</th>
         <!–
         <th dataType="html">Body</th>
         –>
         <th dataType="html">Actions</th>
      </tr>
   </thead>

   <tbody>
     <#list resultset as node>
     <tr value="${node_index + 1}">
       <td><div id="name_${node_index + 1}">${node.name}</div></td>
       <td>${node.properties.created?datetime}</td>
       <td>${node.properties.modified?datetime}</td>
       <td><div id="desc_${node_index + 1}">${node.properties.description}</div></td>
     <!–
       <td><div id="body_${node_index + 1}">${node.content}</div></td>
     –> 
       <td>
          <div class="bar">
             <a href="#" onClick="populatepreview('${node_index + 1}')"><img src="${url.context}/images/icons/preview.gif"/></a>
             <a href="#" onClick="populate('${node_index + 1}','${node.nodeRef}')"><img src="${url.context}/images/icons/edit_icon.gif"/></a>
             <a href="${url.serviceContext}/api/node/content/${node.nodeRef.storeRef.protocol}/${node.nodeRef.storeRef.identifier}/${node.nodeRef.id}/${node.name?url}"><img src="${url.context}/images/icons/CheckOut_icon.gif"/></a>
             <a href="#" onClick="populateremove('${node_index + 1}','${node.nodeRef}')"><img src="${url.context}/images/icons/delete.gif"/></a>      
          </div>
       </td>
     </tr> 
     </#list>
   </tbody>
   </table>


   <div class="footer">
            Alfresco. &copy; 2009-2010 All rights reserved.
   </div>
</body>
</html>


Please give any ideas on this….

Outcomes