Open-Xchange-RMI
From Open-Xchange
How to provision Open-Xchange with Java RMI
Overview
You need a clone of the backend git repo. Therein you find the com.openexchange.admin.rmi package which contains the RMI bindings to the provisioning interface.
A documentation of the interface is given here: http://software.open-xchange.com/products/appsuite/doc/RMI
Example source is given below.
To build and run, put the .java files shown below in a directory and use something like
javac -d build -cp ~/git/backend.git/com.openexchange.admin.rmi/src:. *.java java -cp build CreateContext java -cp build ListContext java -cp build CreateUser ...
(or a build system / IDE of your choice).
Example: CreateContext.java
import java.util.Map; import java.util.HashMap; import java.util.Arrays; import java.rmi.Naming; import java.rmi.NotBoundException; import java.rmi.RemoteException; import java.net.MalformedURLException; import com.openexchange.admin.rmi.OXContextInterface; import com.openexchange.admin.rmi.dataobjects.Context; import com.openexchange.admin.rmi.dataobjects.Credentials; import com.openexchange.admin.rmi.dataobjects.Database; import com.openexchange.admin.rmi.dataobjects.User; import com.openexchange.admin.rmi.dataobjects.UserModuleAccess; import com.openexchange.admin.rmi.exceptions.ContextExistsException; import com.openexchange.admin.rmi.exceptions.InvalidCredentialsException; import com.openexchange.admin.rmi.exceptions.InvalidDataException; import com.openexchange.admin.rmi.exceptions.NoSuchContextException; import com.openexchange.admin.rmi.exceptions.StorageException; public class CreateContext { static String RMI_HOSTNAME = "rmi://192.168.101.84:1099/"; public static void main(final String args[]) { Context ctx = new Context(); ctx.setId(2001); ctx.setName("performance2001"); ctx.setMaxQuota(100l); ctx.addLoginMappings(Arrays.asList("defaultcontext,unfug".split(","))); final Integer db = new Integer(3); if( null != db ) { ctx.setWriteDatabase(new Database(db)); } final Map<String,Map<String,String>> userAttributes = new HashMap<String,Map<String,String>>(); final Map<String,String> taxMap = new HashMap<String,String>(); taxMap.put("types", "strangedomain"); userAttributes.put("taxonomy", taxMap); ctx.setUserAttributes(userAttributes); User user = new User(); user.setName("oxadmin"); user.setDisplay_name("OX Admin"); user.setGiven_name("OX"); user.setSur_name("Admin"); user.setPassword("secret"); user.setPrimaryEmail("oxadmin@performance2001"); user.setEmail1("oxadmin@performance2001"); user.setTimezone("Europe/Berlin"); user.setLanguage("de_DE"); String accessCombinationName = "all"; Credentials auth = new Credentials("oxadminmaster", "secret"); try { final OXContextInterface oxctx = (OXContextInterface) Naming.lookup(RMI_HOSTNAME +OXContextInterface.RMI_NAME); Context created = oxctx.create(ctx, user, accessCombinationName, auth); System.out.println("Context " + created.getId() + " successfully created."); } catch (RemoteException e) { e.printStackTrace(); } catch (StorageException e) { e.printStackTrace(); } catch (InvalidCredentialsException e) { e.printStackTrace(); } catch (InvalidDataException e) { e.printStackTrace(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (NotBoundException e) { e.printStackTrace(); } catch (ContextExistsException e) { e.printStackTrace(); } } }