requestHeaders.add( "Accept-Charset: " + characterEncoding );
}
HttpClient client = new HttpClient( messageURL, requestHeaders );
HttpResponseHeader responseHeaders = client.getResponseHeaders();
if( responseHeaders.getErrorCode() == 200 ) {
// read in message from URL
InputStreamReader isr =
(InputStreamReader)client.getInputStreamReader();
String encoding = isr.getEncoding();
StringBuffer bodyContent = new StringBuffer();
char[] line = new char[1024];
int read = isr.read(line, 0, line.length);
while( read > -1 ) {
bodyContent.append( line, 0, read );
read = isr.read(line, 0, line.length);
}
String msg = bodyContent.toString();
// if a charset has been specified we need to convert from
// the InputStreamReader charset into the specified
// charset
if (characterEncoding != null) {
msg = ContentUtilities.convertEncoding(msg,
encoding,
characterEncoding);
}
String contentType = getContentTypeHeader(
responseHeaders.getHeader("Content-Type"),
characterEncoding);
rawMessage = new ProtocolIndependentMessage(
msg,
contentType,
getAssetMapFromHeaders(responseHeaders),
characterEncoding);
rawMessage.setBaseURL(messageURL);
rawMessage.setMaxFileSize(
getMaxFileSizeFromHeaders( responseHeaders ) );
rawMessage.setMaxMMSize(
getMaxMMSizeFromHeaders( responseHeaders ) );
} else {
throw new MessageException(
localizer.format( "mcs-server-unknown-error",
new Integer( responseHeaders.getErrorCode() ) ) );
}
} catch( Exception e ) {
throw new MessageException( e );
}
return rawMessage;