1 19 20 23 24 package org.netbeans.modules.j2ee.sun.ws7.j2ee; 25 26 import javax.enterprise.deploy.spi.DeploymentManager ; 27 import javax.enterprise.deploy.spi.Target ; 28 import javax.enterprise.deploy.spi.status.ProgressObject ; 29 30 import org.netbeans.modules.j2ee.deployment.plugins.api.ServerDebugInfo; 31 import org.netbeans.modules.j2ee.deployment.plugins.api.StartServer; 32 import org.openide.ErrorManager; 33 import org.openide.util.NbBundle; 34 import org.netbeans.modules.j2ee.deployment.plugins.api.UISupport; 35 import javax.enterprise.deploy.spi.TargetModuleID ; 36 import javax.enterprise.deploy.spi.exceptions.OperationUnsupportedException ; 37 import javax.enterprise.deploy.spi.exceptions.TargetException ; 38 import javax.enterprise.deploy.spi.status.ClientConfiguration ; 39 import javax.enterprise.deploy.spi.status.DeploymentStatus ; 40 import javax.enterprise.deploy.spi.status.ProgressListener ; 41 import javax.enterprise.deploy.spi.status.ProgressObject ; 42 43 import javax.enterprise.deploy.shared.ActionType ; 44 import javax.enterprise.deploy.shared.CommandType ; 45 import javax.enterprise.deploy.shared.StateType ; 46 47 import org.netbeans.modules.j2ee.sun.ws7.dm.WS70SunDeploymentManager; 48 import org.netbeans.modules.j2ee.sun.ws7.util.ProgressEventSupport; 49 import org.netbeans.modules.j2ee.sun.ws7.util.Status; 50 import org.netbeans.modules.j2ee.sun.ws7.Constants; 51 import org.openide.util.RequestProcessor; 52 53 import java.io.File ; 54 import java.util.Map ; 55 import java.util.HashMap ; 56 import java.util.Collections ; 57 60 public class WS70StartServer extends StartServer implements ProgressObject , Runnable { 61 62 private WS70SunDeploymentManager dm; 63 private ProgressEventSupport pes; 64 private WS70CommandType cmdType; 65 private Target target; 66 private static Map isDebugModeConfig = Collections.synchronizedMap((Map )new HashMap (2,1)); 67 68 public WS70StartServer(DeploymentManager dm) { 69 this.dm = (WS70SunDeploymentManager)dm; 70 pes = new ProgressEventSupport(this); 71 72 } 73 74 75 81 public boolean isAlsoTargetServer(Target target) { 82 return false; 83 } 84 85 86 89 public boolean supportsStartDeploymentManager() { 90 if(dm.isLocalServer()){ 91 return true; 92 } 93 return false; 94 } 95 96 97 103 public ProgressObject startDeploymentManager() { 104 if(dm.isLocalServer()){ 105 cmdType = WS70CommandType.START; 106 pes.fireHandleProgressEvent(null, 107 new Status (ActionType.EXECUTE, CommandType.START, 108 NbBundle.getMessage(WS70StartServer.class, "MSG_STARTING_ADMIN_SERVER"), 109 StateType.RUNNING)); 110 111 RequestProcessor.getDefault().post(this, 0, Thread.NORM_PRIORITY); 112 return this; 113 }else{ 114 return null; 115 } 116 } 117 118 119 125 public ProgressObject stopDeploymentManager() { 126 if(dm.isLocalServer()){ 127 cmdType = WS70CommandType.STOP; 128 pes.fireHandleProgressEvent(null, 129 new Status (ActionType.EXECUTE, CommandType.STOP, 130 NbBundle.getMessage(WS70StartServer.class, "MSG_STOPPING_ADMIN_SERVER"), 131 StateType.RUNNING)); 132 133 RequestProcessor.getDefault().post(this, 0, Thread.NORM_PRIORITY); 134 return this; 135 }else{ 136 return null; 137 } 138 139 } 140 141 142 145 public boolean needsStartForConfigure() { 146 return false; 147 } 148 149 153 public boolean needsStartForTargetList() { 154 return false; 155 } 156 157 158 161 public boolean needsStartForAdminConfig() { 162 return false; 163 } 164 165 166 169 public boolean isRunning() { 170 return ((WS70SunDeploymentManager)dm).isRunning(); 171 } 172 173 174 183 public boolean needsRestart() { 184 return false; 185 } 186 187 190 public boolean isDebuggable(Target t) { 191 if(t==null){ 192 return false; 193 } 194 String config = null; 195 try{ 196 config = this.getConfigNameFromTarget(t); 197 }catch(Exception ex){ 198 ex.printStackTrace(); 199 return false; 200 } 201 if(!isDebugModeConfig.containsKey(dm.getHost()+dm.getPort()+config)){ 202 return false; 203 } 204 205 if(!dm.isRunning(config)){ 206 isDebugModeConfig.remove(dm.getHost()+dm.getPort()+config); 207 return false; 208 } 209 return true; 210 } 211 212 213 220 public ProgressObject startDebugging(Target t) { 221 if(t!=null){ 222 this.target = t; 223 cmdType = WS70CommandType.STARTTARGETDEBUG; 224 pes.fireHandleProgressEvent(null, 225 new Status (ActionType.EXECUTE, CommandType.START, 226 NbBundle.getMessage(WS70StartServer.class, "MSG_STARTING_TARGET_SERVER_DEBUG"), 227 StateType.RUNNING)); 228 229 RequestProcessor.getDefault().post(this, 0, Thread.NORM_PRIORITY); 230 String config = null; 231 try{ 232 config = this.getConfigNameFromTarget(t); 233 }catch(Exception ex){ 234 ex.printStackTrace(); 235 } 236 isDebugModeConfig.put(dm.getHost()+dm.getPort()+config, new Object ()); 237 return this; 238 } 239 return null; 240 } 241 242 243 246 247 public ServerDebugInfo getDebugInfo(Target t) { 248 if(t==null){ 249 return null; 250 } 251 String uri = ((WS70SunDeploymentManager)dm).getUri(); 252 this.dm = org.netbeans.modules.j2ee.sun.ws7.dm.WS70SunDeploymentFactory.getConnectedCachedDeploymentManager(uri); 253 String debugOptions = this.dm.getDebugOptions(); 254 if(debugOptions==null){ 255 ErrorManager.getDefault().log( 256 ErrorManager.ERROR, NbBundle.getMessage(WS70StartServer.class, "ERR_DEBUG_OPTIONS_NULL")); 257 return null; 258 } 259 String nodeName = dm.getNodeNameForTarget(t); 260 String address = debugOptions.substring(debugOptions.indexOf(Constants.DEBUG_OPTIONS_ADDRESS)+Constants.DEBUG_OPTIONS_ADDRESS.length(), debugOptions.length()); 261 int hasMore = address.indexOf("]"); if(hasMore != -1){ 263 address = address.substring(0, hasMore); 264 } 265 if(debugOptions.indexOf(Constants.ISDTSOCKET)!=-1){ 266 int debugport = -1; 267 try{ 268 debugport = Integer.parseInt(address.trim()); 269 }catch(NumberFormatException ex){ 270 ErrorManager.getDefault().log( 271 ErrorManager.ERROR, NbBundle.getMessage(WS70StartServer.class, "ERR_DTSOCKET_PORT_INVALID")); 272 return null; 273 } 274 return new ServerDebugInfo(nodeName, debugport); 275 }else if(debugOptions.indexOf(Constants.ISSHMEM)!=-1){ 276 return new ServerDebugInfo(nodeName, address.trim()); 277 }else{ 278 ErrorManager.getDefault().log( 279 ErrorManager.ERROR, NbBundle.getMessage(WS70StartServer.class, "ERR_UNKNOW_DEBUG_OPTION")); 280 return null; 281 } 282 } 283 284 285 public boolean isRunning(Target t){ 286 if(t==null){ 287 return true; 288 } 289 String uri = ((WS70SunDeploymentManager)dm).getUri(); 290 this.dm = org.netbeans.modules.j2ee.sun.ws7.dm.WS70SunDeploymentFactory.getConnectedCachedDeploymentManager(uri); 291 try{ 292 String configName = this.getConfigNameFromTarget(t); 293 return ((WS70SunDeploymentManager)dm).isRunning(configName); 294 }catch(Exception ex){ 295 ex.printStackTrace(); 296 } 297 return true; 298 } 299 public ProgressObject startTarget(Target t){ 300 if(t!=null){ 301 this.target = t; 302 cmdType = WS70CommandType.STARTTARGET; 303 pes.fireHandleProgressEvent(null, 304 new Status (ActionType.EXECUTE, CommandType.START, 305 NbBundle.getMessage(WS70StartServer.class, "MSG_STARTING_TARGET_SERVER"), 306 StateType.RUNNING)); 307 308 RequestProcessor.getDefault().post(this, 0, Thread.NORM_PRIORITY); 309 String config = null; 310 try{ 311 config = this.getConfigNameFromTarget(t); 312 }catch(Exception ex){ 313 ex.printStackTrace(); 314 } 315 isDebugModeConfig.remove(dm.getHost()+dm.getPort()+config); 316 return this; 317 } 318 return null; 319 } 320 public ProgressObject stoptTarget(Target t){ 321 if(t!=null){ 322 this.target = t; 323 cmdType = WS70CommandType.STOPTARGET; 324 pes.fireHandleProgressEvent(null, 325 new Status (ActionType.EXECUTE, CommandType.START, 326 NbBundle.getMessage(WS70StartServer.class, "MSG_STOPPING_TARGET_SERVER"), 327 StateType.RUNNING)); 328 329 RequestProcessor.getDefault().post(this, 0, Thread.NORM_PRIORITY); 330 String config = null; 331 try{ 332 config = this.getConfigNameFromTarget(t); 333 }catch(Exception ex){ 334 ex.printStackTrace(); 335 } 336 isDebugModeConfig.remove(dm.getHost()+dm.getPort()+config); 337 return this; 338 } 339 return null; 340 } 341 public boolean supportsStartTarget(Target t){ 342 if(t==null){ 343 return false; 344 } 345 return true; 346 } 347 public boolean supportsStartDebugging(Target t){ 348 if(t==null){ 349 return false; 350 } 351 return true; 352 } 353 354 public synchronized void run(){ 356 if (cmdType.equals(WS70CommandType.START)) { 357 try{ 358 runProcess(makeProcessString("start"), true); this.viewAdminLogs(); 360 pes.fireHandleProgressEvent(null, 361 new Status (ActionType.EXECUTE, cmdType, 362 NbBundle.getMessage(WS70StartServer.class, "MSG_ADMIN_SERVER_STARTED"), 363 StateType.COMPLETED)); 364 }catch(Exception ex){ 365 pes.fireHandleProgressEvent(null, 366 new Status (ActionType.EXECUTE, cmdType, 367 ex.getLocalizedMessage(), 368 StateType.FAILED)); 369 370 } 371 } else if(cmdType.equals(WS70CommandType.STOP)) { 372 try{ 373 runProcess(makeProcessString("stop"), true); this.viewAdminLogs(); 375 pes.fireHandleProgressEvent(null, 376 new Status (ActionType.EXECUTE, cmdType, 377 NbBundle.getMessage(WS70StartServer.class, "MSG_ADMIN_SERVER_STOPPED"), 378 StateType.COMPLETED)); 379 }catch(Exception ex){ 380 pes.fireHandleProgressEvent(null, 381 new Status (ActionType.EXECUTE, cmdType, 382 ex.getLocalizedMessage(), 383 StateType.FAILED)); 384 385 } 386 }else if(cmdType.equals(WS70CommandType.STARTTARGET)) { 387 try{ 388 String configName = this.getConfigNameFromTarget(target); 389 dm.startServer(configName); 390 pes.fireHandleProgressEvent(null, 391 new Status (ActionType.EXECUTE, cmdType, 392 NbBundle.getMessage(WS70StartServer.class, "MSG_TARGET_SERVER_STARTED"), 393 StateType.COMPLETED)); 394 }catch(Exception ex){ 395 pes.fireHandleProgressEvent(null, 396 new Status (ActionType.EXECUTE, cmdType, 397 ex.getLocalizedMessage(), 398 StateType.FAILED)); 399 } 400 401 }else if(cmdType.equals(WS70CommandType.STOPTARGET)) { 402 try{ 403 String configName = this.getConfigNameFromTarget(target); 404 dm.stopServer(configName); 405 pes.fireHandleProgressEvent(null, 406 new Status (ActionType.EXECUTE, cmdType, 407 NbBundle.getMessage(WS70StartServer.class, "MSG_TARGET_SERVER_STOPPED"), 408 StateType.COMPLETED)); 409 }catch(Exception ex){ 410 pes.fireHandleProgressEvent(null, 411 new Status (ActionType.EXECUTE, cmdType, 412 ex.getLocalizedMessage(), 413 StateType.FAILED)); 414 } 415 416 }else if(cmdType.equals(WS70CommandType.STARTTARGETDEBUG)) { 417 try{ 418 String configName = this.getConfigNameFromTarget(target); 419 if(dm.isDebugModeEnabled()){ 420 if(!dm.isRunning(configName)){ 421 ErrorManager.getDefault().log( 422 ErrorManager.INFORMATIONAL, NbBundle.getMessage(WS70StartServer.class, "MSG_STARTING_TARGET_SERVER_DEBUG")); 423 dm.startServer(configName); 425 pes.fireHandleProgressEvent(null, 426 new Status (ActionType.EXECUTE, cmdType, 427 NbBundle.getMessage(WS70StartServer.class, "MSG_TARGET_SERVER_STARTED_DEBUG"), 428 StateType.COMPLETED)); 429 }else{ 430 pes.fireHandleProgressEvent(null, 431 new Status (ActionType.EXECUTE, cmdType, 432 NbBundle.getMessage(WS70StartServer.class, "MSG_TARGET_SERVER_STARTED_DEBUG"), 433 StateType.COMPLETED)); 434 } 435 }else{ 436 if(dm.isRunning(configName)){ ErrorManager.getDefault().log( 438 ErrorManager.INFORMATIONAL, NbBundle.getMessage(WS70StartServer.class, "MSG_STOPPING_TARGET_SERVER")); 439 pes.fireHandleProgressEvent(null, 440 new Status (ActionType.EXECUTE, cmdType, 441 NbBundle.getMessage(WS70StartServer.class, "MSG_RESTARTING_TARGET_SERVER_DEBUG"), 442 StateType.RUNNING)); 443 dm.stopServer(configName); 444 445 } 446 ErrorManager.getDefault().log( 448 ErrorManager.INFORMATIONAL, NbBundle.getMessage(WS70StartServer.class, "MSG_TARGET_SERVER_SETTING_DEBUG_MODE")); 449 dm.changeDebugStatus(configName, true); 450 ErrorManager.getDefault().log( 452 ErrorManager.INFORMATIONAL, NbBundle.getMessage(WS70StartServer.class, "MSG_STARTING_TARGET_SERVER_DEBUG")); 453 dm.startServer(configName); 454 pes.fireHandleProgressEvent(null, 455 new Status (ActionType.EXECUTE, cmdType, 456 NbBundle.getMessage(WS70StartServer.class, "MSG_TARGET_SERVER_STARTED_DEBUG"), 457 StateType.COMPLETED)); 458 459 } 460 }catch(Exception ex){ 461 pes.fireHandleProgressEvent(null, 462 new Status (ActionType.EXECUTE, cmdType, 463 ex.getLocalizedMessage(), 464 StateType.FAILED)); 465 466 } 467 } 468 } 469 470 471 public ClientConfiguration getClientConfiguration(TargetModuleID t) { 472 return null; 473 } 474 475 476 public DeploymentStatus getDeploymentStatus() { 477 return pes.getDeploymentStatus(); 478 } 479 480 481 public TargetModuleID [] getResultTargetModuleIDs() { 482 return new TargetModuleID [] {}; 483 } 484 485 486 public boolean isCancelSupported() { 487 return false; 488 } 489 490 491 public void cancel() throws OperationUnsupportedException { 492 throw new OperationUnsupportedException ("cancel not supported in WS deployment"); } 494 495 496 public boolean isStopSupported() { 497 return false; 498 } 499 500 501 public void stop() throws OperationUnsupportedException { 502 throw new OperationUnsupportedException ("stop not supported in WS deployment"); } 504 505 506 public void addProgressListener(ProgressListener l) { 507 pes.addProgressListener(l); 508 } 509 510 511 public void removeProgressListener(ProgressListener l) { 512 pes.removeProgressListener(l); 513 } 514 515 private int runProcess(String str, boolean wait) throws Exception { 516 Process child = Runtime.getRuntime().exec(str); 517 if (wait) 518 child.waitFor(); 519 return child.exitValue(); 520 } 521 private String makeProcessString(String str) { 522 if (org.openide.util.Utilities.isWindows()){ 523 return "net " + str + " " + "https-admserv70"; }else{ 525 String process = str+"serv"; 526 return ((WS70SunDeploymentManager)dm).getServerLocation()+File.separator + 527 "admin-server" + File.separator+"bin" + File.separator + process; } 529 } 530 private void viewAdminLogs(){ 531 String uri = dm.getUri(); 532 String location = dm.getServerLocation(); 533 location = location+File.separator+"admin-server"+ 534 File.separator+"logs"+File.separator+"errors"; 535 536 WS70LogViewer logViewer = new WS70LogViewer(new File (location)); 537 538 try{ 539 logViewer.showLogViewer(UISupport.getServerIO(uri)); 540 }catch(Exception ex){ 541 ErrorManager.getDefault().notify(ErrorManager.WARNING, ex); 542 } 543 } 544 private String getConfigNameFromTarget(Target t) throws Exception { 545 try{ 546 java.lang.reflect.Method getConfigName = t.getClass().getDeclaredMethod("getConfigName", new Class []{}); 547 return (String )getConfigName.invoke(t, new Object []{}); 548 }catch(Exception ex){ 549 throw ex; 550 } 551 } 552 } 553 | Popular Tags |