[SOLVED] Java SOAP Client exception

Have a great idea for extending Zimbra? Share ideas, ask questions, contribute, and get feedback.
fmatar
Posts: 16
Joined: Sat Sep 13, 2014 1:25 am

[SOLVED] Java SOAP Client exception

Post by fmatar »

I'm invoking SOAP requests from a Java client and pro grammatically writing the soap request and invoking it. The outcome of my request looks as follows:

http://schemas.xmlsoap.org/soap/envelope/">















admin

testadmin






The exception I get is the following:

javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target


Now on another hand if I use the zmsoap utility to send the same request the request succeeds and here's the output:
zmsoap -z AuthRequest/account=admin @by=name ../password=testadmin -vv
Output:
Sending admin auth request to https://localhost:7071/service/admin/so ... admin/soap

http://www.w3.org/2003/05/soap-envelope ... p-envelope">















zimbra

***







http://www.w3.org/2003/05/soap-envelope ... p-envelope">











0_005d6e520a976d2095e9908551d5bdde93cc2bb1_69643d33363a65306661666438392d313336302d313164392d383636312d3030306139356439386566323b6578703d31333a313238323737303134373538363b61646d696e3d313a313b747970653d363a7a696d6272613b

43200000

false







Sending request to https://localhost:7071/service/admin/so ... admin/soap

http://www.w3.org/2003/05/soap-envelope ... p-envelope">





0_005d6e520a976d2095e9908551d5bdde93cc2bb1_69643d33363a65306661666438392d313336302d313164392d383636312d3030306139356439386566323b6578703d31333a313238323737303134373538363b61646d696e3d313a313b747970653d363a7a696d6272613b











admin

***







http://www.w3.org/2003/05/soap-envelope ... p-envelope">















0_31eaf7e80c9e15c68a36f9d1e804d0724ad6dfa1_69643d33363a63646666663332332d383463372d343038662d393439352d3939396436386130333636623b6578703d31333a313238323737303134373637313b61646d696e3d313a313b747970653d363a7a696d6272613b

43200000

false








What am I missing in here?
fmatar
Posts: 16
Joined: Sat Sep 13, 2014 1:25 am

[SOLVED] Java SOAP Client exception

Post by fmatar »

I have sorted out this problem by installing the java certificate now I get an error of a different kind
The error is the following:
java.io.IOException: Server returned HTTP response code: 405 for URL: https://volcano.webpatterns.net:7071/service/admin/soap

java.io.IOException: Server returned HTTP response code: 405 for URL: https://volcano.webpatterns.net:7071/se ... /soap?wsdl
What could be the cause of this?
marcmac
Elite member
Elite member
Posts: 2091
Joined: Fri Sep 12, 2014 9:53 pm

[SOLVED] Java SOAP Client exception

Post by marcmac »

You should look in the server logs for the errors, but I think your auth request is invalid; you need a "by" attribute, and if you're doing an admin auth by name, you need the fully qualified email address.
fmatar
Posts: 16
Joined: Sat Sep 13, 2014 1:25 am

[SOLVED] Java SOAP Client exception

Post by fmatar »

I don't think that's the actual problem, I have modified my SOAP request to authenticate a regular user, from zmsoap it works fine, the command looks as follows:

./zmsoap -m tom -p cruise -u https://localhost:7071/service/admin/so ... admin/soap --type account AuthRequest/account=tom @by=name ../password=cruise -vv
the output is as follows:

Sending auth request to https://localhost:7071/service/admin/so ... admin/soap

http://www.w3.org/2003/05/soap-envelope ... p-envelope">















tom

***







http://www.w3.org/2003/05/soap-envelope ... p-envelope">















0_25ef8acf5ba34db4629d9b99cf3eb91dc843d9a7_69643d33363a31633835323736312d346165392d343039342d613930312d6539383031393935646362343b6578703d31333a313238323932373932323031323b76763d313a313b747970653d363a7a696d6272613b

172800000

beach







Sending request to https://localhost:7071/service/admin/so ... admin/soap

http://www.w3.org/2003/05/soap-envelope ... p-envelope">





0_25ef8acf5ba34db4629d9b99cf3eb91dc843d9a7_69643d33363a31633835323736312d346165392d343039342d613930312d6539383031393935646362343b6578703d31333a313238323932373932323031323b76763d313a313b747970653d363a7a696d6272613b











