View Javadoc

1   /*
2    *  soapUI, copyright (C) 2006 eviware.com 
3    *
4    *  soapUI is free software; you can redistribute it and/or modify it under the 
5    *  terms of the GNU Lesser General Public License as published by the Free Software Foundation; 
6    *  either version 2.1 of the License, or (at your option) any later version.
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  public class HttpPrefs implements Prefs
21  {
22     public static final String AUTHENTICATE_PREEMPTIVELY = "Authenticate Preemptively";  
23     public static final String INCLUDE_REQUEST_IN_TIME_TAKEN = "Include request in time taken";
24     public static final String INCLUDE_RESPONSE_IN_TIME_TAKEN = "Include response in time taken";
25     public static final String CLOSE_CONNECTIONS_AFTER_REQUEST = "Close connections after request";
26     public static final String USER_AGENT_HEADER = "User-Agent Header";
27     public static final String SOCKET_TIMEOUT = "Socket Timeout";  
28     public static final String MAX_RESPONSE_SIZE = "Max response size";
29  	public static final String ENCODED_URLS = "Pre-encoded Endpoints";
30     
31     private SimpleForm httpForm;
32  	private final String title;
33     
34     public HttpPrefs( String title )
35     {
36  		this.title = title;
37     }
38     
39  	public SimpleForm getForm()
40  	{
41  		if( httpForm == null )
42  		{
43  			httpForm = new SimpleForm();
44  			httpForm.addSpace( 5 );
45  			httpForm.appendTextField( HttpPrefs.USER_AGENT_HEADER, "User-Agent HTTP header to send, blank will send default" );
46  			httpForm.appendCheckBox( HttpPrefs.CLOSE_CONNECTIONS_AFTER_REQUEST, "Closes the HTTP connection after each SOAP request", true );
47  			httpForm.appendCheckBox( HttpPrefs.AUTHENTICATE_PREEMPTIVELY, "Adds authentication information to outgoing request", true );
48  			httpForm.appendCheckBox( HttpPrefs.INCLUDE_REQUEST_IN_TIME_TAKEN, "Includes the time it took to write the request in time-taken", true );
49  			httpForm.appendCheckBox( HttpPrefs.INCLUDE_RESPONSE_IN_TIME_TAKEN, "Includes the time it took to read the entire response in time-taken", true );
50  			httpForm.appendCheckBox( HttpPrefs.ENCODED_URLS, "Do not URL-escape service endpoints", true );
51  			httpForm.appendTextField( HttpPrefs.SOCKET_TIMEOUT, "Socket timeout in milliseconds" );
52  			httpForm.appendTextField( HttpPrefs.MAX_RESPONSE_SIZE, "Maximum size to read from response (0 = no limit)" );
53  			httpForm.addSpace( 5 );
54  		}
55  		
56  		return httpForm;
57  	}
58  
59  	public void getFormValues(Settings settings)
60  	{
61  		StringToStringMap httpValues = new StringToStringMap();
62  		httpForm.getValues( httpValues );
63  		storeValues(httpValues, settings);
64  	}
65  	
66  	public void storeValues(StringToStringMap httpValues, Settings settings)
67  	{
68  		settings.setString( HttpSettings.USER_AGENT, httpValues.get( USER_AGENT_HEADER ));
69        settings.setString( HttpSettings.CLOSE_CONNECTIONS, httpValues.get( CLOSE_CONNECTIONS_AFTER_REQUEST ));
70        settings.setString( HttpSettings.AUTHENTICATE_PREEMPTIVELY, httpValues.get( AUTHENTICATE_PREEMPTIVELY ));
71        settings.setString( HttpSettings.SOCKET_TIMEOUT, httpValues.get( SOCKET_TIMEOUT ));
72        settings.setString( HttpSettings.ENCODED_URLS, httpValues.get( ENCODED_URLS ));
73        settings.setString( HttpSettings.MAX_RESPONSE_SIZE, httpValues.get( MAX_RESPONSE_SIZE ));
74        settings.setString( HttpSettings.INCLUDE_REQUEST_IN_TIME_TAKEN, httpValues.get( INCLUDE_REQUEST_IN_TIME_TAKEN ));
75        settings.setString( HttpSettings.INCLUDE_RESPONSE_IN_TIME_TAKEN, httpValues.get( INCLUDE_RESPONSE_IN_TIME_TAKEN ));
76  	}
77  
78  	public void setFormValues(Settings settings)
79  	{
80  		getForm().setValues( getValues(settings) ); 
81  	}
82  
83  	public StringToStringMap getValues(Settings settings)
84  	{
85  		StringToStringMap httpValues = new StringToStringMap();
86        httpValues.put( USER_AGENT_HEADER, settings.getString( HttpSettings.USER_AGENT, null ));
87        httpValues.put( CLOSE_CONNECTIONS_AFTER_REQUEST, settings.getString( HttpSettings.CLOSE_CONNECTIONS, null  ));
88        httpValues.put( AUTHENTICATE_PREEMPTIVELY, settings.getString( HttpSettings.AUTHENTICATE_PREEMPTIVELY, null ));
89        httpValues.put( INCLUDE_REQUEST_IN_TIME_TAKEN, settings.getString( HttpSettings.INCLUDE_REQUEST_IN_TIME_TAKEN, null ));
90        httpValues.put( INCLUDE_RESPONSE_IN_TIME_TAKEN, settings.getString( HttpSettings.INCLUDE_RESPONSE_IN_TIME_TAKEN, null ));
91        httpValues.put( SOCKET_TIMEOUT, settings.getString( HttpSettings.SOCKET_TIMEOUT, null ));
92        httpValues.put( ENCODED_URLS, settings.getString( HttpSettings.ENCODED_URLS, null ));
93        httpValues.put( MAX_RESPONSE_SIZE, settings.getString( HttpSettings.MAX_RESPONSE_SIZE, "0" ));
94        return httpValues;
95  	}
96  
97  	public String getTitle()
98  	{
99  		return title;
100 	}
101 }