01: /*
02: * soapUI, copyright (C) 2004-2007 eviware.com
03: *
04: * soapUI is free software; you can redistribute it and/or modify it under the
05: * terms of version 2.1 of the GNU Lesser General Public License as published by
06: * the Free Software Foundation.
07: *
08: * soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
09: * 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.URI;
16:
17: import com.eviware.soapui.SoapUI;
18: import com.eviware.soapui.impl.wsdl.WsdlInterface;
19: import com.eviware.soapui.impl.wsdl.WsdlRequest;
20: import com.eviware.soapui.impl.wsdl.submit.RequestFilter;
21: import com.eviware.soapui.impl.wsdl.submit.transports.http.BaseHttpRequestTransport;
22: import com.eviware.soapui.impl.wsdl.submit.transports.http.TimeablePostMethod;
23: import com.eviware.soapui.impl.wsdl.support.soap.SoapVersion;
24: import com.eviware.soapui.model.iface.SubmitContext;
25: import com.eviware.soapui.settings.HttpSettings;
26:
27: /**
28: * RequestFilter that adds SOAP specific headers
29: *
30: * @author Ole.Matzura
31: */
32:
33: public class SoapHeadersRequestFilter implements RequestFilter {
34: public void filterRequest(SubmitContext context,
35: WsdlRequest wsdlRequest) {
36: TimeablePostMethod postMethod = (TimeablePostMethod) context
37: .getProperty(BaseHttpRequestTransport.POST_METHOD);
38:
39: WsdlInterface wsdlInterface = (WsdlInterface) wsdlRequest
40: .getOperation().getInterface();
41: String strURL = wsdlInterface.getEndpointURL(wsdlRequest
42: .getEndpoint());
43: strURL = PropertyExpansionRequestFilter.expandProperties(
44: context, strURL);
45: try {
46: postMethod.setURI(new URI(strURL, wsdlRequest.getSettings()
47: .getBoolean(HttpSettings.ENCODED_URLS)));
48: } catch (Exception e) {
49: SoapUI.logError(e);
50: }
51:
52: // init content-type and encoding
53: String encoding = wsdlRequest.getEncoding();
54:
55: SoapVersion soapVersion = wsdlInterface.getSoapVersion();
56: postMethod.setRequestHeader("Content-Type", soapVersion
57: .getContentTypeHttpHeader(encoding));
58:
59: // set soapaction
60: String soapAction = wsdlRequest.getOperation().getAction();
61: if (soapAction == null || soapAction.length() == 0) {
62: soapAction = "\"\"";
63: } else {
64: soapAction = "\"" + soapAction + "\"";
65: }
66:
67: postMethod.setRequestHeader("SOAPAction", soapAction);
68:
69: }
70: }
|