tom

***







http://www.w3.org/2003/05/soap-envelope ... p-envelope">















0_9a273e82149b90652ce8b765003dcf2204ea6ae2_69643d33363a31633835323736312d346165392d343039342d613930312d6539383031393935646362343b6578703d31333a313238323932373932323035353b76763d313a313b747970653d363a7a696d6272613b

172800000

beach







Now the same generated request, sent through the SOAP API is as follows:


http://schemas.xmlsoap.org/soap/envelope/">















tom

cruite








and the error I get is the following:


java.io.IOException: Server returned HTTP response code: 405 for URL: https://volcano.webpatterns.net:7071/service/admin/soap

java.io.IOException: Server returned HTTP response code: 405 for URL: https://volcano.webpatterns.net:7071/se ... /soap?wsdl


Can anyone assist?
marcmac
Elite member
Elite member
Posts: 2091
Joined: Fri Sep 12, 2014 9:53 pm

[SOLVED] Java SOAP Client exception

Post by marcmac »

Again, look at the logs on the server to see why it's throwing that 405 response (method not allowed). Is your script performing a GET? That wsdl fetch line is not really necessary.
fmatar
Posts: 16
Joined: Sat Sep 13, 2014 1:25 am

[SOLVED] Java SOAP Client exception

Post by fmatar »

What log file should I check? I see tons of log files in the /opt/zimbra/log folder
marcmac
Elite member
Elite member
Posts: 2091
Joined: Fri Sep 12, 2014 9:53 pm

[SOLVED] Java SOAP Client exception

Post by marcmac »

mailbox.log.
Since you're getting a 405 response, which is unusual, it would probably help to post the full HTTP headers from your client as well, since the soap looks right (though the password in your request has a typo, compared to the zmsoap command line invocation you posted).
fmatar
Posts: 16
Joined: Sat Sep 13, 2014 1:25 am

[SOLVED] Java SOAP Client exception

Post by fmatar »

True there's a typo error in the entry above, now since i'm using the soap api directly, how do I post the http headers? the code I have looks as follows:


public SOAPMessage authenticateById(String urlStr, String id, String password) throws SOAPException, IOException {

MessageFactory mf = MessageFactory.newInstance();

SOAPMessage sm = mf.createMessage();

SOAPHeader sh = sm.getSOAPHeader();

SOAPBody sb = sm.getSOAPBody();



/* Build soap header */

QName headerName = new QName("urn:zimbra", "context");

SOAPHeaderElement headerElement = sh.addHeaderElement(headerName);

QName noSessionQName = new QName("nosession");

headerElement.addChildElement(noSessionQName);
/* Build soap body */

QName serviceName = new QName("urn:zimbraAccount", "AuthRequest");

SOAPBodyElement bodyElement = sb.addBodyElement(serviceName);

QName nameQn = new QName("account");

SOAPElement nameElementValue = bodyElement.addChildElement(nameQn);

nameElementValue.addAttribute(new QName("by"), "name");

nameElementValue.addTextNode(id);

QName passwordQn = new QName("password");

SOAPElement passwordElementValue = bodyElement.addChildElement(passwordQn);

passwordElementValue.addTextNode(password);
sm.writeTo(System.out);
URL url = new URL(urlStr);

Service service = Service.create(url, serviceName);
Dispatch dispatch = service.createDispatch(serviceName, SOAPMessage.class, Service.Mode.MESSAGE);

SOAPMessage request = MessageFactory.newInstance().createMessage(null, new FileInputStream("result.xml"));

SOAPMessage response = dispatch.invoke(request);

response.writeTo(System.out);

return sm;

}


So basically to invoke the AuthRequest for user: henry with password 1234 at url https://localhost:7071/soap/admin/service you would do the following


authenticateById(https://localhost:7071/service/admin/soap", "henry", "1234");

marcmac
Elite member
Elite member
Posts: 2091
Joined: Fri Sep 12, 2014 9:53 pm

[SOLVED] Java SOAP Client exception

Post by marcmac »

There should be a way to have the API show the http(s) transaction, but you'll have to research the API docs to find it.
fmatar
Posts: 16
Joined: Sat Sep 13, 2014 1:25 am

[SOLVED] Java SOAP Client exception

Post by fmatar »

The error has been resolved, I have updated my client to invoke the soap services differently and now they work like charm. Thanks for the feedback
Post Reply