Skip to content

Commit

Permalink
use 2.0.0-CR1 methods
Browse files Browse the repository at this point in the history
  • Loading branch information
nectarine committed Jun 19, 2013
1 parent d5a11a6 commit 17d86a9
Show file tree
Hide file tree
Showing 16 changed files with 141 additions and 124 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.nhncorp.mods.socket.io.common;

import org.jboss.netty.channel.Channel;
import io.netty.channel.Channel;
import org.vertx.java.core.http.HttpServerRequest;
import org.vertx.java.core.http.impl.AbstractConnection;
import org.vertx.java.core.http.impl.DefaultHttpServerRequest;
Expand All @@ -12,6 +12,7 @@

/**
* @author Keesun Baik
* @
*/
public class RequestUtils {

Expand All @@ -23,7 +24,7 @@ public static String getRemoteAddress(HttpServerRequest req) {
Channel channel = (Channel)getPrivateMember(conn, "channel", ConnectionBase.class);

if(channel != null) {
SocketAddress remoteAddress = channel.getRemoteAddress();
SocketAddress remoteAddress = channel.remoteAddress();
InetSocketAddress address = (InetSocketAddress) remoteAddress;
host = address.getHostString();
}
Expand Down
15 changes: 8 additions & 7 deletions src/main/java/com/nhncorp/mods/socket/io/impl/ClientData.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.nhncorp.mods.socket.io.impl;

import com.nhncorp.mods.socket.io.impl.handlers.StaticHandler;
import org.vertx.java.core.MultiMap;
import org.vertx.java.core.http.HttpServerRequest;
import org.vertx.java.core.http.ServerWebSocket;

Expand All @@ -13,8 +14,8 @@ public class ClientData {

private String namespace;
private String query;
private Map<String, String> headers;
private Map<String, String> params;
private MultiMap headers;
private MultiMap params;
private String path;
private int protocol;
private String transport;
Expand All @@ -27,10 +28,10 @@ public class ClientData {
public ClientData(String namespace, HttpServerRequest req) {
this.namespace = namespace;
this.request = req;
this.query = req.query;
this.query = req.query();
this.headers = req.headers();
this.params = req.params();
this.path = req.path.substring(namespace.length());
this.path = req.path().substring(namespace.length());
this.isStatic = StaticHandler.has(this.path);

if(!isStatic) {
Expand All @@ -43,7 +44,7 @@ public ClientData(String namespace, HttpServerRequest req) {
}

public ClientData(ServerWebSocket socket) {
String path = socket.path;
String path = socket.path();
String[] pieces = path.substring(1).split("/");

if(pieces.length > 1) this.protocol = Integer.parseInt(pieces[1]);
Expand All @@ -57,7 +58,7 @@ public String getQuery() {
return query;
}

public Map<String, String> getHeaders() {
public MultiMap getHeaders() {
return headers;
}

Expand All @@ -81,7 +82,7 @@ public boolean isStatic() {
return isStatic;
}

public Map<String, String> getParams() {
public MultiMap getParams() {
return params;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ public void on(String event, final Handler<JsonObject> handler) {
String address = id + ":" + namespace.getName() + ":" + event;
Handler<Message<JsonObject>> localHandler = new Handler<Message<JsonObject>>() {
public void handle(Message<JsonObject> event) {
handler.handle(event.body);
handler.handle(event.body());
}
};
vertx.eventBus().registerHandler(address, localHandler);
Expand Down
17 changes: 9 additions & 8 deletions src/main/java/com/nhncorp/mods/socket/io/impl/HandshakeData.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.nhncorp.mods.socket.io.impl;

import org.vertx.java.core.MultiMap;
import org.vertx.java.core.json.JsonObject;
import org.vertx.java.core.shareddata.Shareable;

Expand All @@ -17,7 +18,7 @@
public class HandshakeData extends JsonObject implements Shareable {

// headers: req.headers // <Object> the headers of the request
private Map<String, String> headers;
private MultiMap headers;
// time: (new Date) +'' // <String> date time of the connection
private String time;
// address: socket.address() // <Object> remoteAddress and remotePort object
Expand All @@ -31,7 +32,7 @@ public class HandshakeData extends JsonObject implements Shareable {
// url: request.url // <String> the entrance path of the request
private String url;
// query: data.query // <Object> the result of url.parse().query or a empty object
private Map<String, String> queryParams;
private MultiMap queryParams;

/**
* @since 2013.01.18
Expand All @@ -43,13 +44,13 @@ public HandshakeData(ClientData clientData) {
this.headers = clientData.getHeaders();
this.time = now.toString();
this.xdomain = clientData.getHeaders().get("Origin") != null;
this.secure = clientData.getRequest().uri.contains("https");
this.secure = clientData.getRequest().uri().contains("https");
this.issued = now.getTime();
this.url = clientData.getRequest().uri;
this.url = clientData.getRequest().uri();
this.queryParams = clientData.getParams();
}

public Map<String, String> getHeaders() {
public MultiMap getHeaders() {
return headers;
}

Expand Down Expand Up @@ -77,11 +78,11 @@ public String getUrl() {
return url;
}

public Map<String, String> getQueryParams() {
public MultiMap getQueryParams() {
return queryParams;
}

public void setHeaders(Map<String, String> headers) {
public void setHeaders(MultiMap headers) {
this.headers = headers;
}

Expand Down Expand Up @@ -109,7 +110,7 @@ public void setUrl(String url) {
this.url = url;
}

public void setQueryParams(Map<String, String> queryParams) {
public void setQueryParams(MultiMap queryParams) {
this.queryParams = queryParams;
}

Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/nhncorp/mods/socket/io/impl/Manager.java
Original file line number Diff line number Diff line change
Expand Up @@ -165,16 +165,16 @@ public void writeError(HttpServerRequest req, int status, String message) {
if(req == null) {
return;
}
req.response.statusCode = status;
req.response.end(message);
req.response().setStatusCode(status);
req.response().end(message);
}

public void writeError(HttpServerRequest req, Exception e) {
if(req == null) {
return;
}
req.response.statusCode = 500;
req.response.end("handshake error");
req.response().setStatusCode(500);
req.response().end("handshake error");
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/nhncorp/mods/socket/io/impl/Transport.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ protected Transport(Manager manager, ClientData clientData) {
*/
protected void handleRequest() {
if(request != null) {
log.debug("setting request " + request.method + " " + request.uri);
log.debug("setting request " + request.method() + " " + request.uri());
}

if(clientData.getSocket() != null || request.method.toUpperCase().equals("GET")) {
if(clientData.getSocket() != null || request.method().toUpperCase().equals("GET")) {
// this.socket = req.socket;
this.isOpen = true;
this.isDrained = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.nhncorp.mods.socket.io.impl.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.vertx.java.core.MultiMap;
import org.vertx.java.core.http.HttpServerRequest;

import java.util.Map;
Expand Down Expand Up @@ -36,10 +37,10 @@ public void handle(final ClientData clientData) {
final Settings settings = manager.getSettings();

log.trace("In handshake handler");
Map<String, String> reqHeaders = request.headers();
final Map<String, Object> resHeaders = request.response.headers();
MultiMap reqHeaders = request.headers();
final MultiMap resHeaders = request.response().headers();
String reqOrigin = reqHeaders.get("Origin");
resHeaders.put("CONTENT_TYPE", "text/plain; charset=UTF-8");
resHeaders.add("CONTENT_TYPE", "text/plain; charset=UTF-8");

if (!this.verifyOrigin(reqOrigin)) {
manager.writeError(request, 403, "handshake bad origin");
Expand All @@ -50,8 +51,8 @@ public void handle(final ClientData clientData) {

if (reqOrigin != null) {
// https://developer.mozilla.org/En/HTTP_Access_Control
resHeaders.put("Access-Control-Allow-Origin", reqOrigin);
resHeaders.put("Access-Control-Allow-Credentials", "true");
resHeaders.add("Access-Control-Allow-Origin", reqOrigin);
resHeaders.add("Access-Control-Allow-Credentials", "true");
}

authorize(request, handshakeData, new AuthorizationCallback() {
Expand All @@ -68,13 +69,13 @@ public void handle(Exception e, boolean isAuthorized) {
+ settings.getCloseTimeout() + ":"
+ settings.getTransports();

request.response.statusCode = 200;
request.response().setStatusCode(200);
String jsonp = clientData.getParams().get("jsonp");
if(jsonp != null) {
result = "io.j[" + jsonp + "](\"" + result + "\");";
resHeaders.put("Content-Type", "application/javascript");
resHeaders.add("Content-Type", "application/javascript");
}
request.response.end(result);
request.response().end(result);

manager.getHandshaken().put(id, handshakeData);
// self.store.publish('handshake', id, newData || handshakeData);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.vertx.java.core.Handler;
import org.vertx.java.core.MultiMap;
import org.vertx.java.core.buffer.Buffer;
import org.vertx.java.core.http.HttpServerRequest;
import org.vertx.java.core.http.ServerWebSocket;
Expand Down Expand Up @@ -41,17 +42,17 @@ public void handle(ClientData clientData) {
Settings settings = manager.getSettings();

// handle sync disconnect xhrs
Map<String, String> params = clientData.getParams();
MultiMap params = clientData.getParams();
if (params != null && params.get("disconnect") != null) {
Transport transport = manager.transport(clientData.getId());
if (transport != null && transport.isOpen()) {
transport.onForcedDisconnect();
} else {
// this.store.publish('disconnect-force:' + data.id);
}
request.response.statusCode = 200;
request.response.end();
request.response.close();
request.response().setStatusCode(200);
request.response().end();
request.response().close();
return;
}

Expand All @@ -73,9 +74,9 @@ public void handle(ClientData clientData) {
socket.close();
}
if(request != null) {
request.response.statusCode = 200;
request.response.end();
request.response.close();
request.response().setStatusCode(200);
request.response().end();
request.response().close();
}
return;
}
Expand All @@ -85,8 +86,8 @@ public void handle(ClientData clientData) {
HandshakeData handshakeData = manager.handshakeData(clientData.getId());
if (transport.isDisconnected()) {
// failed during transport setup
request.response.end();
request.response.close();
request.response().end();
request.response().close();
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public StaticHandler(Manager manager) {

public void handle(ClientData clientData) {
HttpServerRequest req = clientData.getRequest();
HttpServerResponse res = req.response;
HttpServerResponse res = req.response();
String requestedFileName = clientData.getPath();
String resourceRootDir = getRootDir();

Expand All @@ -42,22 +42,26 @@ public void handle(ClientData clientData) {
copyFilesToDir();
}

switch (requestedFileName) {
case "/static/flashsocket/WebSocketMainInsecure.swf":
res.sendFile(resourceRootDir + "/WebSocketMainInsecure.swf");
break;
case "/static/flashsocket/WebSocketMain.swf":
res.sendFile(resourceRootDir + "/WebSocketMain.swf");
break;
case "/socket.io.js":
res.sendFile(resourceRootDir + "/socket.io.js");
break;
case "/socket.io.min.js":
res.sendFile(resourceRootDir + "/socket.io.min.js");
break;
default:
throw new IllegalArgumentException(requestedFileName);
}
switch (requestedFileName) {
case "/static/flashsocket/WebSocketMainInsecure.swf":
res.sendFile(resourceRootDir + "/WebSocketMainInsecure.swf");

break;
case "/static/flashsocket/WebSocketMain.swf":
res.sendFile(resourceRootDir + "/WebSocketMain.swf");

break;
case "/socket.io.js":
res.sendFile(resourceRootDir + "/socket.io.js");

break;
case "/socket.io.min.js":
res.sendFile(resourceRootDir + "/socket.io.min.js");

break;
default:
throw new IllegalArgumentException(requestedFileName);
}
res.close();
}

Expand Down
Loading

0 comments on commit 17d86a9

Please sign in to comment.