cancel
Showing results for 
Search instead for 
Did you mean: 

upload remote webscript file into Web Scripts Ext [solved]

efycaci_ramesh
Champ in-the-making
Champ in-the-making
Hi to all,

my task is :
File that are required for webscript are in local\ remote system eg 1)hello.get.desc.xml and hello.get.html.ftl two files are in cSmiley Sadlocal files). My task is to upload these file into  the following directory in alfresco
"Company Home > Data Dictionary > Web Scripts Extensions " as like a webscript but upload through stand alone java class or using webservices.

2) Invoke that webservice from stand alone java class \ webservices.

So pls provide some sample or any code related to my task which ill be more helpful to me.


thanks in advance.
2 REPLIES 2

openpj
Elite Collaborator
Elite Collaborator
You can find an example of an upload File webscripts in the following page of the Alfresco Wiki:
http://wiki.alfresco.com/wiki/Web_Scripts_Examples#File_Upload
Hope this helps.

efycaci_ramesh
Champ in-the-making
Champ in-the-making
Solution for my task:

private void uploadWebScript(String fileName, String contentType) {
      try {
         // Start the session
         AuthenticationUtils.startSession("admin", "password");

         // Create a reference to the parent where we want to create content
         Store storeRef = new Store(Constants.WORKSPACE_STORE, "SpacesStore");
         
         // ParentReference companyHomeParent = new ParentReference(storeRef,
         // null,
         // "/app:company_home/app:dictionary/cm:extensionwebscripts/cm:WebScriptRegistration",
         // Constants.ASSOC_CONTAINS, null);
         ParentReference companyHomeParent = new ParentReference(storeRef,
               null,
               "/app:company_home/app:dictionary/cm:extensionwebscripts",
               Constants.ASSOC_CONTAINS, null);
         System.out.println("childname:"
               + companyHomeParent.getAssociationType());
         System.out.println("path:" + companyHomeParent.getPath());
         // Assign name

         companyHomeParent.setChildName("cm:" + fileName);
         System.out.println("Cm name:" + fileName);
         // Construct CML statement to create content node
         // Note: Assign "1" as a local id, so we can refer to it in
         // subsequent
         // CML statements within the same CML block
         NamedValue[] contentProps = new NamedValue[1];
         contentProps[0] = Utils.createNamedValue(Constants.PROP_NAME,
               fileName);
         CMLCreate create = new CMLCreate("1", companyHomeParent, null,
               null, null, Constants.TYPE_CONTENT, contentProps);
         System.out.println("companyHomeParent"
               + companyHomeParent.toString());

         // Construct CML statement to add titled aspect
         NamedValue[] titledProps = new NamedValue[2];
         titledProps[0] = Utils.createNamedValue(Constants.PROP_TITLE,
               fileName);
         titledProps[1] = Utils.createNamedValue(Constants.PROP_DESCRIPTION,
               fileName);
         CMLAddAspect addAspect = new CMLAddAspect(Constants.ASPECT_TITLED,
               titledProps, null, "1");
         System.out.println("addAspect:" + addAspect);

         // Construct CML Block
         CML cml = new CML();
         cml.setCreate(new CMLCreate[] { create });
         cml.setAddAspect(new CMLAddAspect[] { addAspect });
         System.out.println("cml.setCreate:" + cml.getCreate());

         // Issue CML statement via Repository Web Service and retrieve
         // result
         // Note: Batching of multiple statements into a single web call
         UpdateResult[] result = WebServiceFactory.getRepositoryService()
               .update(cml);
         System.out.println("result" + result);
         Reference content = result[0].getDestination();
         System.out.println("content" + content);

         // Write the content
         ContentServiceSoapBindingStub contentService = WebServiceFactory
               .getContentService();
         FileInputStream is = new FileInputStream("E:/Upload/" + fileName);
         byte[] bytes = ContentUtils.convertToByteArray(is);
         ContentFormat format = new ContentFormat(contentType, "UTF-8");
         Content contentRef = contentService.write(content,
               Constants.PROP_CONTENT, bytes, format);
         System.out.println("Content Length: " + contentRef.getLength());
      } catch (Exception e) {
         System.out.println(e.toString());
      } finally {
         // End the session
         AuthenticationUtils.endSession();

      }
   }



To refresh the webscript thru java program using curl command.
Coding for refresh the webscript:

private void refreshServices() {
      String curlCommand = "curl installed location -u adminSmiley Tongueassword ";
      String values = "-d \"reset=on&submit=Refresh Web Scripts\"";
      String url = " http://localhost:8080/alfresco/service/index –silent" ;
      String executeCmd = curlCommand + values + url;
      Process pr;
      System.out.println("cmd:" + executeCmd);

               pr = Runtime.getRuntime().exec(executeCmd);

//handle the exception and get the result.
}