View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2007 eviware.com 
3    *
4    *  soapUI is free software; you can redistribute it and/or modify it under the 
5    *  terms of version 2.1 of the GNU Lesser General Public License as published by 
6    *  the Free Software Foundation.
7    *
8    *  soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without 
9    *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
10   *  See the GNU Lesser General Public License for more details at gnu.org.
11   */
12  
13  package com.eviware.soapui.actions;
14  
15  import com.eviware.soapui.model.settings.Settings;
16  import com.eviware.soapui.settings.HttpSettings;
17  import com.eviware.soapui.support.components.SimpleForm;
18  import com.eviware.soapui.support.types.StringToStringMap;
19  
20  /***
21   * Preferences class for HttpSettings
22   * 
23   * @author ole.matzura
24   */
25  
26  public class HttpPrefs implements Prefs
27  {
28     public static final String AUTHENTICATE_PREEMPTIVELY = "Authenticate Preemptively";  
29     public static final String INCLUDE_REQUEST_IN_TIME_TAKEN = "Include request in time taken";
30     public static final String INCLUDE_RESPONSE_IN_TIME_TAKEN = "Include response in time taken";
31     public static final String CLOSE_CONNECTIONS_AFTER_REQUEST = "Close connections after request";
32     public static final String USER_AGENT_HEADER = "User-Agent Header";
33     public static final String SOCKET_TIMEOUT = "Socket Timeout";  
34     public static final String MAX_RESPONSE_SIZE = "Max response size";
35  	public static final String ENCODED_URLS = "Pre-encoded Endpoints";
36  	public static final String MAX_CONNECTIONS_PER_HOST = "Max Connections Per Host";
37  	public static final String MAX_TOTAL_CONNECTIONS = "Max Total Connections";
38  	public static final String BIND_ADDRESS = "Bind Address";
39  	public static final String LEAVE_MOCKENGINE = "Leave MockEngine";
40     
41     private SimpleForm httpForm;
42  	private final String title;
43     
44     public HttpPrefs( String title )
45     {
46  		this.title = title;
47     }
48     
49  	public SimpleForm getForm()
50  	{
51  		if( httpForm == null )
52  		{
53  			httpForm = new SimpleForm();
54  			httpForm.addSpace( 5 );
55  			httpForm.appendTextField( HttpPrefs.USER_AGENT_HEADER, "User-Agent HTTP header to send, blank will send default" );
56  			httpForm.appendCheckBox( HttpPrefs.CLOSE_CONNECTIONS_AFTER_REQUEST, "Closes the HTTP connection after each SOAP request", true );
57  			httpForm.appendCheckBox( HttpPrefs.AUTHENTICATE_PREEMPTIVELY, "Adds authentication information to outgoing request", true );
58  			httpForm.appendCheckBox( HttpPrefs.INCLUDE_REQUEST_IN_TIME_TAKEN, "Includes the time it took to write the request in time-taken", true );
59  			httpForm.appendCheckBox( HttpPrefs.INCLUDE_RESPONSE_IN_TIME_TAKEN, "Includes the time it took to read the entire response in time-taken", true );
60  			httpForm.appendCheckBox( HttpPrefs.ENCODED_URLS, "Do not URL-escape service endpoints", true );
61  			httpForm.appendTextField( HttpPrefs.SOCKET_TIMEOUT, "Socket timeout in milliseconds" );
62  			httpForm.appendTextField( HttpPrefs.MAX_RESPONSE_SIZE, "Maximum size to read from response (0 = no limit)" );
63  			httpForm.appendSeparator();
64  			httpForm.appendTextField( HttpPrefs.MAX_CONNECTIONS_PER_HOST, "Maximum number of Connections Per Host" );
65  			httpForm.appendTextField( HttpPrefs.MAX_TOTAL_CONNECTIONS, "Maximum number of Total Connections" );
66  			httpForm.appendTextField( HttpPrefs.BIND_ADDRESS, "Default local address to bind to when sending requests" );
67  			httpForm.appendSeparator();
68  			httpForm.appendCheckBox( HttpPrefs.LEAVE_MOCKENGINE, "Leave MockEngine running when stopping MockServices", false );
69  			httpForm.addSpace( 5 );
70  		}
71  		
72  		return httpForm;
73  	}
74  
75  	public void getFormValues(Settings settings)
76  	{
77  		StringToStringMap httpValues = new StringToStringMap();
78  		httpForm.getValues( httpValues );
79  		storeValues(httpValues, settings);
80  	}
81  	
82  	public void storeValues(StringToStringMap httpValues, Settings settings)
83  	{
84  		settings.setString( HttpSettings.USER_AGENT, httpValues.get( USER_AGENT_HEADER ));
85        settings.setString( HttpSettings.CLOSE_CONNECTIONS, httpValues.get( CLOSE_CONNECTIONS_AFTER_REQUEST ));
86        settings.setString( HttpSettings.AUTHENTICATE_PREEMPTIVELY, httpValues.get( AUTHENTICATE_PREEMPTIVELY ));
87        settings.setString( HttpSettings.SOCKET_TIMEOUT, httpValues.get( SOCKET_TIMEOUT ));
88        settings.setString( HttpSettings.ENCODED_URLS, httpValues.get( ENCODED_URLS ));
89        settings.setString( HttpSettings.MAX_RESPONSE_SIZE, httpValues.get( MAX_RESPONSE_SIZE ));
90        settings.setString( HttpSettings.INCLUDE_REQUEST_IN_TIME_TAKEN, httpValues.get( INCLUDE_REQUEST_IN_TIME_TAKEN ));
91        settings.setString( HttpSettings.INCLUDE_RESPONSE_IN_TIME_TAKEN, httpValues.get( INCLUDE_RESPONSE_IN_TIME_TAKEN ));
92        settings.setString( HttpSettings.MAX_CONNECTIONS_PER_HOST, httpValues.get( MAX_CONNECTIONS_PER_HOST ));
93        settings.setString( HttpSettings.MAX_TOTAL_CONNECTIONS, httpValues.get( MAX_TOTAL_CONNECTIONS ));
94        settings.setString( HttpSettings.BIND_ADDRESS, httpValues.get( BIND_ADDRESS ));
95        settings.setString( HttpSettings.LEAVE_MOCKENGINE, httpValues.get(  LEAVE_MOCKENGINE ) );
96  	}
97  
98  	public void setFormValues(Settings settings)
99  	{
100 		getForm().setValues( getValues(settings) ); 
101 	}
102 
103 	public StringToStringMap getValues(Settings settings)
104 	{
105 		StringToStringMap httpValues = new StringToStringMap();
106       httpValues.put( USER_AGENT_HEADER, settings.getString( HttpSettings.USER_AGENT, null ));
107       httpValues.put( CLOSE_CONNECTIONS_AFTER_REQUEST, settings.getString( HttpSettings.CLOSE_CONNECTIONS, null  ));
108       httpValues.put( AUTHENTICATE_PREEMPTIVELY, settings.getString( HttpSettings.AUTHENTICATE_PREEMPTIVELY, null ));
109       httpValues.put( INCLUDE_REQUEST_IN_TIME_TAKEN, settings.getString( HttpSettings.INCLUDE_REQUEST_IN_TIME_TAKEN, null ));
110       httpValues.put( INCLUDE_RESPONSE_IN_TIME_TAKEN, settings.getString( HttpSettings.INCLUDE_RESPONSE_IN_TIME_TAKEN, null ));
111       httpValues.put( SOCKET_TIMEOUT, settings.getString( HttpSettings.SOCKET_TIMEOUT, null ));
112       httpValues.put( ENCODED_URLS, settings.getString( HttpSettings.ENCODED_URLS, null ));
113       httpValues.put( MAX_RESPONSE_SIZE, settings.getString( HttpSettings.MAX_RESPONSE_SIZE, "0" ));
114       httpValues.put( MAX_CONNECTIONS_PER_HOST, settings.getString( HttpSettings.MAX_CONNECTIONS_PER_HOST, "500" ));
115       httpValues.put( MAX_TOTAL_CONNECTIONS, settings.getString( HttpSettings.MAX_TOTAL_CONNECTIONS, "2000" ));
116       httpValues.put( BIND_ADDRESS, settings.getString( HttpSettings.BIND_ADDRESS, "" ));
117       httpValues.put( LEAVE_MOCKENGINE, settings.getString( HttpSettings.LEAVE_MOCKENGINE, null ));
118       return httpValues;
119 	}
120 
121 	public String getTitle()
122 	{
123 		return title;
124 	}
125 }