1 22 package org.jboss.web; 23 24 import java.io.IOException ; 25 import java.net.InetAddress ; 26 import java.net.URL ; 27 import java.net.UnknownHostException ; 28 import java.util.Enumeration ; 29 import java.util.Properties ; 30 31 import javax.management.MBeanServer ; 32 import javax.management.ObjectName ; 33 34 import org.jboss.system.MissingAttributeException; 35 import org.jboss.system.ServiceMBeanSupport; 36 import org.jboss.system.server.ServerConfigUtil; 37 import org.jboss.util.ThrowableHandler; 38 import org.jboss.util.threadpool.BasicThreadPoolMBean; 39 40 53 public class WebService extends ServiceMBeanSupport implements WebServiceMBean 54 { 55 66 73 private WebServer server = new WebServer(); 74 75 78 public WebService() 79 { 80 super(); 81 } 82 83 86 public URL addClassLoader(ClassLoader cl) 87 { 88 return server.addClassLoader(cl); 89 } 90 91 94 public void removeClassLoader(ClassLoader cl) 95 { 96 server.removeClassLoader(cl); 97 } 98 99 106 public void setPort(int port) 107 { 108 server.setPort(port); 109 } 110 111 116 public int getPort() 117 { 118 return server.getPort(); 119 } 120 121 127 public void setHost(final String hostname) 128 { 129 server.setBindAddress(hostname); 130 } 131 132 138 public String getHost() 139 { 140 return server.getBindHostname(); 141 } 142 143 150 public String getBindAddress() 151 { 152 return server.getBindAddress(); 153 } 154 155 165 public void setBindAddress(String host) throws UnknownHostException 166 { 167 server.setBindAddress(host); 168 } 169 170 180 public int getBacklog() 181 { 182 return server.getBacklog(); 183 } 184 185 195 public void setBacklog(int backlog) 196 { 197 server.setBacklog(backlog); 198 } 199 200 204 public void setThreadPool(BasicThreadPoolMBean threadPool) 205 { 206 server.setThreadPool(threadPool); 207 } 208 209 216 public boolean getDownloadServerClasses() 217 { 218 return server.getDownloadServerClasses(); 219 } 220 221 224 public void setDownloadServerClasses(boolean flag) 225 { 226 server.setDownloadServerClasses(flag); 227 } 228 229 235 public boolean getDownloadResources() 236 { 237 return server.getDownloadResources(); 238 } 239 240 243 public void setDownloadResources(boolean flag) 244 { 245 server.setDownloadResources(flag); 246 } 247 248 protected ObjectName getObjectName(MBeanServer server, ObjectName name) 249 throws javax.management.MalformedObjectNameException 250 { 251 return name == null ? OBJECT_NAME : name; 252 } 253 254 protected void createService() throws Exception 255 { 256 Properties mimeTypes = new Properties (); 258 259 try 260 { 261 mimeTypes.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("org/jboss/web/mime.types")); 262 263 Enumeration keys = mimeTypes.keys(); 264 while (keys.hasMoreElements()) 265 { 266 String extension = (String ) keys.nextElement(); 267 String type = mimeTypes.getProperty(extension); 268 server.addMimeType(extension, type); 269 } 270 } 271 catch (Exception e) 272 { 273 log.error("Failed to load org/jboss/web/mime.types; ignoring", e); 274 } 275 276 String hostname = server.getBindAddress(); 277 278 if (hostname == null) 280 { 281 try 283 { 284 hostname = System.getProperty("java.rmi.server.hostname"); 285 } 286 catch (SecurityException e) 287 { 288 ThrowableHandler.addWarning(e); 290 } 291 292 if (hostname == null) 294 { 295 try 296 { 297 hostname = InetAddress.getLocalHost().getHostName(); 298 } 299 catch (IOException e) 300 { 301 log.error("Failed to get localhost name; ignoring", e); 302 } 303 } 304 305 if (hostname != null) 306 { 307 setHost(hostname); 308 } 309 } 310 String address = getHost(); 312 if (address == null) 313 throw new MissingAttributeException("Host"); 314 315 String codebase = System.getProperty("java.rmi.server.codebase"); 317 if (codebase == null) 318 { 319 address = ServerConfigUtil.fixRemoteAddress(address); 320 321 codebase = "http://" + address + ":" + getPort() + "/"; 322 System.setProperty("java.rmi.server.codebase", codebase); 323 } 324 log.info("Using RMI server codebase: " + codebase); 325 } 326 327 334 protected void startService() throws Exception 335 { 336 server.start(); 338 log.debug("Started WebServer with address: " + server.getBindAddress() + ":" + getPort()); 339 } 340 341 protected void stopService() throws Exception 342 { 343 server.stop(); 344 } 345 } 346 | Popular Tags |