I tried to execute webservice client (Apache Axis) against Alfresco
community version 3.2r2, and I am getting following exception:
10:27:33,027 ERROR [axis.client.Call] Exception:
org.xml.sax.SAXException: SimpleDeserializer encountered a child
element, which is NOT expected, in something it was trying to
deserialize.
at
org.apache.axis.encoding.ser.SimpleDeserializer.onStartChild(SimpleDeserializer.java:
145)
at
org.apache.axis.encoding.DeserializationContext.startElement(DeserializationContext.java:
1035)
at
org.apache.axis.message.SAX2EventRecorder.replay(SAX2EventRecorder.java:
165)
at
org.apache.axis.message.MessageElement.publishToHandler(MessageElement.java:
1141)
at org.apache.axis.message.RPCElement.deserialize(RPCElement.java:
236)
at org.apache.axis.message.RPCElement.getParams(RPCElement.java:384)
at org.apache.axis.client.Call.invoke(Call.java:2467)
at org.apache.axis.client.Call.invoke(Call.java:2366)
at org.apache.axis.client.Call.invoke(Call.java:1812)
at CMIS.CMISTest.main(CMISTest.java:120)
Remote exception : ; nested exception is:
org.xml.sax.SAXException: SimpleDeserializer encountered a child
element, which is NOT expected, in something it was trying to
deserialize.
JAVA Code:
package CMIS;
import java.net.MalformedURLException;
import java.rmi.RemoteException;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import javax.xml.namespace.QName;
import javax.xml.rpc.ParameterMode;
import javax.xml.rpc.ServiceException;
import org.apache.axis.message.SOAPHeaderElement;
import org.apache.axis.message.SOAPEnvelope;
import org.apache.ws.security.message.token.UsernameToken;
import org.apache.ws.security.WSConstants;
import org.apache.ws.security.message.WSSecHeader;
import org.apache.ws.security.util.WSSecurityUtil;
import org.w3c.dom.Document;
import org.apache.ws.security.message.token.Timestamp;
public class CMISTest {
public static void main(String [] args) {
try {
String endpoint = "http://localhost:8080/alfresco/cmis/
RepositoryService";
// String repID = "/app:company_home/cm:Shivam";
String repID ="46f8b242-9f61-423b-b824-c6118f470f01";
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");
}
call.setOperationName(new QName("http://www.cmis.org/2008/05",
"getRepositories"));
call.addParameter("id", new QName("http://www.w3.org/2001/XMLSchema",
"string"), ParameterMode.IN);
call.setReturnType(new QName("http://www.w3.org/2001/XMLSchema",
"string"));
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);
String ret = null;
try {
//call.invokeOneWay(new Object[] { repID});
ret = call.invoke(new Object[] { repID }).toString();
} catch (Exception e) {
System.out.println("Inside remote");
System.err.println("Remote exception : " + e.getMessage());
}
System.out.println(ret);
} catch (Exception e) {
e.printStackTrace();
}
}
}
Kindly suggest how to resolve it.
Thanks,
Nikesh
--
You received this message because you are subscribed to the Google Groups "CMIS Interoperability" group.
To post to this group, send email to cmis-i...@googlegroups.com.
To unsubscribe from this group, send email to cmis-interop...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/cmis-interop?hl=en.
It worked....
On Feb 18, 8:42 pm, David Caruana <david.caru...@alfresco.com> wrote:
> Nikesh,
>
> Your usage of AXIS is incorrect. You assume the response is a string, but it contains the following structure:
> <repositories>
> <repositoryId>0d599136-0485-4258-ad8b-0edd456d2aa3</repositoryId>
> <repositoryName>Main Repository</repositoryName>
> </repositories>
>
> See fix for your code below. It contains deserialization of CmisRepositoryEntryType.
>
> In general it is not good practice to manually code for xml serialization/deserialization. AXIS allows to generate stubs, skeletons, and data types from WSDL using WSDL2Java tool.
>
> You can see Alfresco CMIS tests as example of CMIS AXIS client:http://svn.alfresco.com/repos/alfresco-open-mirror/alfresco/HEAD/root...
> ...
>
> read more »