Zimbra offers Open Source email server software and shared calendar for Linux and the Mac
Go Back   Zimbra :: Forums > Zimbra Collaboration Suite > Developers

Welcome to the Zimbra :: Forums!
Welcome, if you would like to post a comment please register. We also encourage you to explore all things Zimbra with our team and members of the community.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-28-2011, 07:41 AM
Intermediate Member
 
Posts: 17
Default [SOLVED] Java SOAP Request receiving service.UNKNOWN_DOCUMENT

Answer to this (admin, please correct if needed): sevice.UNKNOWN_DOCUMENT happens when server cannot recognize the request (not sure of other reasons for this error). This can be due to the XML element not being linked to appropriate namespace.

Here is one way to write XML using namespaces:

Code:
<soap:Envelope
		xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
		xmlns:zimbra="urn:zimbra"
		xmlns:zaccount="urn:zimbraAccount"
		xmlns:zmail="urn:zimbraMail"
		xmlns:zadmin="urn:zimbraAdmin">
...
	<soap:Body>
		<zaccount:AuthRequest>
			<account by="name">[USERNAME]</account>
			<password>[PWD]</password>
		</zaccount:AuthRequest>
	</soap:Body>
... OR ...
	<soap:Body>
		<zmail:GetFreeBusyRequest
				s="[START_TIME_MS]"
				e="[END_TIME_MS]"
				name="[USERNAME]">
		</zmail:GetFreeBusyRequest>
	</soap:Body>
Entering xmlns in envelope creates simple, consistent structure for this; then each element can be entered as shown above.

- Answer done.

- - - - - - - - - - - - - - - - - - - - - - - -

I wrote Java SOAP request and am getting back unknown document from Zimbra 6.0. Below are code, SOAP request being sent, and response. The request is being made to our test server "carmen.egr.msu.edu" for user "user1".

Please help determine what the problem is, and how to fix it.

