1
2
3
4
5
6
7
8
9
10
11
12
13 package com.eviware.soapui.impl.wsdl.actions.request;
14
15 import java.awt.event.ActionEvent;
16 import java.io.StringReader;
17 import java.io.StringWriter;
18
19 import javax.swing.AbstractAction;
20 import javax.xml.parsers.DocumentBuilder;
21 import javax.xml.parsers.DocumentBuilderFactory;
22
23 import org.apache.ws.security.message.WSSecHeader;
24 import org.apache.ws.security.message.WSSecTimestamp;
25 import org.w3c.dom.Document;
26 import org.xml.sax.InputSource;
27
28 import com.eviware.soapui.impl.wsdl.WsdlRequest;
29 import com.eviware.soapui.support.UISupport;
30 import com.eviware.soapui.support.xml.XmlUtils;
31
32 /***
33 * Prompts to add a WSS Timestamp Token to the specified WsdlRequests requestContent
34 *
35 * @author Ole.Matzura
36 */
37
38 public class AddWSTimestampAction extends AbstractAction
39 {
40 private final WsdlRequest request;
41
42 public AddWSTimestampAction( WsdlRequest request )
43 {
44 super( "Add WS-Timestamp" );
45 this.request = request;
46 }
47
48 public void actionPerformed(ActionEvent e)
49 {
50 String req = request.getRequestContent();
51
52 try
53 {
54 String ttlString = UISupport.prompt( "Add WS-Timestamp", "Specify Time-To-Live value", "60" );
55 if( ttlString == null )
56 return;
57
58 int ttl = 0;
59 try
60 {
61 ttl = Integer.parseInt(ttlString);
62 }
63 catch (Exception ex)
64 {
65 }
66
67 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
68 dbf.setNamespaceAware( true );
69 DocumentBuilder db = dbf.newDocumentBuilder();
70 Document doc = db.parse( new InputSource( new StringReader( req )));
71 WSSecTimestamp addTimestamp = new WSSecTimestamp();
72 addTimestamp.setTimeToLive( ttl );
73
74 StringWriter writer = new StringWriter();
75 WSSecHeader secHeader = new WSSecHeader();
76 secHeader.insertSecurityHeader( doc );
77 XmlUtils.serializePretty( addTimestamp.build( doc, secHeader ), writer );
78 request.setRequestContent( writer.toString() );
79 }
80 catch ( Exception e1)
81 {
82 UISupport.showErrorMessage( e1 );
83 }
84 }
85 }