00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 package org.openmobileis.synchro.openmsp.client.services;
00026
00027 import java.io.IOException;
00028
00029 import javax.servlet.ServletException;
00030 import javax.servlet.http.HttpServletRequest;
00031 import javax.servlet.http.HttpServletResponse;
00032
00033 import org.openmobileis.common.intl.IntlResourceManager;
00034 import org.openmobileis.common.util.PropertiesManager;
00035 import org.openmobileis.common.util.log.LogManager;
00036 import org.openmobileis.services.TemplateService;
00037 import org.openmobileis.services.common.ServiceManager;
00038 import org.openmobileis.services.common.ServletTools;
00039 import org.openmobileis.services.navigation.NavigationBarService;
00040 import org.openmobileis.services.security.SessionLoginManager;
00041 import org.openmobileis.synchro.client.SynchroDescriptor;
00042 import org.openmobileis.synchro.client.SynchroManager;
00043 import org.openmobileis.synchro.openmsp.client.OpenMSPSynchroManager;
00044 import org.openmobileis.synchro.openmsp.client.conduit.ApacheHTTPClientSynchroConduit;
00045 import org.openmobileis.synchro.openmsp.client.conduit.SynchroConduit;
00046 import org.openmobileis.synchro.openmsp.protocol.Status;
00047 import org.openmobileis.synchro.security.auth.Credential;
00048
00049 import freemarker.template.TemplateModelRoot;
00050
00058 public class DirectSynchroService extends TemplateService implements NavigationBarService {
00059 private static final String templatePath = "openmischannel" + java.io.File.separator + "synchroresult.htm";
00060 private boolean synchroPending = false;
00061
00065 public DirectSynchroService() {
00066 super();
00067
00068 }
00069
00070
00071
00072
00073 public String runTemplate(HttpServletRequest req, HttpServletResponse res, TemplateModelRoot templateData) throws ServletException, IOException {
00074 String login = req.getParameter("login");
00075 String pwd = req.getParameter("pwd");
00076 String showres = req.getParameter("showres");
00077 try {
00078
00079 this.preProcessSynchronisation(req, res, templateData);
00080
00081 String synchroInstallPath = PropertiesManager.getManager().getProperty("org.openmobileis.synchro.direct.installpath");
00082 if (synchroInstallPath == null) {
00083 String propFilePath = PropertiesManager.getManager().getProperty("org.openmobileis.synchro.properties.file.path");
00084 PropertiesManager.getManager().addPropertiesFileFromFilePath(propFilePath);
00085 synchroInstallPath = PropertiesManager.getManager().getProperty("org.openmobileis.synchro.direct.installpath");
00086 }
00087 SynchroDescriptor descriptor = new SynchroDescriptor();
00088 descriptor.addProperty("OpenMSPsynchrotype", "DR");
00089 String useragent = OpenMSPSynchroManager.getManager().getSynchroUserAgent(descriptor);
00090 String conduitClass = PropertiesManager.getManager().getProperty("org.openmobileis.synchro.direct.conduit.class");
00091 if (conduitClass != null) {
00092 SynchroConduit conduit = (SynchroConduit) Class.forName(conduitClass).newInstance();
00093 ;
00094 conduit.setSynchroPath(synchroInstallPath);
00095 conduit.setSynchroUserAgent(useragent);
00096 descriptor.setSynchroConduit(conduit);
00097 } else {
00098 ApacheHTTPClientSynchroConduit conduit = new ApacheHTTPClientSynchroConduit();
00099 conduit.setSynchroPath(synchroInstallPath);
00100 conduit.setSynchroUserAgent(useragent);
00101 descriptor.setSynchroConduit(conduit);
00102 }
00103
00104 String group = PropertiesManager.getManager().getProperty("org.openmobileis.synchro.direct.group");
00105 descriptor.setSynchroGroup(group);
00106 String url = PropertiesManager.getManager().getProperty("org.openmobileis.synchro.direct.targeturl");
00107 descriptor.setServerURL(url);
00108
00109 if (showres != null) {
00110
00111 return this.showResultMessage(req, res, templateData);
00112 }
00113
00114 if ((login == null) || (pwd == null)) {
00115
00116 return null;
00117 }
00118 if (!synchroPending) {
00119 synchronized (this) {
00120 synchroPending = true;
00121 }
00122 try {
00123 Credential cred = new Credential(login, pwd);
00124 SynchroManager.getManager().doSynchro(cred, descriptor);
00125 if (OpenMSPSynchroManager.getManager().getGlobalSynchroStatut() == Status.STATUS_OK) {
00126 SessionLoginManager.getManager().changeSessionPass(pwd);
00127 }
00128 this.postProcessSynchronisation(req, res, templateData);
00129 return this.showResultMessage(req, res, templateData);
00130 } catch (Throwable e) {
00131 LogManager.traceError(0, e);
00132 } finally {
00133 synchronized (this) {
00134 synchroPending = false;
00135 }
00136 }
00137 }
00138
00139 } catch (Throwable ex) {
00140 LogManager.traceError(0, "Error during init of DirectSynchroService. No direct synchro available");
00141 LogManager.traceError(0, ex);
00142 }
00143
00144 return this.showResultMessage(req, res, templateData);
00145 }
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157 public String showResultMessage(HttpServletRequest req, HttpServletResponse res, TemplateModelRoot templateData) throws ServletException, IOException {
00158 SynchroJournalDisplayService journalservice = new SynchroJournalDisplayService();
00159 journalservice.runTemplate(req, res, templateData);
00160 return DirectSynchroService.templatePath;
00161 }
00162
00163 public void preProcessSynchronisation(HttpServletRequest req, HttpServletResponse res, TemplateModelRoot templateData) {
00164
00165 }
00166
00167 public void postProcessSynchronisation(HttpServletRequest req, HttpServletResponse res, TemplateModelRoot templateData) {
00168
00169 }
00170
00171 public String getNavigationBarLabel(HttpServletRequest req) {
00172 return "Synchronisation";
00173 }
00174
00175 public boolean displayFormExitMessage() {
00176 return false;
00177 }
00178
00179 public boolean displayRecursive() {
00180 return false;
00181 }
00182
00183 public String getServiceUri() {
00184 return ServiceManager.getManager().getServiceBaseURI() + "/synchro/direct";
00185 }
00186
00187 }