}
public void open()
throws IOException, XFireException
{
MessageContext context = getMessageContext();
createClient();
// Pull the HttpState from the context if possible. Otherwise create
// one in the ThreadLocal
state = getHttpState();
postMethod = new PostMethod(getUri());
if (Boolean.valueOf((String) context.getContextualProperty(DISABLE_KEEP_ALIVE)).booleanValue()) {
postMethod.setRequestHeader("Connection", "Close");
}
// set the username and password if present
String username = (String) context.getContextualProperty(Channel.USERNAME);
if (username != null)
{
client.getParams().setAuthenticationPreemptive(true);
String password = (String) context.getContextualProperty(Channel.PASSWORD);
state.setCredentials(AuthScope.ANY, getCredentials(username, password));
}
if (getSoapAction() != null)
{
postMethod.setRequestHeader("SOAPAction", getQuotedSoapAction());
}
OutMessage message = getMessage();
boolean mtomEnabled = Boolean.valueOf((String) context.getContextualProperty(SoapConstants.MTOM_ENABLED)).booleanValue();
Attachments atts = message.getAttachments();
if (mtomEnabled || atts != null)
{
if (atts == null)
{
atts = new JavaMailAttachments();
message.setAttachments(atts);
}
source = new OutMessageDataSource(context, message);
DataHandler soapHandler = new DataHandler(source);
atts.setSoapContentType(HttpChannel.getSoapMimeType(message, false));
atts.setSoapMessage(new SimpleAttachment(source.getName(), soapHandler));
postMethod.setRequestHeader("Content-Type", atts.getContentType());
}
else
{
postMethod.setRequestHeader("Content-Type", HttpChannel.getSoapMimeType(getMessage(), true));
}
if (isGzipResponseEnabled(context))
{
postMethod.setRequestHeader("Accept-Encoding", GZIP_CONTENT_ENCODING);
}
if (isGzipRequestEnabled(context))
{
postMethod.setRequestHeader("Content-Encoding", GZIP_CONTENT_ENCODING);
}
Map headersMap = (Map) context.getContextualProperty(HTTP_HEADERS);
if (headersMap != null) {
for (Iterator iter = headersMap.entrySet().iterator(); iter.hasNext();) {
Map.Entry entry = (Entry) iter.next();
postMethod.addRequestHeader(entry.getKey().toString(), entry.getValue().toString());
}