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