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     
40     private SimpleForm httpForm;
41  	private final String title;
42     
43     public HttpPrefs( String title )
44     {
45  		this.title = title;
46     }
47     
48  	public SimpleForm getForm()
49  	{
50  		if( httpForm == null )
51  		{
52  			httpForm = new SimpleForm();
53  			httpForm.addSpace( 5 );
54  			httpForm.appendTextField( HttpPrefs.USER_AGENT_HEADER, "User-Agent HTTP header to send, blank will send default" );
55  			httpForm.appendCheckBox( HttpPrefs.CLOSE_CONNECTIONS_AFTER_REQUEST, "Closes the HTTP connection after each SOAP request", true );
56  			httpForm.appendCheckBox( HttpPrefs.AUTHENTICATE_PREEMPTIVELY, "Adds authentication information to outgoing request", true );
57  			httpForm.appendCheckBox( HttpPrefs.INCLUDE_REQUEST_IN_TIME_TAKEN, "Includes the time it took to write the request in time-taken", true );
58  			httpForm.appendCheckBox( HttpPrefs.INCLUDE_RESPONSE_IN_TIME_TAKEN, "Includes the time it took to read the entire response in time-taken", true );
59  			httpForm.appendCheckBox( HttpPrefs.ENCODED_URLS, "Do not URL-escape service endpoints", true );
60  			httpForm.appendTextField( HttpPrefs.SOCKET_TIMEOUT, "Socket timeout in milliseconds" );
61  			httpForm.appendTextField( HttpPrefs.MAX_RESPONSE_SIZE, "Maximum size to read from response (0 = no limit)" );
62  			httpForm.appendSeparator();
63  			httpForm.appendTextField( HttpPrefs.MAX_CONNECTIONS_PER_HOST, "Maximum number of Connections Per Host" );
64  			httpForm.appendTextField( HttpPrefs.MAX_TOTAL_CONNECTIONS, "Maximum number of Total Connections" );
65  			httpForm.appendTextField( HttpPrefs.BIND_ADDRESS, "Default local address to bind to when sending requests" );
66  			httpForm.addSpace( 5 );
67  		}
68  		
69  		return httpForm;
70  	}
71  
72  	public void getFormValues(Settings settings)
73  	{
74  		StringToStringMap httpValues = new StringToStringMap();
75  		httpForm.getValues( httpValues );
76  		storeValues(httpValues, settings);
77  	}
78  	
79  	public void storeValues(StringToStringMap httpValues, Settings settings)
80  	{
81  		settings.setString( HttpSettings.USER_AGENT, httpValues.get( USER_AGENT_HEADER ));
82        settings.setString( HttpSettings.CLOSE_CONNECTIONS, httpValues.get( CLOSE_CONNECTIONS_AFTER_REQUEST ));
83        settings.setString( HttpSettings.AUTHENTICATE_PREEMPTIVELY, httpValues.get( AUTHENTICATE_PREEMPTIVELY ));
84        settings.setString( HttpSettings.SOCKET_TIMEOUT, httpValues.get( SOCKET_TIMEOUT ));
85        settings.setString( HttpSettings.ENCODED_URLS, httpValues.get( ENCODED_URLS ));
86        settings.setString( HttpSettings.MAX_RESPONSE_SIZE, httpValues.get( MAX_RESPONSE_SIZE ));
87        settings.setString( HttpSettings.INCLUDE_REQUEST_IN_TIME_TAKEN, httpValues.get( INCLUDE_REQUEST_IN_TIME_TAKEN ));
88        settings.setString( HttpSettings.INCLUDE_RESPONSE_IN_TIME_TAKEN, httpValues.get( INCLUDE_RESPONSE_IN_TIME_TAKEN ));
89        settings.setString( HttpSettings.MAX_CONNECTIONS_PER_HOST, httpValues.get( MAX_CONNECTIONS_PER_HOST ));
90        settings.setString( HttpSettings.MAX_TOTAL_CONNECTIONS, httpValues.get( MAX_TOTAL_CONNECTIONS ));
91        settings.setString( HttpSettings.BIND_ADDRESS, httpValues.get( BIND_ADDRESS ));
92  	}
93  
94  	public void setFormValues(Settings settings)
95  	{
96  		getForm().setValues( getValues(settings) ); 
97  	}
98  
99  	public StringToStringMap getValues(Settings settings)
100 	{
101 		StringToStringMap httpValues = new StringToStringMap();
102       httpValues.put( USER_AGENT_HEADER, settings.getString( HttpSettings.USER_AGENT, null ));
103       httpValues.put( CLOSE_CONNECTIONS_AFTER_REQUEST, settings.getString( HttpSettings.CLOSE_CONNECTIONS, null  ));
104       httpValues.put( AUTHENTICATE_PREEMPTIVELY, settings.getString( HttpSettings.AUTHENTICATE_PREEMPTIVELY, null ));
105       httpValues.put( INCLUDE_REQUEST_IN_TIME_TAKEN, settings.getString( HttpSettings.INCLUDE_REQUEST_IN_TIME_TAKEN, null ));
106       httpValues.put( INCLUDE_RESPONSE_IN_TIME_TAKEN, settings.getString( HttpSettings.INCLUDE_RESPONSE_IN_TIME_TAKEN, null ));
107       httpValues.put( SOCKET_TIMEOUT, settings.getString( HttpSettings.SOCKET_TIMEOUT, null ));
108       httpValues.put( ENCODED_URLS, settings.getString( HttpSettings.ENCODED_URLS, null ));
109       httpValues.put( MAX_RESPONSE_SIZE, settings.getString( HttpSettings.MAX_RESPONSE_SIZE, "0" ));
110       httpValues.put( MAX_CONNECTIONS_PER_HOST, settings.getString( HttpSettings.MAX_CONNECTIONS_PER_HOST, "500" ));
111       httpValues.put( MAX_TOTAL_CONNECTIONS, settings.getString( HttpSettings.MAX_TOTAL_CONNECTIONS, "2000" ));
112       httpValues.put( BIND_ADDRESS, settings.getString( HttpSettings.BIND_ADDRESS, "" ));
113       return httpValues;
114 	}
115 
116 	public String getTitle()
117 	{
118 		return title;
119 	}
120 }