Skip to content

Commit

Permalink
Fixes #1256
Browse files Browse the repository at this point in the history
  • Loading branch information
jfarcand committed Sep 6, 2013
1 parent d6acbfb commit b996bd0
Showing 1 changed file with 26 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -532,9 +532,9 @@ public AtmosphereFramework init(final ServletConfig sc) throws ServletException
}

/**
* Prevent Atmosphere from scanning the entire class path.
* Prevent Atmosphere from scanning the entire class path.
*/
protected void preventOOM(){
protected void preventOOM() {

String s = config.getInitParameter(ApplicationConfig.SCAN_CLASSPATH);
if (s != null) {
Expand Down Expand Up @@ -1568,25 +1568,8 @@ public AtmosphereFramework configureRequestResponse(AtmosphereRequest req, Atmos
body = null;
}

// We need to strip Atmosphere's own query string from the request in case an
// interceptor re-inject the request because the wrong body will be passed.
StringBuilder queryStrings = new StringBuilder("");
Enumeration<String> e = req.getParameterNames();
String name, key;
while (e.hasMoreElements()) {
key = e.nextElement();
name = key.toLowerCase().trim();
if (!name.startsWith("x-atmosphere") && !name.equalsIgnoreCase("x-cache-date")) {
queryStrings.append(key).append("=").append(req.getParameter(key));
}
if (e.hasMoreElements() && queryStrings.length() > 0) {
queryStrings.append("&");
}
}

// Reconfigure the request. Clear the Atmosphere queryString
req.headers(headers)
.queryString(queryStrings.toString())
.method(body != null && req.getMethod().equalsIgnoreCase("GET") ? "POST" : req.getMethod());

if (body != null) {
Expand Down Expand Up @@ -1802,6 +1785,7 @@ public Map<String, AtmosphereHandlerWrapper> getAtmosphereHandlers() {
protected Map<String, String> configureQueryStringAsRequest(AtmosphereRequest request) {
Map<String, String> headers = new HashMap<String, String>();

StringBuilder q = new StringBuilder();
try {
String qs = request.getQueryString();
if (qs != null && !qs.isEmpty()) {
Expand All @@ -1816,32 +1800,25 @@ protected Map<String, String> configureQueryStringAsRequest(AtmosphereRequest re
request.contentType(s.length > 1 ? s[1] : "");
}
}
if (!s[0].toLowerCase().startsWith("x-atmosphere")
&& !s[0].equalsIgnoreCase("x-cache-date")
&& !s[0].equalsIgnoreCase("Content-Type")
&& !s[0].equalsIgnoreCase("_")) {
q.append(s[0]).append("=").append(s.length > 1 ? s[1] : "").append("&");
}
headers.put(s[0], s.length > 1 ? s[1] : "");
}
}
} catch (Exception ex) {
logger.error("Unable to parse query string", ex);
}
if (q.length() > 0) q.deleteCharAt(q.length() - 1);
request.queryString(q.toString());

logger.trace("Query String translated to headers {}", headers);
return headers;
}

protected boolean isIECandidate(AtmosphereRequest request) {
String userAgent = request.getHeader("User-Agent");
if (userAgent == null) return false;

if (userAgent.contains("MSIE") || userAgent.contains(".NET")) {
// Now check the header
String transport = request.getHeader(HeaderConfig.X_ATMOSPHERE_TRANSPORT);
if (transport != null) {
return false;
} else {
return true;
}
}
return false;
}

public WebSocketProtocol getWebSocketProtocol() {
// TODO: Spagetthi code, needs to rework.
// Make sure we initialized the WebSocketProtocol
Expand Down Expand Up @@ -1907,6 +1884,7 @@ public AtmosphereFramework setLibPath(String libPath) {

/**
* The current {@link org.atmosphere.websocket.WebSocketProcessor} used to handle websocket requests.
*
* @return {@link org.atmosphere.websocket.WebSocketProcessor}
*/
public String getWebSocketProcessorClassName() {
Expand All @@ -1916,6 +1894,7 @@ public String getWebSocketProcessorClassName() {
/**
* Set the {@link org.atmosphere.websocket.WebSocketProcessor} class name used to process WebSocket request. Default is
* {@link DefaultWebSocketProcessor}
*
* @param webSocketProcessorClassName {@link org.atmosphere.websocket.WebSocketProcessor}
* @return this
*/
Expand Down Expand Up @@ -2136,6 +2115,7 @@ public boolean accept(File arg0, String arg1) {

/**
* The current {@link EndpointMapper} used to map request to {@link AtmosphereHandler}
*
* @return {@link EndpointMapper}
*/
public EndpointMapper<AtmosphereHandlerWrapper> endPointMapper() {
Expand All @@ -2144,7 +2124,8 @@ public EndpointMapper<AtmosphereHandlerWrapper> endPointMapper() {

/**
* Set the {@link EndpointMapper}
* @param endpointMapper {@link EndpointMapper}
*
* @param endpointMapper {@link EndpointMapper}
* @return this
*/
public AtmosphereFramework endPointMapper(EndpointMapper endpointMapper) {
Expand Down Expand Up @@ -2211,9 +2192,9 @@ public AtmosphereFramework addWebSocketHandler(String path, WebSocketHandler han
* Add an {@link WebSocketHandler} mapped to the path and the {@link AtmosphereHandler} in case {@link Broadcaster} are
* used.
*
* @param path a path
* @param path a path
* @param handler a {@link WebSocketHandler}
* @param h an {@link AtmosphereHandler}
* @param h an {@link AtmosphereHandler}
* @return this
*/
public AtmosphereFramework addWebSocketHandler(String path, WebSocketHandler handler, AtmosphereHandler h) {
Expand All @@ -2225,10 +2206,10 @@ public AtmosphereFramework addWebSocketHandler(String path, WebSocketHandler han
* Add an {@link WebSocketHandler} mapped to the path and the {@link AtmosphereHandler} in case {@link Broadcaster} are
* used.
*
* @param path a path
* @param path a path
* @param handler a {@link WebSocketHandler}
* @param h an {@link AtmosphereHandler}
* @param l {@link AtmosphereInterceptor}
* @param h an {@link AtmosphereHandler}
* @param l {@link AtmosphereInterceptor}
* @return this
*/
public AtmosphereFramework addWebSocketHandler(String path, WebSocketHandler handler, AtmosphereHandler h, List<AtmosphereInterceptor> l) {
Expand All @@ -2239,6 +2220,7 @@ public AtmosphereFramework addWebSocketHandler(String path, WebSocketHandler han

/**
* Invoked when a {@link AnnotationProcessor} found annotation.
*
* @param b true when found
* @return this
*/
Expand All @@ -2249,6 +2231,7 @@ public AtmosphereFramework annotationScanned(boolean b) {

/**
* Return the list of packages the framework should look for {@link org.atmosphere.config.AtmosphereAnnotation}
*
* @return the list of packages the framework should look for {@link org.atmosphere.config.AtmosphereAnnotation}
*/
public List<String> customAnnotation() {
Expand All @@ -2257,10 +2240,11 @@ public List<String> customAnnotation() {

/**
* Add a package containing classes annotated with {@link org.atmosphere.config.AtmosphereAnnotation}.
*
* @param p a package
* @return this;
*/
public AtmosphereFramework addCustomAnnotationPackage(Class p){
public AtmosphereFramework addCustomAnnotationPackage(Class p) {
annotationPackages.addLast(p.getPackage().getName());
return this;
}
Expand Down

0 comments on commit b996bd0

Please sign in to comment.