1
2
3
4
5
6
7
8
9
10
11
12
13 package com.eviware.soapui.actions;
14
15 import java.io.IOException;
16
17 import org.apache.log4j.Logger;
18
19 import com.eviware.soapui.DefaultSoapUICore;
20 import com.eviware.soapui.SoapUI;
21 import com.eviware.soapui.impl.wsdl.WsdlProject;
22 import com.eviware.soapui.impl.wsdl.support.HelpUrls;
23 import com.eviware.soapui.settings.ProjectSettings;
24 import com.eviware.soapui.support.UISupport;
25 import com.eviware.soapui.support.action.support.AbstractSoapUIAction;
26 import com.eviware.soapui.tools.MockAsWar;
27 import com.eviware.x.form.XFormDialog;
28 import com.eviware.x.form.XFormField;
29 import com.eviware.x.form.XFormFieldListener;
30 import com.eviware.x.form.support.ADialogBuilder;
31 import com.eviware.x.form.support.AField;
32 import com.eviware.x.form.support.AForm;
33 import com.eviware.x.form.support.AField.AFieldType;
34 import com.eviware.x.form.validators.RequiredValidator;
35
36 public class MockAsWarAction extends AbstractSoapUIAction<WsdlProject>
37 {
38 private XFormDialog dialog;
39 private Logger log = Logger.getLogger( MockAsWarAction.class );
40
41 public MockAsWarAction()
42 {
43 super( "Deploy As War", "Deploys Project MockServices as a WAR file" );
44 }
45
46 public void perform( WsdlProject project, Object param )
47 {
48
49 if( project.getMockServiceCount() == 0 )
50 {
51 UISupport.showErrorMessage( "Project does not have any MockServices to deploy" );
52 return;
53 }
54
55
56 if( dialog == null )
57 {
58 dialog = ADialogBuilder.buildDialog( MockAsWarDialog.class );
59 dialog.getFormField( MockAsWarDialog.GLOBAL_SETTINGS ).addFormFieldListener( new XFormFieldListener()
60 {
61 public void valueChanged( XFormField sourceField, String newValue, String oldValue )
62 {
63 if( Boolean.valueOf( newValue ) )
64 dialog.getFormField( MockAsWarDialog.SETTINGS_FILE ).setEnabled( true );
65 else
66 dialog.getFormField( MockAsWarDialog.SETTINGS_FILE ).setEnabled( false );
67 }
68
69 } );
70
71 dialog.getFormField( MockAsWarDialog.WAR_DIRECTORY ).addFormFieldValidator(
72 new RequiredValidator( "WAR Directory is required" ) );
73 }
74
75 XFormField settingFile = dialog.getFormField( MockAsWarDialog.SETTINGS_FILE );
76 settingFile.setValue( ( ( DefaultSoapUICore )SoapUI.getSoapUICore() ).getSettingsFile() );
77 settingFile.setEnabled( false );
78
79 XFormField warDirectory = dialog.getFormField( MockAsWarDialog.WAR_DIRECTORY );
80 XFormField warFile = dialog.getFormField( MockAsWarDialog.WAR_FILE );
81
82 String passwordForEncryption = project.getSettings().getString( ProjectSettings.SHADOW_PASSWORD, null );
83 project.getSettings().setString( ProjectSettings.SHADOW_PASSWORD, null );
84
85 if( dialog.show() )
86 {
87 project.beforeSave();
88 try
89 {
90 project.save();
91 }
92 catch( IOException e )
93 {
94 log.error( e.getMessage(), e );
95 }
96 finally
97 {
98 project.getSettings().setString( ProjectSettings.SHADOW_PASSWORD, passwordForEncryption );
99 }
100
101 MockAsWar mockAsWar = new MockAsWar( project.getPath(), dialog
102 .getBooleanValue( MockAsWarDialog.GLOBAL_SETTINGS ) ? settingFile.getValue() : "", warDirectory
103 .getValue(), warFile.getValue(), dialog.getBooleanValue( MockAsWarDialog.EXT_LIBS ), dialog
104 .getBooleanValue( MockAsWarDialog.ACTIONS ), dialog.getBooleanValue( MockAsWarDialog.LISTENERS ), dialog
105 .getValue( MockAsWarDialog.MOCKSERVICE_ENDPOINT ), dialog.getBooleanValue( MockAsWarDialog.ENABLE_WEBUI ) );
106 mockAsWar.createMockAsWarArchive();
107 }
108 }
109
110 @AForm( description = "Configure what to include in generated WAR", name = "Deploy Project as WAR", helpUrl = HelpUrls.MOCKASWAR_HELP_URL )
111 protected interface MockAsWarDialog
112 {
113 @AField( description = "Specify if global settings should be included", name = "Include Global Settings", type = AFieldType.BOOLEAN )
114 public final static String GLOBAL_SETTINGS = "Include Global Settings";
115
116 @AField( description = "Specify Settings File", name = "Settings", type = AFieldType.FILE )
117 public final static String SETTINGS_FILE = "Settings";
118
119 @AField( description = "Specify if action extensions should be included", name = "Include Actions", type = AFieldType.BOOLEAN )
120 public final static String ACTIONS = "Include Actions";
121
122 @AField( description = "Specify if listener extensions should be included", name = "Include Listeners", type = AFieldType.BOOLEAN )
123 public final static String LISTENERS = "Include Listeners";
124
125 @AField( description = "Include jar files from ext folder", name = "Include External Jar Files", type = AFieldType.BOOLEAN )
126 public final static String EXT_LIBS = "Include External Jar Files";
127
128 @AField( description = "Check to enable WebUI", name = "WebUI", type = AFieldType.BOOLEAN )
129 public final static String ENABLE_WEBUI = "WebUI";
130
131 @AField( description = "Local endpoint that will be used for WSDL endpoints/includes/imports", name = "MockService Endpoint", type = AFieldType.STRING )
132 public final static String MOCKSERVICE_ENDPOINT = "MockService Endpoint";
133
134 @AField( description = "Specify name of target War File", name = "War File", type = AFieldType.FILE )
135 public final static String WAR_FILE = "War File";
136
137 @AField( description = "Specify a directory where War file structure will be created", name = "War Directory", type = AFieldType.FOLDER )
138 public final static String WAR_DIRECTORY = "War Directory";
139
140 }
141 }