HTTPConnectionFactory.java

00001 /*
00002  * OpenMobileIS - a free Java(TM) Framework for mobile applications Java(TM)
00003  * Copyright (C) 2004-2007 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.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                 //                      LogManager.traceDebug(0, "proxy :"+proxy);
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                 //manage proxy server
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 }

Generated on Tue May 22 23:01:10 2007 for OpenMobileIS by  doxygen 1.5.1-p1