throws IOException
{
if( log.isDebugEnabled() )
log.debug("COMMIT sending headers " + res + " " + res.getMimeHeaders() );
C2BConverter c2b=(C2BConverter)res.getNote( utfC2bNote );
if( c2b==null ) {
if(System.getSecurityManager() != null) {
try {
c2b = (C2BConverter)
AccessController.doPrivileged(
new PrivilegedExceptionAction () {
public Object run()
throws IOException{
return new C2BConverter( "iso-8859-1" );
}
});
} catch(PrivilegedActionException pae) {
Exception ex = pae.getException();
if(ex instanceof IOException)
throw (IOException)ex;
}
} else {
c2b=new C2BConverter( "iso-8859-1" );
}
res.setNote( utfC2bNote, c2b );
}
MsgContext ep=(MsgContext)res.getNote( epNote );
MsgAjp msg=(MsgAjp)ep.getNote( headersMsgNote );
msg.reset();
msg.appendByte(HandlerRequest.JK_AJP13_SEND_HEADERS);
msg.appendInt( res.getStatus() );
MessageBytes mb=(MessageBytes)ep.getNote( tmpMessageBytesNote );
if( mb==null ) {
mb=MessageBytes.newInstance();
ep.setNote( tmpMessageBytesNote, mb );
}
String message=res.getMessage();
if( message==null ){
if( System.getSecurityManager() != null ) {
message = (String)AccessController.doPrivileged(
new StatusLinePrivilegedAction(res.getStatus()));
} else {
message= HttpMessages.getMessage(res.getStatus());
}
} else {
message = message.replace('\n', ' ').replace('\r', ' ');
}
mb.setString( message );
c2b.convert( mb );
msg.appendBytes(mb);
// XXX add headers
MimeHeaders headers=res.getMimeHeaders();
String contentType = res.getContentType();
if( contentType != null ) {
headers.setValue("Content-Type").setString(contentType);
}
String contentLanguage = res.getContentLanguage();
if( contentLanguage != null ) {
headers.setValue("Content-Language").setString(contentLanguage);
}
int contentLength = res.getContentLength();
if( contentLength >= 0 ) {
headers.setValue("Content-Length").setInt(contentLength);
}
int numHeaders = headers.size();
msg.appendInt(numHeaders);
for( int i=0; i<numHeaders; i++ ) {
MessageBytes hN=headers.getName(i);
// no header to sc conversion - there's little benefit
// on this direction
c2b.convert ( hN );
msg.appendBytes( hN );
MessageBytes hV=headers.getValue(i);
c2b.convert( hV );
msg.appendBytes( hV );
}
ep.setType( JkHandler.HANDLE_SEND_PACKET );
ep.getSource().send( msg, ep );
}