SOAP Request:
Quote:
<?xml version="1.0" encoding="UTF-8"?>

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<soap:context xmlns:soap="http://carmen.egr.msu.edu/service/soap/" xmlns="urn:zimbraSoap">
<nonotify xmlns=""></nonotify>
<noqualify xmlns=""></noqualify>
</soap:context>
</soap:Header>
<soap:Body>
<soap:AuthRequest xmlns="urn:zimbraSoap">
<account xmlns="" by="name">user1</account>
<password xmlns=""></password>
</soap:AuthRequest>
<SearchRequest calExpandInstEnd="1256248799000" calExpandInstStar="1193004000000" types="appointment"/>
</soap:Body>
</soap:Envelope>
SOAP Response:
Quote:
<?xml version="1.0" encoding="UTF-8"?>

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<context xmlns="urn:zimbra"></context>
</soap:Header>
<soap:Body>
<soap:Fault>
<soap:faultcode>soap:Client</soap:faultcode>
<soap:faultstring>unknown document: soap:AuthRequest</soap:faultstring>
<soap:detail>
<Error xmlns="urn:zimbra">
<Code>service.UNKNOWN_DOCUMENT</Code>
<Trace>com.zimbra.common.service.ServiceExceptio n: unknown document: soap:AuthRequest ExceptionId:btpool0-16://carmen.egr.msu.edu/service/soap/:1301322591086:0f0b2eafcb1b26e0 Code:service.UNKNOWN_DOCUMENT at com.zimbra.common.service.ServiceException.UNKNOWN _DOCUMENT(ServiceException.java:262) at com.zimbra.soap.SoapEngine.dispatchRequest(SoapEng ine.java:330) at com.zimbra.soap.SoapEngine.dispatch(SoapEngine.jav a:274) at com.zimbra.soap.SoapEngine.dispatch(SoapEngine.jav a:158) at com.zimbra.soap.SoapServlet.doWork(SoapServlet.jav a:291) at com.zimbra.soap.SoapServlet.doPost(SoapServlet.jav a:212) at javax.servlet.http.HttpServlet.service(HttpServlet .java:727) at com.zimbra.cs.servlet.ZimbraServlet.service(Zimbra Servlet.java:181) at javax.servlet.http.HttpServlet.service(HttpServlet .java:820) at org.mortbay.jetty.servlet.ServletHolder.handle(Ser vletHolder.java:511) at org.mortbay.jetty.servlet.ServletHandler$CachedCha in.doFilter(ServletHandler.java:1166) at com.zimbra.cs.servlet.SetHeaderFilter.doFilter(Set HeaderFilter.java:79) at org.mortbay.jetty.servlet.ServletHandler$CachedCha in.doFilter(ServletHandler.java:1157) at org.mortbay.servlet.UserAgentFilter.doFilter(UserA gentFilter.java:81) at org.mortbay.servlet.GzipFilter.doFilter(GzipFilter .java:155) at org.mortbay.jetty.servlet.ServletHandler$CachedCha in.doFilter(ServletHandler.java:1157) at org.mortbay.jetty.servlet.ServletHandler.handle(Se rvletHandler.java:388) at org.mortbay.jetty.security.SecurityHandler.handle( SecurityHandler.java:216) at org.mortbay.jetty.servlet.SessionHandler.handle(Se ssionHandler.java:182) at org.mortbay.jetty.handler.ContextHandler.handle(Co ntextHandler.java:765) at org.mortbay.jetty.webapp.WebAppContext.handle(WebA ppContext.java:418) at org.mortbay.jetty.handler.ContextHandlerCollection .handle(ContextHandlerCollection.java:230) at org.mortbay.jetty.handler.HandlerCollection.handle (HandlerCollection.java:114) at org.mortbay.jetty.handler.HandlerWrapper.handle(Ha ndlerWrapper.java:152) at org.mortbay.jetty.handler.rewrite.RewriteHandler.h andle(RewriteHandler.java:230) at org.mortbay.jetty.handler.HandlerWrapper.handle(Ha ndlerWrapper.java:152) at org.mortbay.jetty.handler.DebugHandler.handle(Debu gHandler.java:77) at org.mortbay.jetty.handler.HandlerWrapper.handle(Ha ndlerWrapper.java:152) at org.mortbay.jetty.Server.handle(Server.java:326) at org.mortbay.jetty.HttpConnection.handleRequest(Htt pConnection.java:543) at org.mortbay.jetty.HttpConnection$RequestHandler.co ntent(HttpConnection.java:939) at org.mortbay.jetty.HttpParser.parseNext(HttpParser. java:755) at org.mortbay.jetty.HttpParser.parseAvailable(HttpPa rser.java:212) at org.mortbay.jetty.HttpConnection.handle(HttpConnec tion.java:405) at org.mortbay.io.nio.SelectChannelEndPoint.run(Selec tChannelEndPoint.java:413) at org.mortbay.thread.BoundedThreadPool$PoolThread.ru n(BoundedThreadPool.java:451)</Trace>
</Error>
</soap:detail>
</soap:Fault>
</soap:Body>
</soap:Envelope>

JAVA:
Code:
import java.io.ByteArrayOutputStream;
import java.net.URL;

import javax.xml.soap.MessageFactory;
import javax.xml.soap.SOAPBody;
import javax.xml.soap.SOAPConnection;
import javax.xml.soap.SOAPConnectionFactory;
import javax.xml.soap.SOAPElement;
import javax.xml.soap.SOAPEnvelope;
import javax.xml.soap.SOAPHeader;
import javax.xml.soap.SOAPMessage;

		MessageFactory mf = MessageFactory.newInstance();
		SOAPMessage sm = mf.createMessage();
		SOAPEnvelope envelope = sm.getSOAPPart().getEnvelope();
		envelope.addNamespaceDeclaration("soap", "http://carmen.egr.msu.edu/service/soap/");
		envelope.setPrefix("soap");
		envelope.setAttribute("xmlns:soap", "http://carmen.egr.msu.edu/service/soap/");
		SOAPHeader header = envelope.getHeader();
		header.setPrefix("soap");
		SOAPElement context = header.addChildElement("context", "soap");
		context.setAttribute("xmlns", "urn:zimbraSoap");
		context.addChildElement("nonotify");
		context.addChildElement("noqualify");
		SOAPBody body = envelope.getBody();
		body.setPrefix("soap");
		SOAPElement authRequest = body.addChildElement("AuthRequest");
		authRequest.setPrefix("soap");
		authRequest.setAttribute("xmlns", "urn:zimbraSoap");
		SOAPElement account = authRequest.addChildElement("account");
		account.setAttribute("by", "name");
		account.setTextContent("user1");
		SOAPElement password = authRequest.addChildElement("password");
		password.setTextContent("foo");
		// Request
		SOAPElement request = body.addChildElement("SearchRequest");
		request.setAttribute("types", "appointment");
		request.setAttribute("calExpandInstStar", "1193004000000");
		request.setAttribute("calExpandInstEnd", "1256248799000");
		// Display SOAP Request
		System.out.println("\nSoap Request: ");
		writeSoapMessagePretty(sm);
		// Make request
		SOAPConnectionFactory sfc = SOAPConnectionFactory.newInstance();
		SOAPConnection connection = sfc.createConnection();
		URL requestUrl = new URL("http://carmen.egr.msu.edu/service/soap/");
		SOAPMessage response = connection.call(sm, requestUrl);
		// Print SOAP response
		writeSoapMessagePretty(response);

