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 09-13-2007, 07:14 AM
Member
 
Posts: 10
Default [SOLVED] SOAP API from Java

I want to create accounts in zimbra from a java aplication. Y followed the wiki on ZClient - ZimbraWiki and I couldnt get auth token.
I did something like this (on Ubuntu 7.04, Zimbra 4.5, Eclipse 3.2):

SoapHttpTransport trans = null;
try {
trans = new SoapHttpTransport("https://www.technicaldetails.org" + ZimbraServlet.USER_SERVICE_URI);
Element request = Element.XMLElement.mFactory.createElement(AccountS ervice.AUTH_REQUEST);
request.addAttribute(AccountService.E_ACCOUNT, "userdoesntexist@technicaldetails.org", Element.DISP_CONTENT);
request.addAttribute(AccountService.E_PASSWORD, "notapassword", Element.DISP_CONTENT);
Element response = trans.invoke(request);
}
catch (Exception E)
e.printStackTrace();
}

But I had problemas with ssl. First throws javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException, then I did something like:
jturner@teacup:~$ openssl s_client -connect imap.atlassian.com:imaps
to get the certificate and
jturner@teacup:~$ keytool -import -alias mail.yourcompany.com -keystore /etc/java/keystore -file imapd.pem
And runs the applecation with -Djavax.net.ssl.trustStore=/etc/java/keystore
But throws java.net.SocketException: Default SSL context init failed: Invalid keystore format

Anybody can help me please??
Reply With Quote
  #2 (permalink)  
Old 09-13-2007, 09:06 AM
Zimlet Guru & Moderator
 
Posts: 467
Default

Quote:
Originally Posted by liriarte View Post
I want to create accounts in zimbra from a java aplication. Y followed the wiki on ZClient - ZimbraWiki and I couldnt get auth token.
I did something like this (on Ubuntu 7.04, Zimbra 4.5, Eclipse 3.2):

SoapHttpTransport trans = null;
try {
trans = new SoapHttpTransport("https://www.technicaldetails.org" + ZimbraServlet.USER_SERVICE_URI);
Element request = Element.XMLElement.mFactory.createElement(AccountS ervice.AUTH_REQUEST);
request.addAttribute(AccountService.E_ACCOUNT, "userdoesntexist@technicaldetails.org", Element.DISP_CONTENT);
request.addAttribute(AccountService.E_PASSWORD, "notapassword", Element.DISP_CONTENT);
Element response = trans.invoke(request);
}
catch (Exception E)
e.printStackTrace();
}

But I had problemas with ssl. First throws javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException, then I did something like:
jturner@teacup:~$ openssl s_client -connect imap.atlassian.com:imaps
to get the certificate and
jturner@teacup:~$ keytool -import -alias mail.yourcompany.com -keystore /etc/java/keystore -file imapd.pem
And runs the applecation with -Djavax.net.ssl.trustStore=/etc/java/keystore
But throws java.net.SocketException: Default SSL context init failed: Invalid keystore format

Anybody can help me please??
what does /etc/java/keystore look like? (don't copy and paste the key, but is it ascii, binrary, etc? Does it contain error messages?
Reply With Quote
  #3 (permalink)  
Old 09-13-2007, 09:40 AM
Member
 
Posts: 10
Default

I put the response of openssl command in a file imapd.pem, it looks like a certificate with
-----BEGIN CERTIFICATE-----
**
-----END CERTIFICATE-----

The I try to import that certificate with keytool and try to call zimbra from my eclipse with this keytore. Is it right?
--
Reply With Quote
  #4 (permalink)  
Old 09-13-2007, 03:51 PM
Zimbra Employee
 
Posts: 1,434
Default

Quote:
Originally Posted by liriarte View Post
I want to create accounts in zimbra from a java aplication.
Have you considered using the SoapProvisioning.java class? It wraps all the account/cos/domain/etc. provisioning requests in a Java interface.
__________________
Bugzilla - Wiki - Downloads - Before posting... Search!
Reply With Quote
  #5 (permalink)  
Old 09-14-2007, 04:58 AM
Member
 
Posts: 10
Default

Quote:
Originally Posted by dkarp View Post
Have you considered using the SoapProvisioning.java class? It wraps all the account/cos/domain/etc. provisioning requests in a Java interface.
Yes I tried that and also I tried something like
Zimbra.toolSetup();
String serverURL = "http://tsavo4:7071/zimbra";
LmcPingRequest pr = new LmcPingRequest();
try {
LmcPingResponse pResp = (LmcPingResponse) pr.invoke(serverURL);
}

But nothing, the problem is with ssl and certificates.
Reply With Quote
  #6 (permalink)  
Old 09-14-2007, 05:54 AM
Member
 
Posts: 10
Default com.zimbra.soap.SoapParseException: unable to parse response:

Quote:
Originally Posted by liriarte View Post
Yes I tried that and also I tried something like
Zimbra.toolSetup();
String serverURL = "http://tsavo4:7071/zimbra";
LmcPingRequest pr = new LmcPingRequest();
try {
LmcPingResponse pResp = (LmcPingResponse) pr.invoke(serverURL);
}

But nothing, the problem is with ssl and certificates.
I can fixed the ssl problem. Know I get this:
com.zimbra.soap.SoapParseException: unable to parse response: <html><head><title>Apache Tomcat/5.5.15 - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;

?¿
Reply With Quote
  #7 (permalink)  
Old 09-14-2007, 09:16 AM
Zimbra Employee
 
Posts: 1,434
Default

Send the request to http://tsavo4:7071/service/admin/soap instead of http://tsavo4:7071/zimbra. And seriously, please consider using the SoapProvisioning.java class.
__________________
Bugzilla - Wiki - Downloads - Before posting... Search!
Reply With Quote
  #8 (permalink)  
Old 09-14-2007, 09:22 AM
Member
 
Posts: 10
Default

Quote:
Originally Posted by dkarp View Post
Send the request to http://tsavo4:7071/service/admin/soap instead of http://tsavo4:7071/zimbra. And seriously, please consider using the SoapProvisioning.java class.
The url is not the problem, with that change nothing happens. I will use SoapProvisioning but I have the same error
Reply With Quote
  #9 (permalink)  
Old 09-14-2007, 04:24 PM
Zimbra Employee
 
Posts: 1,434
Default

Right! Since you're going to the admin interface, you must use https.
__________________
Bugzilla - Wiki - Downloads - Before posting... Search!
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.