TestOpenMSPSynchro.java

00001 /*
00002  * OpenMobileIS - a free Java(TM) Framework for mobile applications Java(TM)
00003  * Copyright (C) 2004-2006 Philippe Delrieu
00004  * All rights reserved.
00005  * Contact: pdelrieu@openmobileis.org
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with this library; if not, write to the Free Software
00019  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00020  * USA
00021  *
00022  *  Author : Philippe Delrieu
00023  * 
00024  */
00025 package org.openmobileis.synchro.openmsp.protocol.test;
00026 
00027 import java.util.Properties;
00028 
00029 import org.openmobileis.common.user.UserManager;
00030 import org.openmobileis.common.user.impl.MonoUserUserManagerFactory;
00031 import org.openmobileis.common.user.profile.ProfileDataManager;
00032 import org.openmobileis.common.user.profile.impl.XmlFileProfilDataFactory;
00033 import org.openmobileis.common.util.PropertiesManager;
00034 import org.openmobileis.common.util.log.LogManager;
00035 import org.openmobileis.embedded.webserver.WebServer;
00036 import org.openmobileis.synchro.client.SynchroDescriptor;
00037 import org.openmobileis.synchro.client.SynchroManager;
00038 import org.openmobileis.synchro.openmsp.client.OpenMSPSynchroManager;
00039 import org.openmobileis.synchro.openmsp.client.conduit.ApacheHTTPClientSynchroConduit;
00040 import org.openmobileis.synchro.openmsp.server.synctarget.SynchroTargerManager;
00041 import org.openmobileis.synchro.openmsp.server.synctarget.proxy.GenericProxySynchroTarget;
00042 import org.openmobileis.synchro.security.auth.Credential;
00043 
00051 public final class TestOpenMSPSynchro {
00052 
00056   public TestOpenMSPSynchro() {
00057     super();
00058   }
00059 
00063   public static void main(String[] args) {
00064     //init 
00065     LogManager.registerLogManager(null);
00066     //init Terminal side.
00067     //load synchro properties
00068     try {
00069         
00070             //init dummy db
00071       PropertiesManager.getManager().addPropertiesFile(System.getProperty("user.dir")+"/WEB-INF/conf/properties/dummy.properties");
00072       
00073       PropertiesManager.getManager().addProperty("org.openmobileis.synchro.client.openmsp.numsyncpropsfile",System.getProperty("user.dir") + "/WEB-INF/conf/numsync.txt");
00074       OpenMSPSynchroManager.getManager().addListener(new TestOpenMSSyncListener(), null);
00075       SynchroManager.getManager().registerSynchroProcessor(OpenMSPSynchroManager.getManager());
00076   
00077       //init Synchro Server side.
00078       PropertiesManager.getManager().addProperty("org.openmobileis.common.user.profil.xmlprofilfile.path",System.getProperty("user.dir") + "/WEB-INF/conf/defaultprofils.xml");
00079       SynchroTargerManager.getManager().addSynchroTargetListener(new TestOpenMSPSynchroTargetListener(), null, null);
00080       UserManager.getManager().registerUserManagerFactoryForGroup("default", new MonoUserUserManagerFactory());
00081       ProfileDataManager.getManager().registerProfilDataFactoryForGroup("default", new XmlFileProfilDataFactory());
00082       SynchroTargerManager.getManager().addSynchroTargetListener(new TestOpenMSPSynchroTargetListener(), null, null);
00083       SynchroTargerManager.getManager().registerProxyTargetForTerminal(new GenericProxySynchroTarget(), null);
00084       
00085       //start server
00086       Runnable startWebServer = new Runnable() {
00087   
00088         public void run() {
00089           try {
00090   
00091             System.out.println("start WebServer");
00092   
00093             Properties props = new Properties();
00094             props.put("LOGFILE", System.getProperty("user.dir") + "/WEB-INF/log/server/log");
00095             LogManager.registerLogManager(props); //log to a file
00096   
00097             WebServer server = null;
00098             server = new WebServer();
00099   
00100             server.serve();
00101           } catch (Throwable ex) {
00102             ex.printStackTrace();
00103           }
00104         }
00105   
00106       };
00107       Thread th = new Thread(startWebServer);
00108       th.start();
00109       //do synchro
00110       //wait 1 second until the webserver is started.
00111       Thread.currentThread().sleep(1000);
00112       Credential cred = new Credential("test", "test");
00113       SynchroDescriptor descriptor = new SynchroDescriptor();
00114       ApacheHTTPClientSynchroConduit conduit = new ApacheHTTPClientSynchroConduit();
00115         conduit.setSynchroPath(System.getProperty("user.dir") + "/synchro");
00116         conduit.setSynchroUserAgent("OpenMSPPlug-WI-V[1.0]-WINCE[DR-FR-WINCE/04-02-00-00]");
00117       descriptor.setSynchroConduit(conduit);
00118       descriptor.setSynchroGroup("default");
00119       descriptor.setServerURL("http://localhost:9091/services/openmspservice");
00120       
00121       SynchroManager.getManager().doSynchro(cred, descriptor);
00122       
00123     } catch (Throwable ex)  {
00124       LogManager.traceError(0, ex);
00125     }
00126   }
00127 
00128 }

Generated on Mon Jan 14 17:29:50 2008 for OpenMobileIS by  doxygen 1.5.4