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 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
48
49 private static TreeMap<String, String> compressionAlgs = new TreeMap<String, String>();
50 static {
51 compressionAlgs.put("None", "None");
52 compressionAlgs.put(CompressionSupport.ALG_GZIP, "GZIP");
53 compressionAlgs.put(CompressionSupport.ALG_DEFLATE, "DEFLATE");
54 }
55 private SimpleForm httpForm;
56 private final String title;
57
58 public HttpPrefs( String title )
59 {
60 this.title = title;
61 }
62
63 public SimpleForm getForm()
64 {
65 if( httpForm == null )
66 {
67 httpForm = new SimpleForm();
68 httpForm.addSpace( 5 );
69 httpForm.appendComboBox(HttpPrefs.HTTP_VERSION, new String[]
70 {HttpSettings.HTTP_VERSION_1_1, HttpSettings.HTTP_VERSION_1_0,HttpSettings.HTTP_VERSION_0_9},
71 "Select HTTP Version to use");
72 httpForm.appendTextField( HttpPrefs.USER_AGENT_HEADER, "User-Agent HTTP header to send, blank will send default" );
73 httpForm.appendComboBox( HttpPrefs.REQUEST_COMPRESSION, compressionAlgs );
74 httpForm.appendCheckBox( HttpPrefs.RESPONSE_COMPRESSION, "Accept compressed responses from hosts", true );
75 httpForm.appendCheckBox( HttpPrefs.CLOSE_CONNECTIONS_AFTER_REQUEST, "Closes the HTTP connection after each SOAP request", true );
76 httpForm.appendCheckBox( HttpPrefs.DISABLE_CHUNKING, "Disables content-chunking", true );
77 httpForm.appendCheckBox( HttpPrefs.AUTHENTICATE_PREEMPTIVELY, "Adds authentication information to outgoing request", true );
78 httpForm.appendCheckBox( HttpPrefs.ENCODED_URLS, "Do not URL-escape service endpoints", true );
79 httpForm.appendTextField( HttpPrefs.BIND_ADDRESS, "Default local address to bind to when sending requests" );
80 httpForm.appendSeparator();
81 httpForm.appendCheckBox( HttpPrefs.INCLUDE_REQUEST_IN_TIME_TAKEN, "Includes the time it took to write the request in time-taken", true );
82 httpForm.appendCheckBox( HttpPrefs.INCLUDE_RESPONSE_IN_TIME_TAKEN, "Includes the time it took to read the entire response in time-taken", true );
83 httpForm.appendTextField( HttpPrefs.SOCKET_TIMEOUT, "Socket timeout in milliseconds" );
84 httpForm.appendTextField( HttpPrefs.MAX_RESPONSE_SIZE, "Maximum size to read from response (0 = no limit)" );
85 httpForm.appendTextField( HttpPrefs.MAX_CONNECTIONS_PER_HOST, "Maximum number of Connections Per Host" );
86 httpForm.appendTextField( HttpPrefs.MAX_TOTAL_CONNECTIONS, "Maximum number of Total Connections" );
87 httpForm.appendSeparator();
88 httpForm.appendCheckBox( HttpPrefs.LEAVE_MOCKENGINE, "Leave MockEngine running when stopping MockServices", false );
89 httpForm.addSpace( 5 );
90 }
91
92 return httpForm;
93 }
94
95 public void getFormValues(Settings settings)
96 {
97 StringToStringMap httpValues = new StringToStringMap();
98 httpForm.getValues( httpValues );
99 storeValues(httpValues, settings);
100 }
101
102 public void storeValues(StringToStringMap httpValues, Settings settings)
103 {
104 settings.setString( HttpSettings.HTTP_VERSION, httpValues.get( HTTP_VERSION ));
105 settings.setString( HttpSettings.DISABLE_CHUNKING, httpValues.get( DISABLE_CHUNKING ));
106 settings.setString( HttpSettings.USER_AGENT, httpValues.get( USER_AGENT_HEADER ));
107 settings.setString( HttpSettings.REQUEST_COMPRESSION, httpValues.get( REQUEST_COMPRESSION ));
108 settings.setString( HttpSettings.RESPONSE_COMPRESSION, httpValues.get( RESPONSE_COMPRESSION ));
109 settings.setString( HttpSettings.CLOSE_CONNECTIONS, httpValues.get( CLOSE_CONNECTIONS_AFTER_REQUEST ));
110 settings.setString( HttpSettings.AUTHENTICATE_PREEMPTIVELY, httpValues.get( AUTHENTICATE_PREEMPTIVELY ));
111 settings.setString( HttpSettings.SOCKET_TIMEOUT, httpValues.get( SOCKET_TIMEOUT ));
112 settings.setString( HttpSettings.ENCODED_URLS, httpValues.get( ENCODED_URLS ));
113 settings.setString( HttpSettings.MAX_RESPONSE_SIZE, httpValues.get( MAX_RESPONSE_SIZE ));
114 settings.setString( HttpSettings.INCLUDE_REQUEST_IN_TIME_TAKEN, httpValues.get( INCLUDE_REQUEST_IN_TIME_TAKEN ));
115 settings.setString( HttpSettings.INCLUDE_RESPONSE_IN_TIME_TAKEN, httpValues.get( INCLUDE_RESPONSE_IN_TIME_TAKEN ));
116 settings.setString( HttpSettings.MAX_CONNECTIONS_PER_HOST, httpValues.get( MAX_CONNECTIONS_PER_HOST ));
117 settings.setString( HttpSettings.MAX_TOTAL_CONNECTIONS, httpValues.get( MAX_TOTAL_CONNECTIONS ));
118 settings.setString( HttpSettings.BIND_ADDRESS, httpValues.get( BIND_ADDRESS ));
119 settings.setString( HttpSettings.LEAVE_MOCKENGINE, httpValues.get( LEAVE_MOCKENGINE ) );
120 }
121
122 public void setFormValues(Settings settings)
123 {
124 getForm().setValues( getValues(settings) );
125 }
126
127 public StringToStringMap getValues(Settings settings)
128 {
129 StringToStringMap httpValues = new StringToStringMap();
130 httpValues.put( HTTP_VERSION, settings.getString( HttpSettings.HTTP_VERSION, HttpSettings.HTTP_VERSION_1_1 ));
131 httpValues.put( DISABLE_CHUNKING, settings.getString( HttpSettings.DISABLE_CHUNKING, null ));
132 httpValues.put( USER_AGENT_HEADER, settings.getString( HttpSettings.USER_AGENT, null ));
133 httpValues.put( REQUEST_COMPRESSION, compressionAlgs.get(settings.getString( HttpSettings.REQUEST_COMPRESSION, "None" )));
134 httpValues.put( RESPONSE_COMPRESSION, settings.getString( HttpSettings.RESPONSE_COMPRESSION, null ));
135 httpValues.put( CLOSE_CONNECTIONS_AFTER_REQUEST, settings.getString( HttpSettings.CLOSE_CONNECTIONS, null ));
136 httpValues.put( AUTHENTICATE_PREEMPTIVELY, settings.getString( HttpSettings.AUTHENTICATE_PREEMPTIVELY, null ));
137 httpValues.put( INCLUDE_REQUEST_IN_TIME_TAKEN, settings.getString( HttpSettings.INCLUDE_REQUEST_IN_TIME_TAKEN, null ));
138 httpValues.put( INCLUDE_RESPONSE_IN_TIME_TAKEN, settings.getString( HttpSettings.INCLUDE_RESPONSE_IN_TIME_TAKEN, null ));
139 httpValues.put( SOCKET_TIMEOUT, settings.getString( HttpSettings.SOCKET_TIMEOUT, null ));
140 httpValues.put( ENCODED_URLS, settings.getString( HttpSettings.ENCODED_URLS, null ));
141 httpValues.put( MAX_RESPONSE_SIZE, settings.getString( HttpSettings.MAX_RESPONSE_SIZE, "0" ));
142 httpValues.put( MAX_CONNECTIONS_PER_HOST, settings.getString( HttpSettings.MAX_CONNECTIONS_PER_HOST, "500" ));
143 httpValues.put( MAX_TOTAL_CONNECTIONS, settings.getString( HttpSettings.MAX_TOTAL_CONNECTIONS, "2000" ));
144 httpValues.put( BIND_ADDRESS, settings.getString( HttpSettings.BIND_ADDRESS, "" ));
145 httpValues.put( LEAVE_MOCKENGINE, settings.getString( HttpSettings.LEAVE_MOCKENGINE, null ));
146 return httpValues;
147 }
148
149 public String getTitle()
150 {
151 return title;
152 }
153 }