org.projectodd.sockjs.servlet.SockJsWebsocketRequest Maven / Gradle / Ivy
package org.projectodd.sockjs.servlet;
import org.projectodd.sockjs.SockJsRequest;
import javax.websocket.Session;
import java.util.List;
import java.util.Map;
public class SockJsWebsocketRequest extends SockJsRequest {
public SockJsWebsocketRequest(Session session, String contextPath, String prefix, Map> headers) {
this.session = session;
this.contextPath = contextPath;
this.prefix = prefix;
this.headers = headers;
}
@Override
public String getMethod() {
// Let's just pretend they're all GETs
return "GET";
}
@Override
public String getUrl() {
return session.getRequestURI().toString();
}
@Override
public String getPath() {
String path = session.getRequestURI().getPath();
if (path == null) {
return null;
}
if (contextPath.length() > 1 && path.startsWith(contextPath)) {
path = path.substring(contextPath.length());
}
if (prefix.length() > 0 && path.startsWith(prefix)) {
path = path.substring(prefix.length());
}
return path;
}
@Override
public String getPrefix() {
String sockjsPrefix = contextPath + prefix;
return sockjsPrefix.equals("") ? "/" : sockjsPrefix;
}
@Override
public String getRemoteAddr() {
// TODO: grab this during the handshake process
return null;
}
@Override
public int getRemotePort() {
return 0;
}
@Override
public String getHeader(String name) {
for (String header : headers.keySet()) {
if (name.equalsIgnoreCase(header)) {
List values = headers.get(header);
if (values != null && values.size() > 0) {
return values.get(0);
}
}
}
return null;
}
@Override
public String getContentType() {
return null;
}
@Override
public String getCookie(String name) {
return null;
}
@Override
public String getQueryParameter(String name) {
List paramValues = session.getRequestParameterMap().get(name);
if (paramValues != null && paramValues.size() > 0) {
return paramValues.get(0);
}
return null;
}
private Session session;
private String contextPath;
private String prefix;
private Map> headers;
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy