{
serviceURL = new URL(url) ;
}
catch (final MalformedURLException murle)
{
throw new SoapFault10(SoapFaultType.FAULT_SENDER, WSCLogger.log_mesg.getString("com.arjuna.webservices.transport.http.HttpClient_2")) ;
}
final boolean threadLogEnabled = SoapMessageLogging.isThreadLogEnabled() ;
final String requestContents ;
if (threadLogEnabled)
{
requestContents = serialiseRequest(request) ;
SoapMessageLogging.appendThreadLog(requestContents) ;
}
else
{
requestContents = null ;
}
final HttpURLConnection httpURLConnection ;
try
{
httpURLConnection = (HttpURLConnection)serviceURL.openConnection() ;
}
catch (final ClassCastException cce)
{
throw new SoapFault10(SoapFaultType.FAULT_SENDER, WSCLogger.log_mesg.getString("com.arjuna.webservices.transport.http.HttpClient_3")) ;
}
httpURLConnection.setDoOutput(true) ;
httpURLConnection.setUseCaches(false) ;
final int numHeaders = HTTP_HEADERS.length ;
for(int count = 0 ; count < numHeaders ; count++)
{
final String[] header = HTTP_HEADERS[count] ;
httpURLConnection.setRequestProperty(header[0], header[1]) ;
}
final SoapDetails soapDetails = request.getSoapDetails() ;
final String contentType = HttpUtils.getContentType(soapDetails) ;
httpURLConnection.setRequestProperty(HttpUtils.HTTP_CONTENT_TYPE_HEADER, contentType + HttpUtils.HTTP_DEFAULT_CHARSET_PARAMETER) ;
httpURLConnection.setRequestProperty(HttpUtils.HTTP_ACCEPT_HEADER, contentType) ;
final String requestAction = request.getAction() ;
final String actionValue = (requestAction == null ? "" : requestAction) ;
// KEV - fix action handling for different SOAP versions
httpURLConnection.setRequestProperty(HttpUtils.SOAP_ACTION_HEADER, '"' + actionValue + '"') ;
if (requestContents != null)
{
httpURLConnection.setRequestProperty(HttpUtils.HTTP_CONTENT_LENGTH_HEADER,
Integer.toString(requestContents.length())) ;
}
final int port = serviceURL.getPort() ;
final String host = (port > 0 ? serviceURL.getHost() + ":" + port : serviceURL.getHost()) ;
httpURLConnection.setRequestProperty(HttpUtils.HTTP_HOST_HEADER, host) ;
httpURLConnection.setRequestMethod("POST") ;
httpURLConnection.connect() ;
final OutputStream os = httpURLConnection.getOutputStream() ;
try
{
final PrintWriter writer = new PrintWriter(os) ;
if (requestContents != null)
{
writer.print(requestContents) ;
}
else
{
request.output(writer) ;
}
writer.flush() ;
}
finally
{
os.close() ;
}
final int responseCode = httpURLConnection.getResponseCode() ;
if ((responseCode != HttpURLConnection.HTTP_OK) &&
(responseCode != HttpURLConnection.HTTP_ACCEPTED) &&
(responseCode != HttpURLConnection.HTTP_INTERNAL_ERROR))
{
final String pattern = WSCLogger.log_mesg.getString("com.arjuna.webservices.transport.http.HttpClient_4") ;
final String message = MessageFormat.format(pattern, new Object[] {new Integer(responseCode)}) ;
throw new SoapFault10(SoapFaultType.FAULT_SENDER, message) ;
}
final String fullResponseContentType = httpURLConnection.getContentType() ;
// final String responseContentType = HttpUtils.getContentType(fullResponseContentType) ;
// Ignore responses that aren't the same version of SOAP