1
2
3
4
5
6
7
8
9
10
11
12 package com.eviware.soapui.actions;
13
14 import java.awt.event.ActionEvent;
15 import java.io.File;
16 import java.util.Map;
17
18 import javax.swing.AbstractAction;
19 import javax.swing.Action;
20
21 import com.eviware.soapui.SoapUI;
22 import com.eviware.soapui.impl.wsdl.submit.transports.jms.util.HermesUtils;
23 import com.eviware.soapui.settings.ToolsSettings;
24 import com.eviware.soapui.support.UISupport;
25 /***
26 * this class represents toolbar button for starting HermesJMS
27 * @author nebojsa.tasic
28 *
29 */
30 public class StartHermesJMSButtonAction extends AbstractAction
31 {
32 public StartHermesJMSButtonAction()
33 {
34 putValue(Action.SMALL_ICON, UISupport.createImageIcon("/hermes-16x16.gif"));
35 putValue(Action.SHORT_DESCRIPTION, "Start HermesJMS application");
36 putValue(Action.NAME, "HermesJMS");
37 }
38
39 public void actionPerformed(ActionEvent e)
40 {
41 try
42 {
43 String hermesHome =SoapUI.getSettings().getString(ToolsSettings.HERMES_JMS, HermesUtils.defaultHermesJMSPath());
44 if(!isHermesHomeValid( hermesHome )){
45 UISupport.showErrorMessage("Please set Hermes JMS path in Preferences->Tools ! ");
46 if( UISupport.getMainFrame() != null )
47 {
48 if( SoapUIPreferencesAction.getInstance().show( SoapUIPreferencesAction.INTEGRATED_TOOLS ) )
49 {
50 hermesHome = SoapUI.getSettings().getString( ToolsSettings.HERMES_JMS,HermesUtils.defaultHermesJMSPath() );
51 }
52 }
53
54 }
55 if( !isHermesHomeValid( hermesHome )){
56 return;
57 }
58 String extension = UISupport.isWindows() ? ".bat" : ".sh";
59 String hermesBatPath =hermesHome + File.separator + "bin"+ File.separator + "hermes" +extension;
60 ProcessBuilder pb = new ProcessBuilder(hermesBatPath);
61 Map<String, String> env = pb.environment();
62 env.put("JAVA_HOME", System.getProperty( "java.home" ));
63 pb.start();
64 }
65 catch (Throwable t)
66 {
67 SoapUI.logError(t);
68 }
69 }
70
71
72 private boolean isHermesHomeValid( String hermesHome )
73 {
74 File file = new File( hermesHome + File.separator + "bin"+ File.separator + "hermes.bat" );
75 if( file.exists() )
76 {
77 return true;
78 }
79 return false;
80 }
81 }