View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2009 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.submit.transports.http.support.attachments;
14  
15  import java.io.StringWriter;
16  import java.util.Vector;
17  
18  import org.w3c.dom.Document;
19  
20  import com.eviware.soapui.impl.wsdl.WsdlRequest;
21  import com.eviware.soapui.impl.wsdl.submit.filters.WssRequestFilter;
22  import com.eviware.soapui.impl.wsdl.submit.transports.http.ExtendedHttpMethod;
23  import com.eviware.soapui.impl.wsdl.submit.transports.http.SinglePartHttpResponse;
24  import com.eviware.soapui.impl.wsdl.submit.transports.http.WsdlResponse;
25  import com.eviware.soapui.impl.wsdl.support.wss.IncomingWss;
26  import com.eviware.soapui.model.propertyexpansion.PropertyExpansionContext;
27  import com.eviware.soapui.support.xml.XmlUtils;
28  
29  public class WsdlSinglePartHttpResponse extends SinglePartHttpResponse implements WsdlResponse
30  {
31  	private Vector<Object> wssResult;
32  
33  	public WsdlSinglePartHttpResponse( WsdlRequest wsdlRequest, ExtendedHttpMethod postMethod, String requestContent,
34  			PropertyExpansionContext context )
35  	{
36  		super( wsdlRequest, postMethod, requestContent, context );
37  
38  		processIncomingWss( wsdlRequest, context );
39  	}
40  
41  	private void processIncomingWss( WsdlRequest wsdlRequest, PropertyExpansionContext context )
42  	{
43  		IncomingWss incomingWss = ( IncomingWss )context.getProperty( WssRequestFilter.INCOMING_WSS_PROPERTY );
44  		if( incomingWss != null )
45  		{
46  			try
47  			{
48  				Document document = XmlUtils.parseXml( getResponseContent() );
49  				wssResult = incomingWss.processIncoming( document, context );
50  				if( wssResult != null && wssResult.size() > 0 )
51  				{
52  					StringWriter writer = new StringWriter();
53  					XmlUtils.serializePretty( document, writer );
54  					setResponseContent( writer.toString() );
55  				}
56  			}
57  			catch( Exception e )
58  			{
59  				if( wssResult == null )
60  					wssResult = new Vector<Object>();
61  				wssResult.add( e );
62  			}
63  		}
64  	}
65  
66  	public Vector<?> getWssResult()
67  	{
68  		return wssResult;
69  	}
70  
71  	@Override
72  	public WsdlRequest getRequest()
73  	{
74  		return ( WsdlRequest )super.getRequest();
75  	}
76  }