{
String userAgent = (String) userAgentObj;
isRemotingUserAgent = userAgent.startsWith("JBossRemoting");
}
InvocationRequest invocationRequest = versionedRead(req, request, response, version);
if (invocationRequest.getRequestPayload() == null)
invocationRequest.setRequestPayload(new HashMap());
MessageBytes remoteAddressMB = req.remoteAddr();
if (remoteAddressMB != null)
{
String remoteAddressString = remoteAddressMB.toString();
InetAddress remoteAddress = InetAddress.getByName(remoteAddressString);
invocationRequest.getRequestPayload().put(Remoting.CLIENT_ADDRESS, remoteAddress);
}
else
{
log.debug("unable to retrieve client address from coyote transport layer");
}
// FIXME: OPTIONS method handling ?
try
{
// call transport on the subclass, get the result to handback
responseObject = invoke(invocationRequest);
}
catch(Throwable ex)
{
log.debug("Error thrown calling invoke on server invoker.", ex);
responseObject = ex;
isError = true;
}
//Start with response code of 204 (no content), then if is a return from handler, change to 200 (ok)
int status;
String message = "";
if(responseObject != null)
{
if(isError)
{
status = 500;
message = "JBoss Remoting: Error occurred within target application.";
}
else
{
status = 200;
message = "OK";
}
}
else
{
if (isRemotingUserAgent && !req.method().equals("HEAD"))
{
status = 200;
message = "OK";
}
else
{
status = 204;
message = "No Content";
}
}
// extract response code/message if exists
Map responseMap = invocationRequest.getReturnPayload();
if(responseMap != null)
{
Integer handlerStatus = (Integer) responseMap.get(HTTPMetadataConstants.RESPONSE_CODE);
if(handlerStatus != null)
{
status = handlerStatus.intValue();
}
String handlerMessage = (String) responseMap.get(HTTPMetadataConstants.RESPONSE_CODE_MESSAGE);
if(handlerMessage != null)
{
message = handlerMessage;
}
}
res.setStatus(status);
res.setMessage(message);
if (isRemotingUserAgent && ((Boolean)receivedInvocationRequest.get()).booleanValue())
{
responseMap = ((ResponseMap) responseMap).getMap();
responseObject = new InvocationResponse(invocationRequest.getSessionId(),
responseObject, isError, responseMap);
}
if(responseObject != null)
{