cancel
Showing results for 
Search instead for 
Did you mean: 

Webservie client with Axis1

silvia1983
Champ in-the-making
Champ in-the-making
Hi!

I'm trying to use the method createDocument of webservice ObjectService but i always get the same exception:

(400)Petici�n incorrecta

If instead of local Alfresco, try the public Alfresco on the web ("http://cmis.alfresco.com:80/service/cmis") the answer is 'This method is not allowed'

The way to connect to the service is that I use is:

ObjectServiceLocator servLocator = new ObjectServiceLocator();
Object endpoint = "http://localhost:8080/service/cmis";
Object port = "ObjectServicePort";
servLocator.setEndpointAddress(port.toString(),endpoint.toString());
      
ObjectServicePortBindingStub stub = null;
CreateDocumentResponse response = null;
try{
     stub = (ObjectServicePortBindingStub)servLocator
         .getPort(ObjectServicePortBindingStub.class);
     stub.setUsername("admin");
     stub.setPassword("admin");
     response = stub.createDocument(parameters);

¿Anyone can help me with this problem? Because i'm not able to do anything with Alfresco's services yet and I need it

Thank you
8 REPLIES 8

rameshbelli
Champ in-the-making
Champ in-the-making
Hi Silvia,

First you have to find the repository id by using the getRepositories() method in RepositoryService.

Then you have to call the createFolder method in ObjectService to create a folder using the repository id  to get the objectId of  the folder and then

call the createDocument() method using the repositoryId and the objectId along with other Document related parameters .

Hope this helps,

Ramesh

silvia1983
Champ in-the-making
Champ in-the-making
Thanks for the answer RameshBelli, but there is something that i must be doing wrong because when I call getRepositories service I recieve this answer:

An error was discovered processing the <wsseSmiley Frustratedecurity> header

I'm going to put the instance of GetRepositories and then the call to the service for someone who tell me what i'm doing wrong because in other post i saw a differente way to call the service. It could be the reason? Is the call wrong?

The instance of GetRepositories

GetRepositories parameters = new GetRepositories();
CmisExtensionType extensiones = new CmisExtensionType();
      
parameters.setExtension(extensiones);
try{
alfresco.getRepositories(parameters, null);
}catch(Exception e){
   System.out.println(e);
}

The call to the service:

RepositoryServiceLocator servLocator = new RepositoryServiceLocator();
Object endpoint = "http://localhost:8080/alfresco/cmis/RepositoryService";

servLocator.setRepositoryServicePortEndpointAddress(endpoint.toString());
CmisRepositoryEntryType[] response = null;
RepositoryServiceSoapBindingStub stub = null;
try{
    stub = (RepositoryServiceSoapBindingStub)servLocator
         .getPort(RepositoryServiceSoapBindingStub.class);
    stub.setUsername("admin");
    stub.setPassword("admin");
    response = stub.getRepositories(parameters);
}catch (Exception e){
    System.out.println(e.toString());
}

nikes
Champ on-the-rise
Champ on-the-rise
You need to set username and Timestamp token for security headers.

http://forums.alfresco.com/en/viewtopic.php?f=45&t=26137

There are two ways to talk to ECM system using CMIS, Web Service and RESTFul.

For web service you can use any framework like Axis, Axis2, CXF etc… I am using CXF since it requires less coding.

You can find sample CXF client code here
http://svn.alfresco.com/repos/alfresco-open-mirror/alfresco/HEAD/root/projects/remote-api/source/sam...

Also you can use OpenCMIS pure java API which can be used for both REST and SOAP which hides implementation classes,
so you use same code for REST as well as SOAP.

For your approach you can use following code:


public class CMISTest {
public static void main(String [] args) {
try {

   String endpoint = "http://localhost:8080/alfresco/cmis/RepositoryService";
   
   Service serv = new Service();

   Call call = null;
   try {
      call = (Call) serv.createCall();

      call.setTargetEndpointAddress(new java.net.URL(endpoint));
   } catch (ServiceException e) {
      System.err.println("Servic call create error");
   } catch (MalformedURLException e) {
      System.err.println("Malformed url");
   }

   
   ParameterDesc param;
        OperationDesc oper = new OperationDesc();
        oper.setName("getRepositories");
        param = new org.apache.axis.description.ParameterDesc(new javax.xml.namespace.QName("http://docs.oasis-open.org/ns/cmis/messaging/200908/", "getRepositories"), org.apache.axis.description.ParameterDesc.IN, new javax.xml.namespace.QName("http://docs.oasis-open.org/ns/cmis/messaging/200908/", ">getRepositories"));
       
        oper.addParameter(param);
        oper.setReturnType(new javax.xml.namespace.QName("http://docs.oasis-open.org/ns/cmis/messaging/200908/", ">getRepositoriesResponse"));
        oper.setReturnClass(CmisRepositoryEntryType[].class);
        oper.setReturnQName(new javax.xml.namespace.QName("http://docs.oasis-open.org/ns/cmis/messaging/200908/", "getRepositoriesResponse"));
       
        param = oper.getReturnParamDesc();
        param.setItemQName(new javax.xml.namespace.QName("http://docs.oasis-open.org/ns/cmis/messaging/200908/", "repositories"));
        oper.setStyle(org.apache.axis.constants.Style.DOCUMENT);
        oper.setUse(org.apache.axis.constants.Use.LITERAL);

        call.setOperationName(new javax.xml.namespace.QName("", "getRepositories"));
        call.setOperation(oper);

        QName qName = new QName("http://docs.oasis-open.org/ns/cmis/messaging/200908/", ">getRepositoriesResponse");
        call.registerTypeMapping(CmisRepositoryEntryType[].class, qName, ArraySerializerFactory.class, ArrayDeserializerFactory.class);

        qName = new javax.xml.namespace.QName("http://docs.oasis-open.org/ns/cmis/messaging/200908/", "cmisRepositoryEntryType");
        call.registerTypeMapping(CmisRepositoryEntryType.class, qName, BeanSerializerFactory.class, BeanDeserializerFactory.class);

   SOAPEnvelope se = new SOAPEnvelope(); // dummy envelope to create Header
   Document doc = null;
   try {
      doc = se.getAsDocument();
   } catch (Exception e) {
      System.err.println("Exception caught while getting the doc");
   }

   WSSecHeader secHeader = new WSSecHeader();
   secHeader.setMustUnderstand(true);
   secHeader.insertSecurityHeader(doc);

   UsernameToken username = new UsernameToken(Boolean.TRUE, doc,
         WSConstants.PASSWORD_TEXT);
   username.setName("admin");
   username.setPassword("admin");
   Timestamp ts = new Timestamp(true, doc, 300);

   WSSecurityUtil.prependChildElement(doc, secHeader.getSecurityHeader(),
         username.getElement(), false);
   WSSecurityUtil.prependChildElement(doc, secHeader.getSecurityHeader(),
         ts.getElement(), false);



   SOAPHeaderElement she = new SOAPHeaderElement(secHeader.getSecurityHeader());
   call.addHeader(she);

   try {
      
      CmisRepositoryEntryType[] ret = null;
        try
        {
            ret = (CmisRepositoryEntryType[]) call.invoke(new Object[] { null });

        }
        catch (Exception e)
        {
            System.out.println("Inside remote");
            System.err.println("Remote exception : " + e.getMessage());
        }

        for (CmisRepositoryEntryType repository : ret)
        {
            System.out.println("Repository [Name=" + repository.getRepositoryName() + ", id=" + repository.getRepositoryId() + "]");
        }
      
   } catch (Exception e) {
      System.out.println("Inside remote");
      System.err.println("Remote exception : " + e.getMessage());
   }
   
} catch (Exception e) {
e.printStackTrace();
}
}
}

Cheers  😎

silvia1983
Champ in-the-making
Champ in-the-making
Thank you very much Nike!

At least I could get the repositoryId, now I'll try to create a document.

Thank you so much!!!

silvia1983
Champ in-the-making
Champ in-the-making
Hi again!

My problem continue because when I call createDocument Service or createFolder I get this error: Type Id property required

well, I don't know the way to get all the information that I need to get this client works fine because in other posts I saw that people use addNewProperties, but i don't have this metthod.

I need to import some library from Alfresco?

Thanks

nikes
Champ on-the-rise
Champ on-the-rise
I had issues with parsing while using Axis and Axis 2 frameworks.

I would suggest to use Apache CXF framework or OpenCMIS API for simplicity.

Refer my earlier reply for Apache CXF Sample code.

Go through CMIS Specs for basics of CMIS standard and definitions.

In your case you need to set property "cmisSmiley SurprisedbjectTypeId" with values "cmis:folder" for folder and
"cmis:document" for creating document.

Hope this helps.

silvia1983
Champ in-the-making
Champ in-the-making
Thank you!

But i can't use this framework because I use jdk 1.4

I've put the properties like this:

CmisPropertyId cmisId = new CmisPropertyId();
cmisId.setPropertyDefinitionId("cmisSmiley SurprisedbjectTypeId");
cmisId.setValue(new String[]{"cmis:document"});

but now I get this message 'Name property not found'

i don't know how to do this… :cry:

silvia1983
Champ in-the-making
Champ in-the-making
Hi!

Finally I could have created a document in a folder!!

It was missing the Stringproperty

Thank you everybody
Getting started

Tags


Find what you came for

We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.