From ba7d4af2433eb1c1460b61f88eb1baad8d9369a3 Mon Sep 17 00:00:00 2001 From: jfarcand Date: Mon, 12 Mar 2012 14:36:33 -0400 Subject: [PATCH] More fix for #220 [runtime] Allow WebSocketProtocol to dispatch asynchronously --- .../org/atmosphere/cpr/AtmosphereRequest.java | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/modules/cpr/src/main/java/org/atmosphere/cpr/AtmosphereRequest.java b/modules/cpr/src/main/java/org/atmosphere/cpr/AtmosphereRequest.java index bdfd4adda5b..6a3dbe76d7e 100644 --- a/modules/cpr/src/main/java/org/atmosphere/cpr/AtmosphereRequest.java +++ b/modules/cpr/src/main/java/org/atmosphere/cpr/AtmosphereRequest.java @@ -337,32 +337,40 @@ public HttpSession getSession(boolean create) { @Override public String getRemoteAddr() { - return b.remoteAddr; + return b.request != null ? b.request.getRemoteAddr() : b.remoteAddr; } @Override public String getRemoteHost() { - return b.remoteHost; + return b.request != null ? b.request.getRemoteHost() : b.remoteHost; } @Override public int getRemotePort() { - return b.remotePort; + return b.request != null ? b.request.getRemotePort() : b.remotePort; } @Override public String getLocalName() { - return b.localName; + return b.request != null ? b.request.getLocalName() : b.localName; } @Override public int getLocalPort() { - return b.localPort; + return b.request != null ? b.request.getLocalPort() : b.localPort; } @Override public String getLocalAddr() { - return b.localAddr; + return b.request != null ? b.request.getLocalAddr() : b.localAddr; + } + + /** + * Dispatch the request asynchronously to container. The default is false. + * @return true to dispatch asynchronously the request to container. + */ + public boolean dispatchRequestAsynchronously(){ + return b.dispatchRequestAsynchronously; } /** @@ -433,6 +441,7 @@ public final static class Builder { private String localAddr = ""; private String localName = ""; private int localPort = 0; + private boolean dispatchRequestAsynchronously; public Builder() { } @@ -442,6 +451,11 @@ public Builder headers(Map headers) { return this; } + public Builder dispatchRequestAsynchronously(boolean dispatchRequestAsynchronously) { + this.dispatchRequestAsynchronously = dispatchRequestAsynchronously; + return this; + } + public Builder remoteAddr(String remoteAddr) { this.remoteAddr = remoteAddr; return this;