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.impl.wsdl.support.wss.entries;
14  
15  import javax.swing.JComponent;
16  
17  import org.apache.ws.security.message.WSSecHeader;
18  import org.apache.ws.security.message.WSSecTimestamp;
19  import org.w3c.dom.Document;
20  
21  import com.eviware.soapui.config.WSSEntryConfig;
22  import com.eviware.soapui.impl.wsdl.support.wss.OutgoingWss;
23  import com.eviware.soapui.model.propertyexpansion.PropertyExpansionContext;
24  import com.eviware.soapui.support.components.SimpleBindingForm;
25  import com.eviware.soapui.support.xml.XmlObjectConfigurationBuilder;
26  import com.eviware.soapui.support.xml.XmlObjectConfigurationReader;
27  import com.jgoodies.binding.PresentationModel;
28  
29  public class AddTimestampEntry extends WssEntryBase
30  {
31  	public static final String TYPE = "Timestamp";
32  	
33  	private int timeToLive;
34  
35  	public void init( WSSEntryConfig config, OutgoingWss container )
36  	{
37  		super.init( config, container, TYPE );
38  	}
39  	
40  	@Override
41  	protected JComponent buildUI()
42  	{
43  		SimpleBindingForm form = new SimpleBindingForm( new PresentationModel<AddTimestampEntry>( this ) ); 
44  		form.addSpace(5);
45  		form.appendTextField( "timeToLive", "Time To Live", "Sets the TimeToLive value for the Timestamp Token" );
46  		
47  		return form.getPanel();
48  	}
49  
50  	@Override
51  	protected void load( XmlObjectConfigurationReader reader )
52  	{
53  		timeToLive = reader.readInt( "timeToLive", 0 );
54  	}
55  
56  	@Override
57  	protected void save( XmlObjectConfigurationBuilder builder )
58  	{
59  		builder.add( "timeToLive", timeToLive );
60  	}
61  
62  	public void process( WSSecHeader secHeader, Document doc, PropertyExpansionContext context )
63  	{
64  		if( timeToLive <= 0 )
65  			return;
66  		
67  		WSSecTimestamp timestamp = new WSSecTimestamp();
68  		timestamp.setTimeToLive( timeToLive );
69  		timestamp.build( doc, secHeader );
70  	}
71  	
72  	public String getTimeToLive()
73  	{
74  		return String.valueOf( timeToLive );
75  	}
76  
77  	public void setTimeToLive( String timeToLive )
78  	{
79  		try
80  		{
81  			this.timeToLive = Integer.valueOf( timeToLive );
82  			saveConfig();
83  		}
84  		catch( Exception e )
85  		{
86  		}		
87  	}
88  }