cancel
Showing results for 
Search instead for 
Did you mean: 

Creating Documents Using CreateDocument Web Service

amitgoda
Champ on-the-rise
Champ on-the-rise
Hello Everyone,

I am using Alfresco Community 4.2 version. I am using CreateDocument web service to create different documents in my alfresco share. I am using the web service and passing relevant data for each document.

I have 2 questions about it,

1.) What should be the encoding type for documents, like MS-Word, MS-Excel, JPEG, PNG? I tried creating word document with encoding type as ISO-8859-1 but the document that formed do not have english characters. For e.g for the following content in doc

<strong>This file is created using create document web service</strong>

I am getting the following content in the document that got created in share contains some invalid characters.

So can anyone tell what encoding should I use.I have also tried with UTF-8 and UTF-16, but still facing the same issue.

2.) When I create document with the name which doesnt have spaces like <strong>TestDoc</strong> than the document is created properly, but when I try to create a document with space character in the name like <strong>Test Doc</strong> than Alfresco returns with the following error

<ns1:errorCode>0</ns1:errorCode><ns1:message>org.alfresco.service.cmr.repository.XPathException: 03260166 Error executing xpath: 
   xpath: /app:company_home/st:sites/cm:site-demo/cm:documentLibrary/cm:Test Doc</ns1:message></ns1:RepositoryFault><ns2:exceptionName xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns2="http://xml.apache.org/axis/">org.alfresco.repo.webservice.repository.RepositoryFault</ns2:exceptionName><ns3:stackTrace xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns3="http://xml.apache.org/axis/">
   at org.alfresco.repo.webservice.repository.RepositoryWebService.update(RepositoryWebService.java:335)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
   at java.lang.reflect.Method.invoke(Method.java:601)
   at org.apache.axis.providers.java.RPCProvider.invokeMethod(RPCProvider.java:397)
   at org.apache.axis.providers.java.RPCProvider.processMessage(RPCProvider.java:186)
   at org.apache.axis.providers.java.JavaProvider.invoke(JavaProvider.java:323)
   at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32)
   at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)
   at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)
   at org.apache.axis.handlers.soap.SOAPService.invoke(SOAPService.java:454)
   at org.apache.axis.server.AxisServer.invoke(AxisServer.java:281)
   at org.apache.axis.transport.http.AxisServlet.doPost(AxisServlet.java:699)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
   at org.apache.axis.transport.http.AxisServletBase.service(AxisServletBase.java:327)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
   at org.alfresco.web.app.servlet.GlobalLocalizationFilter.doFilter(GlobalLocalizationFilter.java:61)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
   at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
   at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
   at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002)
   at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
   at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:1813)
   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
   at java.lang.Thread.run(Thread.java:722)


Can anyone explain why I am unable to create document with name which has space characters ?

Thanks in advance!!!
3 REPLIES 3

amitgoda
Champ on-the-rise
Champ on-the-rise
No Reply !!!

Please do let me know if I have posted in wrong section. I do not know what is wrong with the request I am sending. I have checked the alf_encoding table and I am sending the same encoding type as mentioned in the table for corresponding mime_type.

Below is my soap request


<SOAP:Envelope xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/">
  <SOAP:Body>
    <CreateDocument xmlns="http://schemas.cmis.com/cmis/core/1.0">
      <Session>
        <UserName>Admin</UserName>
        <Password>root</Password>
        <Ticket></Ticket>
      </Session>
      <DocumentDetails>
        <Path-UUID type="Path">/app:company_home/st:sites/cm:site-demo/cm:documentLibrary</Path-UUID>
        <FileName>TestDoc</FileName>
        <MimeType>text/plain</MimeType>
        <Encoding>utf-8</Encoding>
        <Content>This file is created using create document web service</Content>
      </DocumentDetails>
    </CreateDocument>
  </SOAP:Body>
</SOAP:Envelope>

amitgoda
Champ on-the-rise
Champ on-the-rise
Ok, So I got the solution for my second problem, hope it helps others.

Using web service you can create a file with name having space characters in alfresco, but when you try to modify that file and that file name contains space characters than alfresco comes with exception <strong>Error executing XPath</strong>

For e.g
If your xpath contains file name with space characters as follows,
<strong>/app:company_home/st:sites/cm:site-demo/cm:documentLibrary/cm:Test Doc</strong>

than alfresco comes with the exception.

So to avoid that, we need to encode the file name and append it to the path like below

<strong>/app:company_home/st:sites/cm:site-demo/cm:documentLibrary/cmSmiley Surprisedrg.alfresco.webservice.util.ISO9075.encode(string(FileName))<strong>

I was helped by the following link

<a>http://forums.alfresco.com/forum/developer-discussions/other-apis/problems-folder-path-08012008-2053</a> .


My 1st question is still not solved.

Any help will be highly appreciated !

amitgoda
Champ on-the-rise
Champ on-the-rise
Ok So finally I got the solution for my 1st question.

If you want to write some content inside the document created, we need to pass the appropriate mime-type and encoding as base64.

The content which we want in the document has to be encoded as base64 and pass the encoded content to the alfresco.

So the base64 encoded content is converted into appropriate format to display the actual content we want to be in our document.

A quick example below


<SOAP:Envelope xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/">
  <SOAP:Body>
    <CreateDocument xmlns="http://schemas.cmis.com/cmis/core/1.0">
      <Session>
        <UserName>Admin</UserName>
        <Password>root</Password>
        <Ticket></Ticket>
      </Session>
      <DocumentDetails>
        <Path-UUID type="Path">/app:company_home/st:sites/cm:site-demo/cm:documentLibrary</Path-UUID>
        <FileName>TestDoc</FileName>
        <MimeType>text/plain</MimeType>
        <Encoding>base64</Encoding>
        <Content>(base64 encoded content)</Content>
      </DocumentDetails>
    </CreateDocument>
  </SOAP:Body>
</SOAP:Envelope>