1
2
3
4
5
6
7
8
9
10
11
12
13 package com.eviware.soapui.actions;
14
15 import java.util.TreeMap;
16
17 import com.eviware.soapui.impl.wsdl.support.CompressionSupport;
18 import com.eviware.soapui.model.settings.Settings;
19 import com.eviware.soapui.settings.HttpSettings;
20 import com.eviware.soapui.support.components.SimpleForm;
21 import com.eviware.soapui.support.types.StringToStringMap;
22
23 /***
24 * Preferences class for HttpSettings
25 *
26 * @author ole.matzura
27 */
28
29 public class HttpPrefs implements Prefs
30 {
31 public static final String AUTHENTICATE_PREEMPTIVELY = "Authenticate Preemptively";
32 public static final String EXPECT_CONTINUE = "Expect Continue";
33 public static final String INCLUDE_REQUEST_IN_TIME_TAKEN = "Include request in time taken";
34 public static final String INCLUDE_RESPONSE_IN_TIME_TAKEN = "Include response in time taken";
35 public static final String REQUEST_COMPRESSION = "Request compression";
36 public static final String RESPONSE_COMPRESSION = "Response compression";
37 public static final String CLOSE_CONNECTIONS_AFTER_REQUEST = "Close connections after request";
38 public static final String USER_AGENT_HEADER = "User-Agent Header";
39 public static final String SOCKET_TIMEOUT = "Socket Timeout";
40 public static final String MAX_RESPONSE_SIZE = "Max response size";
41 public static final String ENCODED_URLS = "Pre-encoded Endpoints";
42 public static final String MAX_CONNECTIONS_PER_HOST = "Max Connections Per Host";
43 public static final String MAX_TOTAL_CONNECTIONS = "Max Total Connections";
44 public static final String BIND_ADDRESS = "Bind Address";
45 public static final String LEAVE_MOCKENGINE = "Leave MockEngine";
46
47 public static final String CHUNKING_THRESHOLD = "Chunking Threshold";
48 public static final String HTTP_VERSION = "HTTP Version";
49 public static final String ENABLE_MOCK_WIRE_LOG = "Enable Mock HTTP Log";
50 public static final String DISABLE_RESPONSE_DECOMPRESSION = "Disable Response Decompression";
51
52 private static TreeMap<String, String> compressionAlgs = new TreeMap<String, String>();
53
54 static
55 {
56 compressionAlgs.put( "None", "None" );
57 compressionAlgs.put( CompressionSupport.ALG_GZIP, "GZIP" );
58 compressionAlgs.put( CompressionSupport.ALG_DEFLATE, "DEFLATE" );
59 }
60
61 private SimpleForm httpForm;
62 private final String title;
63
64 public HttpPrefs( String title )
65 {
66 this.title = title;
67 }
68
69 public SimpleForm getForm()
70 {
71 if( httpForm == null )
72 {
73 httpForm = new SimpleForm();
74 httpForm.addSpace( 5 );
75 httpForm.appendComboBox( HttpPrefs.HTTP_VERSION, new String[] { HttpSettings.HTTP_VERSION_1_1,
76 HttpSettings.HTTP_VERSION_1_0 }, "Select HTTP Version to use" );
77 httpForm.appendTextField( HttpPrefs.USER_AGENT_HEADER,
78 "User-Agent HTTP header to send, blank will send default" );
79 httpForm.appendComboBox( HttpPrefs.REQUEST_COMPRESSION, compressionAlgs );
80 httpForm.appendCheckBox( HttpPrefs.RESPONSE_COMPRESSION, "Accept compressed responses from hosts", true );
81 httpForm.appendCheckBox( HttpPrefs.DISABLE_RESPONSE_DECOMPRESSION,
82 "Disable decompression of compressed responses", true );
83 httpForm.appendCheckBox( HttpPrefs.CLOSE_CONNECTIONS_AFTER_REQUEST,
84 "Closes the HTTP connection after each HTTP request", true );
85
86
87 httpForm.appendTextField( HttpPrefs.CHUNKING_THRESHOLD,
88 "Uses content-chunking for requests larger than threshold, blank to disable" );
89 httpForm.appendCheckBox( HttpPrefs.AUTHENTICATE_PREEMPTIVELY,
90 "Adds authentication information to outgoing request", true );
91 httpForm.appendCheckBox( HttpPrefs.EXPECT_CONTINUE,
92 "Activates 'Expect: 100-Continue' handshake for the entity enclosing methods", true );
93 httpForm.appendCheckBox( HttpPrefs.ENCODED_URLS, "Do not URL-escape service endpoints", true );
94 httpForm.appendTextField( HttpPrefs.BIND_ADDRESS, "Default local address to bind to when sending requests" );
95 httpForm.appendSeparator();
96 httpForm.appendCheckBox( HttpPrefs.INCLUDE_REQUEST_IN_TIME_TAKEN,
97 "Includes the time it took to write the request in time-taken", true );
98 httpForm.appendCheckBox( HttpPrefs.INCLUDE_RESPONSE_IN_TIME_TAKEN,
99 "Includes the time it took to read the entire response in time-taken", true );
100 httpForm.appendTextField( HttpPrefs.SOCKET_TIMEOUT, "Socket timeout in milliseconds" );
101 httpForm.appendTextField( HttpPrefs.MAX_RESPONSE_SIZE, "Maximum size to read from response (0 = no limit)" );
102 httpForm.appendTextField( HttpPrefs.MAX_CONNECTIONS_PER_HOST, "Maximum number of Connections Per Host" );
103 httpForm.appendTextField( HttpPrefs.MAX_TOTAL_CONNECTIONS, "Maximum number of Total Connections" );
104 httpForm.appendSeparator();
105 httpForm.appendCheckBox( HttpPrefs.LEAVE_MOCKENGINE, "Leave MockEngine running when stopping MockServices",
106 false );
107 httpForm.appendCheckBox( HttpPrefs.ENABLE_MOCK_WIRE_LOG, "Logs wire content of all mock requests", false );
108 httpForm.addSpace( 5 );
109 }
110
111 return httpForm;
112 }
113
114 public void getFormValues( Settings settings )
115 {
116 StringToStringMap httpValues = new StringToStringMap();
117 httpForm.getValues( httpValues );
118 storeValues( httpValues, settings );
119 }
120
121 public void storeValues( StringToStringMap httpValues, Settings settings )
122 {
123 settings.setString( HttpSettings.HTTP_VERSION, httpValues.get( HTTP_VERSION ) );
124
125
126 settings.setString( HttpSettings.CHUNKING_THRESHOLD, httpValues.get( CHUNKING_THRESHOLD ) );
127 settings.setString( HttpSettings.USER_AGENT, httpValues.get( USER_AGENT_HEADER ) );
128 settings.setString( HttpSettings.REQUEST_COMPRESSION, httpValues.get( REQUEST_COMPRESSION ) );
129 settings.setString( HttpSettings.RESPONSE_COMPRESSION, httpValues.get( RESPONSE_COMPRESSION ) );
130 settings.setString( HttpSettings.EXPECT_CONTINUE, httpValues.get( EXPECT_CONTINUE ) );
131 settings
132 .setString( HttpSettings.DISABLE_RESPONSE_DECOMPRESSION, httpValues.get( DISABLE_RESPONSE_DECOMPRESSION ) );
133 settings.setString( HttpSettings.CLOSE_CONNECTIONS, httpValues.get( CLOSE_CONNECTIONS_AFTER_REQUEST ) );
134 settings.setString( HttpSettings.AUTHENTICATE_PREEMPTIVELY, httpValues.get( AUTHENTICATE_PREEMPTIVELY ) );
135 settings.setString( HttpSettings.SOCKET_TIMEOUT, httpValues.get( SOCKET_TIMEOUT ) );
136 settings.setString( HttpSettings.ENCODED_URLS, httpValues.get( ENCODED_URLS ) );
137 settings.setString( HttpSettings.MAX_RESPONSE_SIZE, httpValues.get( MAX_RESPONSE_SIZE ) );
138 settings.setString( HttpSettings.INCLUDE_REQUEST_IN_TIME_TAKEN, httpValues.get( INCLUDE_REQUEST_IN_TIME_TAKEN ) );
139 settings
140 .setString( HttpSettings.INCLUDE_RESPONSE_IN_TIME_TAKEN, httpValues.get( INCLUDE_RESPONSE_IN_TIME_TAKEN ) );
141 settings.setString( HttpSettings.MAX_CONNECTIONS_PER_HOST, httpValues.get( MAX_CONNECTIONS_PER_HOST ) );
142 settings.setString( HttpSettings.MAX_TOTAL_CONNECTIONS, httpValues.get( MAX_TOTAL_CONNECTIONS ) );
143 settings.setString( HttpSettings.BIND_ADDRESS, httpValues.get( BIND_ADDRESS ) );
144 settings.setString( HttpSettings.LEAVE_MOCKENGINE, httpValues.get( LEAVE_MOCKENGINE ) );
145 settings.setString( HttpSettings.ENABLE_MOCK_WIRE_LOG, httpValues.get( ENABLE_MOCK_WIRE_LOG ) );
146 }
147
148 public void setFormValues( Settings settings )
149 {
150 getForm().setValues( getValues( settings ) );
151 }
152
153 public StringToStringMap getValues( Settings settings )
154 {
155 StringToStringMap httpValues = new StringToStringMap();
156 httpValues.put( HTTP_VERSION, settings.getString( HttpSettings.HTTP_VERSION, HttpSettings.HTTP_VERSION_1_1 ) );
157
158
159 httpValues.put( CHUNKING_THRESHOLD, settings.getString( HttpSettings.CHUNKING_THRESHOLD, null ) );
160 httpValues.put( USER_AGENT_HEADER, settings.getString( HttpSettings.USER_AGENT, null ) );
161 httpValues.put( REQUEST_COMPRESSION, compressionAlgs.get( settings.getString( HttpSettings.REQUEST_COMPRESSION,
162 "None" ) ) );
163 httpValues.put( RESPONSE_COMPRESSION, settings.getString( HttpSettings.RESPONSE_COMPRESSION, null ) );
164 httpValues.put( DISABLE_RESPONSE_DECOMPRESSION, settings.getString( HttpSettings.DISABLE_RESPONSE_DECOMPRESSION,
165 null ) );
166 httpValues.put( EXPECT_CONTINUE, settings.getString( HttpSettings.EXPECT_CONTINUE, null ) );
167 httpValues.put( CLOSE_CONNECTIONS_AFTER_REQUEST, settings.getString( HttpSettings.CLOSE_CONNECTIONS, null ) );
168 httpValues.put( AUTHENTICATE_PREEMPTIVELY, settings.getString( HttpSettings.AUTHENTICATE_PREEMPTIVELY, null ) );
169 httpValues.put( INCLUDE_REQUEST_IN_TIME_TAKEN, settings.getString( HttpSettings.INCLUDE_REQUEST_IN_TIME_TAKEN,
170 null ) );
171 httpValues.put( INCLUDE_RESPONSE_IN_TIME_TAKEN, settings.getString( HttpSettings.INCLUDE_RESPONSE_IN_TIME_TAKEN,
172 null ) );
173 httpValues.put( SOCKET_TIMEOUT, settings.getString( HttpSettings.SOCKET_TIMEOUT, null ) );
174 httpValues.put( ENCODED_URLS, settings.getString( HttpSettings.ENCODED_URLS, null ) );
175 httpValues.put( MAX_RESPONSE_SIZE, settings.getString( HttpSettings.MAX_RESPONSE_SIZE, "0" ) );
176 httpValues.put( MAX_CONNECTIONS_PER_HOST, settings.getString( HttpSettings.MAX_CONNECTIONS_PER_HOST, "500" ) );
177 httpValues.put( MAX_TOTAL_CONNECTIONS, settings.getString( HttpSettings.MAX_TOTAL_CONNECTIONS, "2000" ) );
178 httpValues.put( BIND_ADDRESS, settings.getString( HttpSettings.BIND_ADDRESS, "" ) );
179 httpValues.put( LEAVE_MOCKENGINE, settings.getString( HttpSettings.LEAVE_MOCKENGINE, null ) );
180 httpValues.put( ENABLE_MOCK_WIRE_LOG, settings.getString( HttpSettings.ENABLE_MOCK_WIRE_LOG, null ) );
181 return httpValues;
182 }
183
184 public String getTitle()
185 {
186 return title;
187 }
188 }