01: /*
02: * soapUI, copyright (C) 2004-2007 eviware.com
03: *
04: * soapUI is free software; you can redistribute it and/or modify it under the
05: * terms of version 2.1 of the GNU Lesser General Public License as published by
06: * the Free Software Foundation.
07: *
08: * soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
09: * 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.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: private final WsdlRequest request;
40:
41: public AddWSTimestampAction(WsdlRequest request) {
42: super ("Add WS-Timestamp");
43: this .request = request;
44: }
45:
46: public void actionPerformed(ActionEvent e) {
47: String req = request.getRequestContent();
48:
49: try {
50: String ttlString = UISupport.prompt("Add WS-Timestamp",
51: "Specify Time-To-Live value", "60");
52: if (ttlString == null)
53: return;
54:
55: int ttl = 0;
56: try {
57: ttl = Integer.parseInt(ttlString);
58: } catch (Exception ex) {
59: }
60:
61: DocumentBuilderFactory dbf = DocumentBuilderFactory
62: .newInstance();
63: dbf.setNamespaceAware(true);
64: DocumentBuilder db = dbf.newDocumentBuilder();
65: Document doc = db.parse(new InputSource(new StringReader(
66: req)));
67: WSSecTimestamp addTimestamp = new WSSecTimestamp();
68: addTimestamp.setTimeToLive(ttl);
69:
70: StringWriter writer = new StringWriter();
71: WSSecHeader secHeader = new WSSecHeader();
72: secHeader.insertSecurityHeader(doc);
73: XmlUtils.serializePretty(
74: addTimestamp.build(doc, secHeader), writer);
75: request.setRequestContent(writer.toString());
76: } catch (Exception e1) {
77: UISupport.showErrorMessage(e1);
78: }
79: }
80: }
|