View Javadoc

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