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