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.filters;
14  
15  import org.apache.commons.httpclient.Header;
16  
17  import com.eviware.soapui.impl.settings.XmlBeansSettingsImpl;
18  import com.eviware.soapui.impl.wsdl.WsdlRequest;
19  import com.eviware.soapui.impl.wsdl.submit.transports.http.BaseHttpRequestTransport;
20  import com.eviware.soapui.impl.wsdl.submit.transports.http.support.attachments.WsdlMimeMessageResponse;
21  import com.eviware.soapui.impl.wsdl.submit.transports.http.support.attachments.WsdlSinglePartHttpResponse;
22  import com.eviware.soapui.impl.wsdl.submit.transports.http.support.methods.ExtendedPostMethod;
23  import com.eviware.soapui.model.iface.Response;
24  import com.eviware.soapui.model.iface.SubmitContext;
25  
26  public class WsdlPackagingResponseFilter extends AbstractRequestFilter
27  {
28  	@Override
29  	public void afterWsdlRequest( SubmitContext context, WsdlRequest request )
30  	{
31  		ExtendedPostMethod postMethod = ( ExtendedPostMethod )context.getProperty( BaseHttpRequestTransport.HTTP_METHOD );
32  		String requestContent = ( String )context.getProperty( BaseHttpRequestTransport.REQUEST_CONTENT );
33  		XmlBeansSettingsImpl settings = request.getSettings();
34  
35  		// check content-type for multiplart
36  		Header responseContentTypeHeader = postMethod.getResponseHeader( "Content-Type" );
37  		Response response = null;
38  
39  		if( !settings.getBoolean( WsdlRequest.INLINE_RESPONSE_ATTACHMENTS ) && responseContentTypeHeader != null
40  				&& responseContentTypeHeader.getValue().toUpperCase().startsWith( "MULTIPART" ) )
41  		{
42  			response = new WsdlMimeMessageResponse( request, postMethod, requestContent, context );
43  		}
44  		else
45  		{
46  			response = new WsdlSinglePartHttpResponse( request, postMethod, requestContent, context );
47  		}
48  
49  		context.setProperty( BaseHttpRequestTransport.RESPONSE, response );
50  	}
51  }