001: /*
002: * soapUI, copyright (C) 2004-2007 eviware.com
003: *
004: * soapUI is free software; you can redistribute it and/or modify it under the
005: * terms of version 2.1 of the GNU Lesser General Public License as published by
006: * the Free Software Foundation.
007: *
008: * soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
009: * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
010: * See the GNU Lesser General Public License for more details at gnu.org.
011: */
012:
013: package com.eviware.soapui.actions;
014:
015: import com.eviware.soapui.model.settings.Settings;
016: import com.eviware.soapui.settings.HttpSettings;
017: import com.eviware.soapui.support.components.SimpleForm;
018: import com.eviware.soapui.support.types.StringToStringMap;
019:
020: /**
021: * Preferences class for HttpSettings
022: *
023: * @author ole.matzura
024: */
025:
026: public class HttpPrefs implements Prefs {
027: public static final String AUTHENTICATE_PREEMPTIVELY = "Authenticate Preemptively";
028: public static final String INCLUDE_REQUEST_IN_TIME_TAKEN = "Include request in time taken";
029: public static final String INCLUDE_RESPONSE_IN_TIME_TAKEN = "Include response in time taken";
030: public static final String CLOSE_CONNECTIONS_AFTER_REQUEST = "Close connections after request";
031: public static final String USER_AGENT_HEADER = "User-Agent Header";
032: public static final String SOCKET_TIMEOUT = "Socket Timeout";
033: public static final String MAX_RESPONSE_SIZE = "Max response size";
034: public static final String ENCODED_URLS = "Pre-encoded Endpoints";
035: public static final String MAX_CONNECTIONS_PER_HOST = "Max Connections Per Host";
036: public static final String MAX_TOTAL_CONNECTIONS = "Max Total Connections";
037: public static final String BIND_ADDRESS = "Bind Address";
038:
039: private SimpleForm httpForm;
040: private final String title;
041:
042: public HttpPrefs(String title) {
043: this .title = title;
044: }
045:
046: public SimpleForm getForm() {
047: if (httpForm == null) {
048: httpForm = new SimpleForm();
049: httpForm.addSpace(5);
050: httpForm
051: .appendTextField(HttpPrefs.USER_AGENT_HEADER,
052: "User-Agent HTTP header to send, blank will send default");
053: httpForm
054: .appendCheckBox(
055: HttpPrefs.CLOSE_CONNECTIONS_AFTER_REQUEST,
056: "Closes the HTTP connection after each SOAP request",
057: true);
058: httpForm
059: .appendCheckBox(
060: HttpPrefs.AUTHENTICATE_PREEMPTIVELY,
061: "Adds authentication information to outgoing request",
062: true);
063: httpForm
064: .appendCheckBox(
065: HttpPrefs.INCLUDE_REQUEST_IN_TIME_TAKEN,
066: "Includes the time it took to write the request in time-taken",
067: true);
068: httpForm
069: .appendCheckBox(
070: HttpPrefs.INCLUDE_RESPONSE_IN_TIME_TAKEN,
071: "Includes the time it took to read the entire response in time-taken",
072: true);
073: httpForm.appendCheckBox(HttpPrefs.ENCODED_URLS,
074: "Do not URL-escape service endpoints", true);
075: httpForm.appendTextField(HttpPrefs.SOCKET_TIMEOUT,
076: "Socket timeout in milliseconds");
077: httpForm
078: .appendTextField(HttpPrefs.MAX_RESPONSE_SIZE,
079: "Maximum size to read from response (0 = no limit)");
080: httpForm.appendSeparator();
081: httpForm.appendTextField(
082: HttpPrefs.MAX_CONNECTIONS_PER_HOST,
083: "Maximum number of Connections Per Host");
084: httpForm.appendTextField(HttpPrefs.MAX_TOTAL_CONNECTIONS,
085: "Maximum number of Total Connections");
086: httpForm
087: .appendTextField(HttpPrefs.BIND_ADDRESS,
088: "Default local address to bind to when sending requests");
089: httpForm.addSpace(5);
090: }
091:
092: return httpForm;
093: }
094:
095: public void getFormValues(Settings settings) {
096: StringToStringMap httpValues = new StringToStringMap();
097: httpForm.getValues(httpValues);
098: storeValues(httpValues, settings);
099: }
100:
101: public void storeValues(StringToStringMap httpValues,
102: Settings settings) {
103: settings.setString(HttpSettings.USER_AGENT, httpValues
104: .get(USER_AGENT_HEADER));
105: settings.setString(HttpSettings.CLOSE_CONNECTIONS, httpValues
106: .get(CLOSE_CONNECTIONS_AFTER_REQUEST));
107: settings.setString(HttpSettings.AUTHENTICATE_PREEMPTIVELY,
108: httpValues.get(AUTHENTICATE_PREEMPTIVELY));
109: settings.setString(HttpSettings.SOCKET_TIMEOUT, httpValues
110: .get(SOCKET_TIMEOUT));
111: settings.setString(HttpSettings.ENCODED_URLS, httpValues
112: .get(ENCODED_URLS));
113: settings.setString(HttpSettings.MAX_RESPONSE_SIZE, httpValues
114: .get(MAX_RESPONSE_SIZE));
115: settings.setString(HttpSettings.INCLUDE_REQUEST_IN_TIME_TAKEN,
116: httpValues.get(INCLUDE_REQUEST_IN_TIME_TAKEN));
117: settings.setString(HttpSettings.INCLUDE_RESPONSE_IN_TIME_TAKEN,
118: httpValues.get(INCLUDE_RESPONSE_IN_TIME_TAKEN));
119: settings.setString(HttpSettings.MAX_CONNECTIONS_PER_HOST,
120: httpValues.get(MAX_CONNECTIONS_PER_HOST));
121: settings.setString(HttpSettings.MAX_TOTAL_CONNECTIONS,
122: httpValues.get(MAX_TOTAL_CONNECTIONS));
123: settings.setString(HttpSettings.BIND_ADDRESS, httpValues
124: .get(BIND_ADDRESS));
125: }
126:
127: public void setFormValues(Settings settings) {
128: getForm().setValues(getValues(settings));
129: }
130:
131: public StringToStringMap getValues(Settings settings) {
132: StringToStringMap httpValues = new StringToStringMap();
133: httpValues.put(USER_AGENT_HEADER, settings.getString(
134: HttpSettings.USER_AGENT, null));
135: httpValues.put(CLOSE_CONNECTIONS_AFTER_REQUEST, settings
136: .getString(HttpSettings.CLOSE_CONNECTIONS, null));
137: httpValues.put(AUTHENTICATE_PREEMPTIVELY, settings.getString(
138: HttpSettings.AUTHENTICATE_PREEMPTIVELY, null));
139: httpValues.put(INCLUDE_REQUEST_IN_TIME_TAKEN, settings
140: .getString(HttpSettings.INCLUDE_REQUEST_IN_TIME_TAKEN,
141: null));
142: httpValues.put(INCLUDE_RESPONSE_IN_TIME_TAKEN, settings
143: .getString(HttpSettings.INCLUDE_RESPONSE_IN_TIME_TAKEN,
144: null));
145: httpValues.put(SOCKET_TIMEOUT, settings.getString(
146: HttpSettings.SOCKET_TIMEOUT, null));
147: httpValues.put(ENCODED_URLS, settings.getString(
148: HttpSettings.ENCODED_URLS, null));
149: httpValues.put(MAX_RESPONSE_SIZE, settings.getString(
150: HttpSettings.MAX_RESPONSE_SIZE, "0"));
151: httpValues.put(MAX_CONNECTIONS_PER_HOST, settings.getString(
152: HttpSettings.MAX_CONNECTIONS_PER_HOST, "500"));
153: httpValues.put(MAX_TOTAL_CONNECTIONS, settings.getString(
154: HttpSettings.MAX_TOTAL_CONNECTIONS, "2000"));
155: httpValues.put(BIND_ADDRESS, settings.getString(
156: HttpSettings.BIND_ADDRESS, ""));
157: return httpValues;
158: }
159:
160: public String getTitle() {
161: return title;
162: }
163: }
|