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 clocal 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.
// 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());
// 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: