1
2
3
4
5
6
7
8
9
10
11
12 package com.eviware.soapui.impl.wsdl.actions.project;
13
14 import java.awt.Component;
15 import java.io.File;
16 import java.io.IOException;
17 import java.util.Map;
18
19 import com.eviware.soapui.SoapUI;
20 import com.eviware.soapui.actions.SoapUIPreferencesAction;
21 import com.eviware.soapui.impl.wsdl.WsdlProject;
22 import com.eviware.soapui.impl.wsdl.submit.transports.jms.util.HermesUtils;
23 import com.eviware.soapui.model.propertyexpansion.PropertyExpander;
24 import com.eviware.soapui.settings.ToolsSettings;
25 import com.eviware.soapui.support.UISupport;
26 import com.eviware.soapui.support.action.support.AbstractSoapUIAction;
27 import com.eviware.soapui.support.components.DirectoryFormComponent;
28 import com.eviware.soapui.support.components.SimpleForm;
29
30 public class StartHermesJMS extends AbstractSoapUIAction<WsdlProject>
31 {
32 public static final String SOAPUI_ACTION_ID = "StarHermesJMS";
33
34 public StartHermesJMS()
35 {
36 super( "Start HermesJMS", "Start HermesJMS application" );
37 }
38
39 public void perform( WsdlProject project, Object param )
40 {
41 String hermesConfigPath = chooseFolderDialog( project );
42
43 if( hermesConfigPath == null )
44 return;
45
46 project.setHermesConfig( hermesConfigPath );
47
48 String hermesHome = SoapUI.getSettings().getString( ToolsSettings.HERMES_JMS, HermesUtils.defaultHermesJMSPath() );
49 if(!isHermesHomeValid( hermesHome )){
50 UISupport.showErrorMessage("Please set Hermes JMS path in Preferences->Tools ! ");
51 if( UISupport.getMainFrame() != null )
52 {
53 if( SoapUIPreferencesAction.getInstance().show( SoapUIPreferencesAction.INTEGRATED_TOOLS ) )
54 {
55 hermesHome = SoapUI.getSettings().getString( ToolsSettings.HERMES_JMS,HermesUtils.defaultHermesJMSPath() );
56 }
57 }
58
59 }
60 if( !isHermesHomeValid( hermesHome )){
61 return;
62 }
63 startHermesJMS( hermesConfigPath, hermesHome );
64 }
65
66 private boolean isHermesHomeValid( String hermesHome )
67 {
68 File file = new File( hermesHome + File.separator + "bin"+ File.separator + "hermes.bat" );
69 if( file.exists() )
70 {
71 return true;
72 }
73 return false;
74 }
75
76 private void startHermesJMS( String hermesConfigPath, String hermesHome )
77 {
78 String extension = UISupport.isWindows() ? ".bat" : ".sh";
79 String hermesBatPath = hermesHome + File.separator + "bin" + File.separator + "hermes" + extension;
80 try
81 {
82 File file = new File( hermesConfigPath + File.separator + HermesUtils.HERMES_CONFIG_XML );
83 if( !file.exists() )
84 {
85 UISupport.showErrorMessage( "No hermes-config.xml on this path!" );
86 return;
87 }
88 ProcessBuilder pb = new ProcessBuilder( hermesBatPath );
89 Map<String, String> env = pb.environment();
90 env.put( "HERMES_CONFIG", hermesConfigPath );
91 env.put( "JAVA_HOME", System.getProperty( "java.home" ) );
92 pb.start();
93 }
94 catch( IOException e )
95 {
96 SoapUI.logError( e );
97 }
98 }
99
100 private String chooseFolderDialog( WsdlProject project )
101 {
102 HermesConfigDialog chooseHermesConfigPath = new HermesConfigDialog( PropertyExpander.expandProperties( project,
103 project.getHermesConfig() ) );
104 chooseHermesConfigPath.setVisible( true );
105 String hermesConfigPath = chooseHermesConfigPath.getPath();
106 return hermesConfigPath;
107 }
108
109 private class HermesConfigDialog extends SimpleDialog
110 {
111
112 String path;
113 DirectoryFormComponent folderComponent;
114
115 public HermesConfigDialog( String initialPath )
116 {
117 super( "Start HermesJMS", "Hermes configuration", null, true );
118 folderComponent.setValue( initialPath );
119 folderComponent.setInitialFolder( initialPath );
120
121 }
122
123 protected Component buildContent()
124 {
125
126 SimpleForm form = new SimpleForm();
127 folderComponent = new DirectoryFormComponent(
128 "Location of desired HermesJMS configuration (hermes-config.xml)" );
129 form.addSpace( 5 );
130 form.append( "Path", folderComponent );
131 form.addSpace( 5 );
132
133 return form.getPanel();
134 }
135
136 protected boolean handleOk()
137 {
138 setPath( folderComponent.getValue() );
139 return true;
140 }
141
142 public String getPath()
143 {
144 return path;
145 }
146
147 public void setPath( String path )
148 {
149 this.path = path;
150 }
151
152 }
153 }