Open-Xchange-SOAP-WSDL2JAVA

Revision as of 12:31, 20 December 2011 by Choeger (talk | contribs) (Generating code with wsdl2java from Axis2)

How to provision Open-Xchange with Java and SOAP

Generating code with wsdl2java from Axis2

See the sample script below on how to generate stubs for the Open-Xchange provisioning APIs.

#!/bin/bash

DEST=/home/someuser/workspace/axistest
AXISPATH=/home/someuser/axis2-1.5.6
OXURL=http://localhost/servlet/axis2/services
JAVA_HOME=/usr/lib/jvm/java-6-sun

for class in Context User Group Resource; do
       lname=$(echo $class | tr '[:upper:]' '[:lower:]')
       if [ -d $DEST/$lname ]; then
               rm -rf $DEST/$lname
       fi
       $AXISPATH/bin/wsdl2java.sh -p ox${lname} -u -uw -sp -uri $OXURL/OX${class}Service?wsdl -o $DEST/$lname -ns2p http://soap.admin.openexchange.com=admin.soap.${lname},http://dataobjects.soap.admin.openexchange.com/xsd=admin.soap.${lname}.dataobjects,http://dataobjects.rmi.admin.openexchange.com/xsd=admin.rmi.${lname}.dataobjects,http://exceptions.rmi.admin.openexchange.com/xsd=admin.rmi.${lname}.exceptions,http://rmi.java/xsd=admin.rmi.${lname},http://io.java/xsd=admin.javaio.${lname}
done

The script generates stubs for each of the Context, User, Group and Resource API within a separate directory.

Example Code

The code below lists all users within Context with ID 1:

import java.rmi.RemoteException;
import oxuser.DatabaseUpdateExceptionException;
import oxuser.DuplicateExtensionExceptionException;
import oxuser.InvalidCredentialsExceptionException;
import oxuser.InvalidDataExceptionException;
import oxuser.NoSuchContextExceptionException;
import oxuser.NoSuchUserExceptionException;
import oxuser.OXUserServiceStub;
import oxuser.RemoteExceptionException;
import oxuser.StorageExceptionException;
import admin.rmi.user.dataobjects.Credentials;
import admin.soap.user.dataobjects.Context;
import admin.soap.user.dataobjects.User;

public class UserSOAPTest {

   public static void main(String[] args) throws RemoteException, InvalidDataExceptionException, StorageExceptionException, InvalidCredentialsExceptionException, DatabaseUpdateExceptionException, NoSuchContextExceptionException, RemoteExceptionException, NoSuchUserExceptionException, DuplicateExtensionExceptionException {
       OXUserServiceStub oxus = new OXUserServiceStub("http://10.20.30.176/servlet/axis2/services/OXUserService.OXUserServiceHttpSoap12Endpoint/");

       Context c = new Context();
       c.setId(1);
       Credentials cred = new Credentials();
       cred.setLogin("oxadmin");
       cred.setPassword("secret");
       User allusers[] = oxus.listAll(c, cred);
       allusers = oxus.getMultipleData(c, allusers, cred);
       for(final User u : allusers) {
           System.out.println("Login: " + u.getName() + ", Displayname: " + u.getDisplay_name());
       }
   }
 }