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 05-07-2007, 09:14 AM
Senior Member
 
Posts: 55
Default Add account using SOAP

Hello ,
Has someone already did an application that add zimbra account using SOAP
thx
Reply With Quote
  #2 (permalink)  
Old 05-09-2007, 08:51 AM
Member
 
Posts: 11
Default Soap accont create

Yes i write simple java aplication witch via soap add account. You must login on ZImbraServer:7071/service/admin/soap
and send CreateAccount request witch is describe in soap-admin.txt
Reply With Quote
  #3 (permalink)  
Old 05-09-2007, 01:49 PM
Senior Member
 
Posts: 55
Default

hello thx for your answer
it will very nice from you if u sent me your code java because i already try what u say and i have some exception that seams difficult for me
thx
Reply With Quote
  #4 (permalink)  
Old 05-10-2007, 01:17 AM
Member
 
Posts: 11
Default

Ok this is my code mybe it not look pretty but it work:
1. First you must connect to zimbra admin SOAP service for example and get auth token and session ID:
Code:
import com.zimbra.common.service.ServiceException;
import com.zimbra.cs.service.account.AccountService;
import com.zimbra.cs.service.admin.AdminService;
import com.zimbra.soap.Element;
import com.zimbra.soap.SoapFaultException;
import com.zimbra.soap.SoapHttpTransport;
import com.zimbra.soap.ZimbraSoapContext;
Code:
SoapHttpTransport trans = null;
try {
			
trans = new SoapHttpTransport("https://youZimbraServer:7071/service/admin/soap/"
					);
			
Element request = Element.XMLElement.mFactory .createElement(AdminService.AUTH_REQUEST);

request.addAttribute(AdminService.E_NAME,"admin@example.com",Element.DISP_CONTENT);
request.addAttribute(AdminService.E_PASSWORD, "password",
Element.DISP_CONTENT);
				 response = trans.invoke(request);
		} catch (Exception e) {
			e.printStackTrace();
		}
String authToken = null;
		 // get the auth token out, no default, must be present or a service exception is thrown
        try {
			authToken = response.getAttribute(AccountService.E_AUTH_TOKEN);
		} catch (ServiceException e) {
			// 
			e.printStackTrace();
		}
        // get the session id, if not present, default to null
        String sessionId = response.getAttribute(ZimbraSoapContext.E_SESSION_ID, null);
        System.out.println(sessionId);
        trans.setAuthToken(authToken);
        if (sessionId != null)
             trans.setSessionId(sessionId);


