Skip to content

Commit

Permalink
Fix for #553 Request parameters get lost on ws requests on Tomcat 7
Browse files Browse the repository at this point in the history
  • Loading branch information
jfarcand committed Aug 28, 2012
1 parent 26f74db commit d94f47a
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public String getPathTranslated() {
*/
@Override
public String getQueryString() {
return b.request.getQueryString();
return b.queryString != "" ? b.queryString : isNotNoOps() ? b.request.getQueryString() : "";
}

/**
Expand Down Expand Up @@ -951,7 +951,8 @@ public final static class Builder {
private String contextPath = "";
private String serverName = "";
private int serverPort = 0;
public HttpSession webSocketFakeSession;
private HttpSession webSocketFakeSession;
private String queryString = "";

public Builder() {
}
Expand Down Expand Up @@ -1036,6 +1037,11 @@ public Builder pathInfo(String pathInfo) {
return this;
}

public Builder queryString(String queryString) {
this.queryString = queryString;
return this;
}

public Builder body(byte[] dataBytes, int offset, int length) {
this.dataBytes = dataBytes;
this.offset = offset;
Expand Down Expand Up @@ -1575,6 +1581,7 @@ private static void load(HttpServletRequest request, Builder b) {
s = e.nextElement();
b.queryStrings.put(s, request.getParameterValues(s));
}
b.queryString = request.getQueryString();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ public Enumeration<String> getInitParameterNames() {
});
}


@Test
public void testQueryStringAsRequest() throws IOException, ServletException {
framework.addAtmosphereHandler("/a", new AbstractReflectorAtmosphereHandler() {
Expand Down Expand Up @@ -105,4 +104,40 @@ public void postInspect(AtmosphereResource r) {
assertEquals(e.get(), "application/xml");
assertEquals(e2.get().toLowerCase(), "long_polling");
}

@Test
public void testQueryStringBuilder() throws IOException, ServletException {
framework.addAtmosphereHandler("/a", new AbstractReflectorAtmosphereHandler() {
@Override
public void onRequest(AtmosphereResource resource) throws IOException {
}

@Override
public void destroy() {
}
});

AtmosphereRequest request = new AtmosphereRequest.Builder().queryString("a=b").pathInfo("/a").build();

final AtomicReference<String> e = new AtomicReference<String>();

framework.interceptor(new AtmosphereInterceptor() {
@Override
public void configure(AtmosphereConfig config) {
}

@Override
public Action inspect(AtmosphereResource r) {
e.set(r.getRequest().getQueryString());
return Action.CANCELLED;
}

@Override
public void postInspect(AtmosphereResource r) {
}
});
framework.doCometSupport(request, AtmosphereResponse.create());

assertEquals(e.get(), "a=b");
}
}

0 comments on commit d94f47a

Please sign in to comment.