1 22 package org.jboss.mq.il.http; 23 24 import java.net.InetAddress ; 25 import java.util.Properties ; 26 27 import org.jboss.mq.il.ServerIL; 28 import org.jboss.mq.il.ServerILJMXService; 29 import org.jboss.system.server.ServerConfigUtil; 30 31 39 public class HTTPServerILService extends ServerILJMXService implements HTTPServerILServiceMBean 40 { 41 42 private HTTPServerIL serverIL; 43 private String url = null; 44 private String urlPrefix = "http://"; 45 private int urlPort = 8080; 46 private String urlSuffix = "jbossmq-httpil/HTTPServerILServlet"; 47 private String urlHostName = null; 48 private boolean useHostName = false; 49 private long timeout = 60 * 1000; 50 private long restInterval = 0; 51 52 public HTTPServerILService() 53 { 54 } 55 56 public String getName() 57 { 58 return "JBossMQ-HTTPServerIL"; 59 } 60 61 public ServerIL getServerIL() 62 { 63 return this.serverIL; 64 } 65 66 public Properties getClientConnectionProperties() 67 { 68 Properties properties = super.getClientConnectionProperties(); 69 properties.setProperty(HTTPServerILFactory.CLIENT_IL_SERVICE_KEY, HTTPServerILFactory.CLIENT_IL_SERVICE); 70 properties.setProperty(HTTPServerILFactory.SERVER_URL_KEY, this.url); 71 properties.setProperty(HTTPServerILFactory.TIMEOUT_KEY, String.valueOf(this.timeout)); 72 properties.setProperty(HTTPServerILFactory.REST_INTERVAL_KEY, String.valueOf(this.restInterval)); 73 return properties; 74 } 75 76 public void startService() throws Exception 77 { 78 super.startService(); 79 if (this.url == null) 80 { 81 this.url = this.getConstructedURL(); 82 } 83 this.serverIL = new HTTPServerIL(this.url); 84 super.bindJNDIReferences(); 85 } 86 87 public void stopService() 88 { 89 try 90 { 91 unbindJNDIReferences(); 92 } 93 catch (Exception e) 94 { 95 e.printStackTrace(); 96 } 97 } 98 99 107 public void setTimeOut(int timeout) 108 { 109 this.timeout = timeout * 1000; } 111 112 117 public int getTimeOut() 118 { 119 return (int) this.timeout / 1000; } 121 122 136 public void setRestInterval(int restInterval) 137 { 138 this.restInterval = restInterval * 1000; } 140 141 146 public int getRestInterval() 147 { 148 return (int) this.restInterval / 1000; } 150 151 159 public void setURL(String url) 160 { 161 this.url = url; 162 this.urlPrefix = null; 168 this.urlHostName = null; 169 this.urlPort = 0; 170 this.urlSuffix = null; 171 this.useHostName = false; 172 } 173 174 182 public String getURL() 183 { 184 return this.url; 185 } 186 187 193 public void setURLPrefix(String prefix) 194 { 195 this.urlPrefix = prefix; 196 } 197 198 204 public String getURLPrefix() 205 { 206 return this.urlPrefix; 207 } 208 209 214 public void setURLHostName(String hostname) 215 { 216 this.urlHostName = hostname; 217 } 218 219 224 public String getURLHostName() 225 { 226 return this.urlHostName; 227 } 228 229 235 public void setURLPort(int port) 236 { 237 this.urlPort = port; 238 } 239 240 246 public int getURLPort() 247 { 248 return this.urlPort; 249 } 250 251 257 public void setURLSuffix(String suffix) 258 { 259 this.urlSuffix = suffix; 260 } 261 262 268 public String getURLSuffix() 269 { 270 return this.urlSuffix; 271 } 272 273 274 281 public void setUseHostName(boolean value) 282 { 283 this.useHostName = value; 284 } 285 286 293 public boolean getUseHostName() 294 { 295 return this.useHostName; 296 } 297 298 299 305 private String getConstructedURL() throws Exception 306 { 307 if (System.getProperty(HTTPServerILFactory.SERVER_URL_KEY) != null) 308 { 309 return System.getProperty(HTTPServerILFactory.SERVER_URL_KEY); 310 } 311 else 312 { 313 String hostName = this.urlHostName; 314 if (hostName == null) 315 { 316 hostName = ServerConfigUtil.getSpecificBindAddress(); 318 } 319 if (hostName == null) 320 { 321 if (this.useHostName) 323 { 324 hostName = InetAddress.getLocalHost().getHostName(); 325 } 326 else 327 { 328 hostName = InetAddress.getLocalHost().getHostAddress(); 329 } 330 } 331 return this.urlPrefix + hostName + ":" + String.valueOf(this.urlPort) 332 + "/" + this.urlSuffix; 333 } 334 } 335 } 336 337
| Popular Tags
|