2. Now when you have a token and session ID you can send a request to create account:
Code:
Element accRequest = Element.XMLElement.mFactory.createElement(AdminService.CREATE_ACCOUNT_REQUEST);
accRequest.addElement(AdminService.E_NAME).setText("test@example.com");
accRequest.addElement(AdminService.E_PASSWORD).setText("examplepasswd");
//You can set another parametr for acconut for example:
//tagsRequest.addElement(AdminService.E_A).addAttribute("n", "zimbraPrefFromDisplay").setText("example");
//in response you get a all atribute for account
Element accResponse = null;
		try {
			accResponse = trans.invoke(accRequest);
		} catch (SoapFaultException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
        System.out.println(accResponse.prettyPrint());
3. If all go ok on you console show samethig like that:
Code:
<CreateAccountResponse xmlns="urn:zimbraAdmin">
  <account id="zimbra id" name="test@example.com">
    <a n="zimbraPrefGalAutoCompleteEnabled">FALSE</a>
    <a n="zimbraPrefGroupMailBy">conversation</a>
      ....another atribute for account
      ....
    <a n="zimbraPrefCalendarInitialView">workWeek</a>
  </account>
</CreateAccountResponse>
4. You must change bold element in code

5. It should work - sorry for my English I still learn this language
Reply With Quote
  #5 (permalink)  
Old 05-10-2007, 03:06 AM
Senior Member
 
Posts: 55
Default

Thanks also for your code
Reply With Quote
  #6 (permalink)  
Old 10-05-2007, 04:38 PM
Junior Member
 
Posts: 9
Default

mrojek ... thanks for this post. I tried all that you said and i get this error:

at ZimbraSoap.main(ZimbraSoap.java:30)
Exception in thread "main" java.lang.NoSuchMethodError: org.apache.commons.httpclient.methods.PostMethod.s etRequestContentLength(J)V
at com.zimbra.soap.SoapHttpTransport.invoke(SoapHttpT ransport.java:184)
at com.zimbra.soap.SoapTransport.invoke(SoapTransport .java:231)
at ZimbraSoap.createUser(ZimbraSoap.java:110)
at ZimbraSoap.main(ZimbraSoap.java:30)

My code is straightforward:

__________________________________________________ ________________________
public void createUser() {
SoapHttpTransport trans = null;
try {
trans = new SoapHttpTransport(
"https://localhost.localdomain:7071/service/admin/soap/");
request = Element.XMLElement.mFactory
.createElement(AdminService.AUTH_REQUEST);
request.addAttribute(AdminService.E_NAME, "admin",
Element.DISP_CONTENT);
request.addAttribute(AdminService.E_PASSWORD, "password",
Element.DISP_CONTENT);
response = trans.invoke(request);
} catch (Exception e) {
e.printStackTrace();
} finally {
}
String authToken = null;
try {
authToken = response.getAttribute(AccountService.E_AUTH_TOKEN) ;
} catch (ServiceException e) {
e.printStackTrace();
}
String sessionId = response.getAttribute(
ZimbraSoapContext.E_SESSION_ID, null);
System.out.println(sessionId);
trans.setAuthToken(authToken);
if (sessionId != null)
trans.setSessionId(sessionId);

Element accRequest = Element.XMLElement.mFactory
.createElement(AdminService.CREATE_ACCOUNT_REQUEST );
accRequest.addElement(AdminService.E_NAME).setText ("test@example.com");
accRequest.addElement(AdminService.E_PASSWORD).set Text("examplepasswd");

Element accResponse = null;
try {
accResponse = trans.invoke(accRequest);
} catch (SoapFaultException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
System.out.println(accResponse.prettyPrint());
}
__________________________________________________ ___________________________

Last edited by ozomozo; 10-05-2007 at 04:41 PM..
Reply With Quote
  #7 (permalink)  
Old 10-07-2007, 07:16 PM
Zimbra Employee
 
Posts: 1,434
Default

Much easier is to use the createAccount() method in the com.zimbra.cs.account.soap.SoapProvisioning.java class provided with the ZCS source.
__________________
Bugzilla - Wiki - Downloads - Before posting... Search!
Reply With Quote
  #8 (permalink)  
Old 10-08-2007, 10:16 AM
Junior Member
 
Posts: 9
Default

dkarp

I tried using createAccount() and its the same:

__________________________________________________ ______________-
static SoapProvisioning sp = new SoapProvisioning();
private Account createAccount;
public void createAccount() {
try {
sp.soapSetURI("https://localhost.localdomain:7071" + ZimbraServlet.ADMIN_SERVICE_URI);
sp.soapAdminAuthenticate("admin","password");
createAccount = sp.createAccount("name@address.com", "zimbra", getMap());
}
catch(ServiceException se) {
se.printStackTrace();
} finally {
}
}
__________________________________________________ ______________

Error Stack:

at org.apache.commons.logging.LogFactory.getLog(LogFa ctory.java:353)
at org.apache.commons.httpclient.HttpClient.<clinit>( HttpClient.java:69)
at com.zimbra.soap.SoapHttpTransport.<init>(SoapHttpT ransport.java:71)
at com.zimbra.cs.account.soap.SoapProvisioning.soapSe tURI(SoapProvisioning.java:88)

at ZimbraSoap.createAccount(ZimbraSoap.java:110)
at ZimbraSoap.main(ZimbraSoap.java:38)

Last edited by ozomozo; 10-08-2007 at 10:51 AM..
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.