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 socks = PropertiesManager.getManager().getProperty("org.openmobileis.synchro.socks.address");
00045
00046 if (socks != null) {
00047 String sport = PropertiesManager.getManager().getProperty("org.openmobileis.synchro.socks.port");
00048 if (sport != null) {
00049 int socksport = Integer.parseInt(sport);
00050 HTTPConnection.setSocksServer(socks, socksport);
00051 String login = PropertiesManager.getManager().getProperty("org.openmobileis.synchro.socks.login");
00052 String pass = PropertiesManager.getManager().getProperty("org.openmobileis.synchro.socks.pass");
00053 String realm = PropertiesManager.getManager().getProperty("org.openmobileis.synchro.socks.realm");
00054 if (login != null && pass != null && realm!=null) {
00055 AuthorizationInfo.addBasicAuthorization(socks, socksport, realm, login, pass);
00056 }
00057 }
00058 }
00059 String proxy = PropertiesManager.getManager().getProperty("org.openmobileis.synchro.proxy.address");
00060
00061 if (proxy != null) {
00062 String pport = PropertiesManager.getManager().getProperty("org.openmobileis.synchro.proxy.port");
00063 if (pport != null) {
00064 int proxyport = Integer.parseInt(pport);
00065 HTTPConnection.setProxyServer(proxy, proxyport);
00066 String login = PropertiesManager.getManager().getProperty("org.openmobileis.synchro.proxy.login");
00067 String pass = PropertiesManager.getManager().getProperty("org.openmobileis.synchro.proxy.pass");
00068 String realm = PropertiesManager.getManager().getProperty("org.openmobileis.synchro.proxy.realm");
00069 if (login != null && pass != null && realm!=null) {
00070 AuthorizationInfo.addBasicAuthorization(proxy, proxyport, realm, login, pass);
00071 }
00072 }
00073 }
00074 con = new HTTPConnection(url, port);
00075
00076
00077 CookieModule.setCookiePolicyHandler(null);
00078 NVPair headerData[] = new NVPair[1];
00079 headerData[0] = new NVPair("User-Agent", userAgent);
00080 con.setDefaultHeaders(headerData);
00081 return con;
00082 }
00083
00084 public static String getDefaultUserAgent () {
00085 String usera = PropertiesManager.getManager().getProperty("org.openmobileis.synchro.direct.useragent");
00086 if (usera == null) {
00087 Plateform plateform = ApplicationContextManager.getManager().getApplicationContext().getPlateform();
00088 StringBuffer useragent = new StringBuffer("OpenMSPPlug-");
00089 useragent.append(plateform.getOpenMobileISMajorVersion()).append('.').append(plateform.getOpenMobileISMinorVersion()).append('-');
00090 useragent.append(plateform.getOS()).append('[').append(plateform.getOSVersion()).append("]-");
00091 String language = IntlResourceManager.getManager().getManagerLocaleString();
00092 useragent.append(language);
00093 usera = useragent.toString();
00094 }
00095 return usera;
00096 }
00097
00098 }