1 55 56 package org.jboss.axis.transport.http; 57 58 import org.jboss.axis.server.AxisServer; 59 import org.jboss.axis.session.Session; 60 import org.jboss.axis.session.SimpleSession; 61 import org.jboss.axis.utils.Messages; 62 import org.jboss.axis.utils.Options; 63 import org.jboss.logging.Logger; 64 65 import java.net.MalformedURLException ; 66 import java.net.ServerSocket ; 67 import java.net.Socket ; 68 import java.util.Hashtable ; 69 70 79 public class SimpleAxisServer implements Runnable 80 { 81 private static Logger log = Logger.getLogger(SimpleAxisServer.class.getName()); 82 83 private Hashtable sessions = new Hashtable (); 93 94 private static boolean doThreads = true; 96 97 private static boolean doSessions = true; 100 101 protected boolean isSessionUsed() 102 { 103 return doSessions; 104 } 105 106 public void setDoThreads(boolean value) 107 { 108 doThreads = value; 109 } 110 111 public boolean getDoThreads() 112 { 113 return doThreads; 114 } 115 116 protected Session createSession(String cooky) 117 { 118 Session session = null; 120 if (sessions.containsKey(cooky)) 121 { 122 session = (Session)sessions.get(cooky); 123 } 124 else 125 { 126 session = new SimpleSession(); 128 129 sessions.put(cooky, session); 131 } 132 return session; 133 } 134 135 public static int sessionIndex = 0; 139 140 private static AxisServer myAxisServer = null; 142 143 protected static synchronized AxisServer getAxisServer() 144 { 145 if (myAxisServer == null) 146 { 147 myAxisServer = new AxisServer(); 148 } 149 return myAxisServer; 150 } 151 152 private boolean stopped = false; 155 156 160 public void run() 161 { 162 log.info(Messages.getMessage("start00", "SimpleAxisServer", 163 new Integer (getServerSocket().getLocalPort()).toString())); 164 165 while (!stopped) 167 { 168 Socket socket = null; 169 try 170 { 171 socket = serverSocket.accept(); 172 } 173 catch (java.io.InterruptedIOException iie) 174 { 175 } 176 catch (Exception e) 177 { 178 log.debug(Messages.getMessage("exception00"), e); 179 break; 180 } 181 if (socket != null) 182 { 183 SimpleAxisWorker worker = new SimpleAxisWorker(this, socket); 184 if (doThreads) 185 { 186 Thread thread = new Thread (worker); 187 thread.setDaemon(true); 188 thread.start(); 189 } 190 else 191 { 192 worker.run(); 193 } 194 } 195 } 196 log.info(Messages.getMessage("quit00", "SimpleAxisServer")); 197 } 198 199 private ServerSocket serverSocket; 201 202 205 public ServerSocket getServerSocket() 206 { 207 return serverSocket; 208 } 209 210 215 public void setServerSocket(ServerSocket serverSocket) 216 { 217 this.serverSocket = serverSocket; 218 } 219 220 227 public void start(boolean daemon) throws Exception 228 { 229 if (doThreads) 230 { 231 Thread thread = new Thread (this); 232 thread.setDaemon(daemon); 233 thread.start(); 234 } 235 else 236 { 237 run(); 238 } 239 } 240 241 244 public void start() throws Exception 245 { 246 start(false); 247 } 248 249 254 public void stop() throws Exception 255 { 256 260 stopped = true; 261 try 262 { 263 serverSocket.close(); 264 } 265 catch (Exception e) 266 { 267 log.info(Messages.getMessage("exception00"), e); 268 } 269 270 log.info(Messages.getMessage("quit00", "SimpleAxisServer")); 271 272 System.exit(0); 274 } 275 276 279 public static void main(String args[]) 280 { 281 282 SimpleAxisServer sas = new SimpleAxisServer(); 283 284 Options opts = null; 285 try 286 { 287 opts = new Options(args); 288 } 289 catch (MalformedURLException e) 290 { 291 log.error(Messages.getMessage("malformedURLException00"), e); 292 return; 293 } 294 295 try 296 { 297 doThreads = (opts.isFlagSet('t') > 0); 298 299 int port = opts.getPort(); 300 ServerSocket ss = null; 301 for (int i = 0; i < 5; i++) 303 { 304 try 305 { 306 ss = new ServerSocket (port); 307 break; 308 } 309 catch (java.net.BindException be) 310 { 311 log.debug(Messages.getMessage("exception00"), be); 312 if (i < 4) 313 { 314 Thread.sleep(3000); 316 } 317 else 318 { 319 throw new Exception (Messages.getMessage("unableToStartServer00", 320 Integer.toString(port))); 321 } 322 } 323 } 324 sas.setServerSocket(ss); 325 sas.start(); 326 } 327 catch (Exception e) 328 { 329 log.error(Messages.getMessage("exception00"), e); 330 return; 331 } 332 333 } 334 } 335 | Popular Tags |