Skip to content

Commit

Permalink
Fix for #1
Browse files Browse the repository at this point in the history
  • Loading branch information
jfarcand committed Apr 23, 2013
1 parent f85908c commit 6d9d479
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions module/src/main/java/org/atmosphere/play/AtmosphereUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

import org.atmosphere.cpr.AtmosphereRequest;
import org.jboss.netty.handler.codec.http.HttpHeaders;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import play.mvc.Http;

import java.io.ByteArrayInputStream;
Expand All @@ -26,6 +28,8 @@

public class AtmosphereUtils {

private static Logger logger = LoggerFactory.getLogger(AtmosphereUtils.class);

public final static AtmosphereRequest request(final Http.Request request) throws Throwable {
final String base = getBaseUri(request);
final URI requestUri = new URI(base.substring(0, base.length() - 1) + request.uri());
Expand Down Expand Up @@ -69,7 +73,16 @@ public final static AtmosphereRequest request(final Http.Request request) throws
}
}

URI uri = URI.create(request.remoteAddress());
URI uri = null;
try {
URI.create(request.remoteAddress());
} catch (IllegalArgumentException e) {
logger.trace("", e);
}

int port = uri == null ? 0 : uri.getPort();
String uriString = uri == null ? request.remoteAddress() : uri.toString();
String host = uri == null ? request.remoteAddress() : uri.getHost();
AtmosphereRequest.Builder requestBuilder = new AtmosphereRequest.Builder();
AtmosphereRequest r = requestBuilder.requestURI(url.substring(l))
.requestURL(u)
Expand All @@ -81,9 +94,9 @@ public final static AtmosphereRequest request(final Http.Request request) throws
.attributes(attributes)
.servletPath("")
.queryStrings(qs)
.remotePort(uri.getPort())
.remoteAddr(uri.toString())
.remoteHost(uri.getHost())
.remotePort(port)
.remoteAddr(uriString)
.remoteHost(host)
// .localPort(((InetSocketAddress) ctx.getChannel().getLocalAddress()).getPort())
// .localAddr(((InetSocketAddress) ctx.getChannel().getLocalAddress()).getAddress().getHostAddress())
// .localName(((InetSocketAddress) ctx.getChannel().getLocalAddress()).getHostName())
Expand Down

0 comments on commit 6d9d479

Please sign in to comment.