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.conduit;
00026
00027 import org.openmobileis.common.context.ApplicationContextManager;
00028 import org.openmobileis.common.context.Plateform;
00029 import org.openmobileis.common.intl.IntlResourceManager;
00030 import org.openmobileis.common.util.PropertiesManager;
00031
00032 import HTTPClient.AuthorizationInfo;
00033 import HTTPClient.CookieModule;
00034 import HTTPClient.HTTPConnection;
00035 import HTTPClient.NVPair;
00036
00041 public final class HTTPConnectionFactory {
00042 public static HTTPConnection createConnection(String url, int port, String userAgent) {
00043 HTTPConnection con = null;
00044 String proxy = PropertiesManager.getManager().getProperty("org.openmobileis.synchro.proxy.address");
00045
00046 if (proxy != null) {
00047 String pport = PropertiesManager.getManager().getProperty("org.openmobileis.synchro.proxy.port");
00048 if (pport != null) {
00049 int proxyport = Integer.parseInt(pport);
00050 HTTPConnection.setProxyServer(proxy, proxyport);
00051 String login = PropertiesManager.getManager().getProperty("org.openmobileis.synchro.proxy.login");
00052 String pass = PropertiesManager.getManager().getProperty("org.openmobileis.synchro.proxy.pass");
00053 String realm = PropertiesManager.getManager().getProperty("org.openmobileis.synchro.proxy.realm");
00054 if (login != null && pass != null && realm!=null) {
00055 AuthorizationInfo.addBasicAuthorization(proxy, proxyport, realm, login, pass);
00056 }
00057 }
00058 }
00059 con = new HTTPConnection(url, port);
00060
00061
00062 CookieModule.setCookiePolicyHandler(null);
00063 NVPair headerData[] = new NVPair[1];
00064 headerData[0] = new NVPair("User-Agent", userAgent);
00065 con.setDefaultHeaders(headerData);
00066 return con;
00067 }
00068
00069 public static String getDefaultUserAgent () {
00070 String usera = PropertiesManager.getManager().getProperty("org.openmobileis.synchro.direct.useragent");
00071 if (usera == null) {
00072 Plateform plateform = ApplicationContextManager.getManager().getApplicationContext().getPlateform();
00073 StringBuffer useragent = new StringBuffer("OpenMSPPlug-");
00074 useragent.append(plateform.getOpenMobileISMajorVersion()).append('.').append(plateform.getOpenMobileISMinorVersion()).append('-');
00075 useragent.append(plateform.getOS()).append('[').append(plateform.getOSVersion()).append("]-");
00076 String language = IntlResourceManager.getManager().getManagerLocaleString();
00077 useragent.append(language);
00078 usera = useragent.toString();
00079 }
00080 return usera;
00081 }
00082
00083 }