return result;
}
private Object checkForLeasePing(HttpURLConnection conn, Object invocation, Map metadata) throws IOException
{
InvocationResponse response = null;
boolean shouldLease = false;
long leasePeriod = -1;
if(invocation != null && invocation instanceof InvocationRequest)
{
InvocationRequest request = (InvocationRequest)invocation;
Object payload = request.getParameter();
// although a bit of a hack, this will determin if first time ping called by client.
if(payload != null && payload instanceof String && "$PING$".equalsIgnoreCase((String)payload) && request.getReturnPayload() != null)
{
try
{
// now know is a ping request, so convert to be a HEAD method call
conn.setDoOutput(false);
conn.setDoInput(true);
conn.setRequestMethod("HEAD");
// set the remoting version
conn.setRequestProperty(HTTPMetadataConstants.REMOTING_VERSION_HEADER, new Integer(Version.getDefaultVersion()).toString());
// set the user agent
conn.setRequestProperty(HTTPMetadataConstants.REMOTING_USER_AGENT, "JBossRemoting - " + Version.VERSION);
conn.setRequestProperty(HTTPMetadataConstants.REMOTING_LEASE_QUERY, "true");
conn.setRequestProperty("sessionId", request.getSessionId());
conn.connect();
//InputStream is = (conn.getResponseCode() < 400) ? conn.getInputStream() : conn.getErrorStream();
Map headers = conn.getHeaderFields();
if(headers != null)
{
Object leasingEnabled = headers.get("LEASING_ENABLED");
if(leasingEnabled != null && leasingEnabled instanceof List)
{
shouldLease = new Boolean((String)((List)leasingEnabled).get(0)).booleanValue();
}
Object leasingPeriod = headers.get("LEASE_PERIOD");
if(leasingPeriod != null && leasingPeriod instanceof List)
{
leasePeriod = new Long((String)((List)leasingPeriod).get(0)).longValue();
}
}
}
catch (IOException e)
{
log.error("Error checking server for lease information.", e);
}
Map p = new HashMap();
p.put("clientLeasePeriod", new Long(leasePeriod));
InvocationResponse innterResponse = new InvocationResponse(null, new Boolean(shouldLease), false, p);
response = new InvocationResponse(null, innterResponse, false, null);
}
}
return response;