KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > agent > client > launcher > AgentLauncherApplicationLauncher


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

19             
20 package com.sslexplorer.agent.client.launcher;
21
22 import java.io.File JavaDoc;
23 import java.io.IOException JavaDoc;
24 import java.io.InputStream JavaDoc;
25 import java.lang.reflect.Method JavaDoc;
26 import java.net.URL JavaDoc;
27 import java.net.URLConnection JavaDoc;
28 import java.net.URLEncoder JavaDoc;
29 import java.text.MessageFormat JavaDoc;
30 import java.util.Enumeration JavaDoc;
31 import java.util.Hashtable JavaDoc;
32
33 import com.sslexplorer.agent.client.util.AbstractApplicationLauncher;
34 import com.sslexplorer.agent.client.util.ApplicationLauncherEvents;
35
36 public class AgentLauncherApplicationLauncher extends AbstractApplicationLauncher {
37
38
39     /**
40      * Constructor.
41      *
42      * @param cacheDir cache directory
43      * @param applicationStoreProtocol
44      * @param applicationStoreUser
45      * @param applicationStoreHost
46      * @param applicationStorePort
47      * @param parameters
48      * @param events
49      */

50     public AgentLauncherApplicationLauncher(File JavaDoc cacheDir, String JavaDoc applicationStoreProtocol, String JavaDoc applicationStoreUser, String JavaDoc applicationStoreHost, int applicationStorePort, Hashtable JavaDoc parameters, ApplicationLauncherEvents events) {
51         super(cacheDir, applicationStoreProtocol, applicationStoreUser, applicationStoreHost, applicationStorePort, parameters, events);
52     }
53
54     /**
55      * Download the application descriptor. This should not be called directory,
56      * it gets called during {@link #prepare()}.
57      *
58      * @return application descriptor stream
59      * @throws IOException
60      */

61     protected InputStream JavaDoc getApplicationDescriptor() throws IOException JavaDoc {
62         StringBuffer JavaDoc parms = new StringBuffer JavaDoc();
63         Enumeration JavaDoc en = parameters.keys();
64         while(en.hasMoreElements()) {
65             if(parms.length() == 0) {
66                 parms.append("?"); //$NON-NLS-1$
67
}
68             else {
69                 parms.append("&"); //$NON-NLS-1$
70
}
71             String JavaDoc key = (String JavaDoc) en.nextElement();
72             parms.append(key);
73             parms.append("="); //$NON-NLS-1$
74
parms.append(URLEncoder.encode((String JavaDoc) parameters.get(key)));
75         }
76         
77          URL JavaDoc file = new URL JavaDoc(applicationStoreProtocol, applicationStoreHost, applicationStorePort, "/getExtensionDescriptor.do" //$NON-NLS-1$
78
+ parms);
79          if (events != null)
80              events.debug(MessageFormat.format(Messages.getString("VPNLauncher.requestApplicationUsing"), new Object JavaDoc[] { file.toExternalForm() })); //$NON-NLS-1$
81

82          URLConnection JavaDoc con = (URLConnection JavaDoc)file.openConnection();
83          con.setUseCaches(false);
84
85          try {
86              Method JavaDoc m = con.getClass().getMethod("setConnectTimeout", new Class JavaDoc[] { int.class }); //$NON-NLS-1$
87
if (events != null) {
88                  events.debug(Messages.getString("VPNLauncher.runtime5")); //$NON-NLS-1$
89
}
90              m.invoke(con, new Object JavaDoc[] { new Integer JavaDoc(20000) });
91              m = con.getClass().getMethod("setReadTimeout", new Class JavaDoc[] { int.class }); //$NON-NLS-1$
92
m.invoke(con, new Object JavaDoc[] { new Integer JavaDoc(20000) });
93          } catch (Throwable JavaDoc t) {
94          }
95          return con.getInputStream();
96     }
97 }
98
Popular Tags