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.actions.mockresponse;
14  
15  import java.awt.event.ActionEvent;
16  import java.io.StringWriter;
17  
18  import javax.swing.AbstractAction;
19  
20  import org.w3c.dom.Document;
21  
22  import com.eviware.soapui.impl.wsdl.mock.WsdlMockResponse;
23  import com.eviware.soapui.impl.wsdl.support.wss.OutgoingWss;
24  import com.eviware.soapui.model.propertyexpansion.DefaultPropertyExpansionContext;
25  import com.eviware.soapui.support.UISupport;
26  import com.eviware.soapui.support.xml.XmlUtils;
27  
28  /***
29   * Prompts to add a WSS Username Token to the specified WsdlRequests
30   * requestContent
31   * 
32   * @author Ole.Matzura
33   */
34  
35  public class ApplyOutgoingWSSToMockResponseAction extends AbstractAction
36  {
37  	private final WsdlMockResponse mockResponse;
38  	private final OutgoingWss outgoing;
39  
40  	public ApplyOutgoingWSSToMockResponseAction( WsdlMockResponse mockResponse, OutgoingWss outgoing )
41  	{
42  		super( outgoing.getName() );
43  		this.mockResponse = mockResponse;
44  		this.outgoing = outgoing;
45  	}
46  
47  	public void actionPerformed( ActionEvent e )
48  	{
49  		String req = mockResponse.getResponseContent();
50  
51  		try
52  		{
53  			UISupport.setHourglassCursor();
54  			Document dom = XmlUtils.parseXml( req );
55  			outgoing.processOutgoing( dom, new DefaultPropertyExpansionContext( mockResponse ) );
56  			StringWriter writer = new StringWriter();
57  			XmlUtils.serialize( dom, writer );
58  			mockResponse.setResponseContent( writer.toString() );
59  		}
60  		catch( Exception e1 )
61  		{
62  			UISupport.showErrorMessage( e1 );
63  		}
64  		finally
65  		{
66  			UISupport.resetCursor();
67  		}
68  	}
69  }