Last edited by raymond.naseef; 04-10-2011 at 07:34 AM..
Reply With Quote
  #2 (permalink)  
Old 04-29-2011, 07:22 PM
Intermediate Member
 
Posts: 15
Default

It seems that there is no way to change the soap namespace in Zimbra java client.

However, even we use the raw soap api, by:
SOAPMessage sm = mf.createMessage();
SOAPEnvelope envelope = sm.getSOAPPart().getEnvelope();
envelope.addNamespaceDeclaration("soap", "http://www.w3.org/2003/05/soap-envelope");
envelope.setPrefix("soap");
envelope.setAttribute("xmlns:soap", "http://www.w3.org/2003/05/soap-envelope");
SOAPHeader header = envelope.getHeader();
header.setPrefix("soap");
SOAPElement context = header.addChildElement("context", "soap");
context.setAttribute("xmlns", "urn:zimbraSoap");
context.addChildElement("nonotify");
context.addChildElement("noqualify");

There is still an UNKNOWN-DOCUMENT fail error in the soap response.

Last edited by nickzm; 04-29-2011 at 10:27 PM..
Reply With Quote
  #3 (permalink)  
Old 05-01-2011, 06:07 PM
Intermediate Member
 
Posts: 17
Default Example for SOAP with namespaces

Here is example of one of our requests; notice the "SOAP" namespace is not changed; each element can have prefix of namespace for it (e.g., <SoapRequest> has <zmail:SearchRequest>).

That request successfully gets back user's free/busy times in Zimbra v6.0.8.

Hope this helps,
Ray

Code:
POST /service/soap HTTP/1.1
Host: carmen.egr.msu.edu
Content-Type: text/xml; charset="utf-8"

<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope
		xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
		xmlns:zimbra="urn:zimbra"
		xmlns:zaccount="urn:zimbraAccount"
		xmlns:zmail="urn:zimbraMail">
	<soap:Header>
		<zimbra:context xmlns="urn:zimbraSoap">
			<zaccount:authToken>...</zaccount:authToken>
			<nonotify/>
			<noqualify/>
		</zimbra:context>
	</soap:Header>
	<soap:Body>
		<zmail:SearchRequest
				types="appointment"
				calExpandInstStar="1301394794379"
				calExpandInstEnd="1301452394379">
			<query>inid:10</query>
		</zmail:SearchRequest>
	</soap:Body>
</soap:Envelope>
Reply With Quote
  #4 (permalink)  
Old 05-01-2011, 08:28 PM
Intermediate Member
 
Posts: 15
Default

It is resolved by changing the namespace.
Reply With Quote
  #5 (permalink)  
Old 03-21-2012, 06:33 PM
Junior Member
 
Posts: 7
Default

Quote:
Originally Posted by nickzm View Post
It is resolved by changing the namespace.
Which namespace did you change to make it work?
Reply With Quote
  #6 (permalink)  
Old 03-22-2012, 10:34 AM
Intermediate Member
 
Posts: 17
Default

Sorry, that sentence is vague. The issue is that namespaces need to be set for certain elements, such as "<SearchRequest" above being set "<zimbra:SearchRequest". If you look at my XML above, the error was for request "<SearchRequest".
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads

Why Join?

Registering let's you ask questions, makes it easier to search, displays any files attached to posts, and notifies you about replies.

blog.zimbra.com




 

SEO by vBSEO ©2011, Crawlability, Inc.