Fixes issues 1513 1751. Also updates the unit tests to properly check for POST parameters. Patch by: mmendez Review by: scottb git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@1521 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/javadoc/com/google/gwt/examples/http/client/PostExample.java b/user/javadoc/com/google/gwt/examples/http/client/PostExample.java index 62af798..3fd9755 100644 --- a/user/javadoc/com/google/gwt/examples/http/client/PostExample.java +++ b/user/javadoc/com/google/gwt/examples/http/client/PostExample.java
@@ -12,6 +12,7 @@ RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, url); try { + builder.setHeader("Content-Type", "application/x-www-form-urlencoded"); Request response = builder.sendRequest(postData, new RequestCallback() { public void onError(Request request, Throwable exception) {
diff --git a/user/src/com/google/gwt/http/client/package.html b/user/src/com/google/gwt/http/client/package.html index 8be06af..20a447f 100644 --- a/user/src/com/google/gwt/http/client/package.html +++ b/user/src/com/google/gwt/http/client/package.html
@@ -11,14 +11,14 @@ <h2>Caveats</h2> <h3>Same-Origin Security Policy</h3> Modern web browsers restrict client-side scripts from accessing items outside -of their source origin. This means that a script loaded form <code>www.foo.com</code> cannot access -content from <code>www.bar.com</code>. For more details plesae see, <a +of their source origin. This means that a script loaded from <code>www.foo.com</code> cannot access +content from <code>www.bar.com</code>. For more details please see, <a href="http://en.wikipedia.org/wiki/Same_origin_policy">Same-Origin Security Policy</a>. <h3>Pending Request Limit</h3> Modern web browsers are limited to having only two HTTP requests outstanding at -any one time. If your server experiences and error that prevents it from sending +any one time. If your server experiences an error that prevents it from sending a response, it can tie up your outstanding requests. If you are concerned about this, you can always set timeouts for the request via {@link com.google.gwt.http.client.RequestBuilder#setTimeoutMillis(int)}.
diff --git a/user/test/com/google/gwt/http/client/RequestBuilderTest.java b/user/test/com/google/gwt/http/client/RequestBuilderTest.java index 7e42770..c38591f 100644 --- a/user/test/com/google/gwt/http/client/RequestBuilderTest.java +++ b/user/test/com/google/gwt/http/client/RequestBuilderTest.java
@@ -19,7 +19,7 @@ import com.google.gwt.junit.client.GWTTestCase; /** - * HTTPRequestBuilder tests. + * Test cases for the {@link RequestBuilder} class. */ public class RequestBuilderTest extends GWTTestCase { private static final int TEST_FINISH_DELAY = 10000; @@ -28,6 +28,7 @@ return GWT.getModuleBaseURL() + "testRequestBuilder/"; } + @Override public String getModuleName() { return "com.google.gwt.http.RequestBuilderTest"; } @@ -57,8 +58,7 @@ */ public void testRequestBuilderStringString() throws RequestException { try { - new RequestBuilder((RequestBuilder.Method) null, - null); + new RequestBuilder((RequestBuilder.Method) null, null); fail("NullPointerException should have been thrown for construction with null method."); } catch (NullPointerException ex) { // purposely ignored @@ -110,7 +110,7 @@ MyRequestBuilder(String httpMethod, String url) { super(httpMethod, url); } - }; + } new MyRequestBuilder("HEAD", "FOO"); // should reach here without any exceptions being thrown @@ -146,6 +146,7 @@ RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, getTestBaseURL() + "sendRequest_POST"); + builder.setHeader("Content-Type", "application/x-www-form-urlencoded"); builder.sendRequest("method=test+request", new RequestCallback() { public void onError(Request request, Throwable exception) { fail("HTTPRequest timed out");
diff --git a/user/test/com/google/gwt/http/server/RequestBuilderTestServlet.java b/user/test/com/google/gwt/http/server/RequestBuilderTestServlet.java index 09a384a..a80df93 100644 --- a/user/test/com/google/gwt/http/server/RequestBuilderTestServlet.java +++ b/user/test/com/google/gwt/http/server/RequestBuilderTestServlet.java
@@ -18,13 +18,13 @@ import java.io.BufferedReader; import java.io.IOException; -import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; /** - * TODO: document me. + * Servlet component of the + * {@link com.google.gwt.http.client.RequestBuilderTest RequestBuilderTest}. */ public class RequestBuilderTestServlet extends HttpServlet { @@ -32,13 +32,15 @@ return "/com.google.gwt.http.RequestBuilderTest/testRequestBuilder/"; } + @Override protected void doDelete(HttpServletRequest request, - HttpServletResponse response) throws ServletException, IOException { + HttpServletResponse response) { response.setStatus(HttpServletResponse.SC_OK); } + @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) - throws ServletException, IOException { + throws IOException { String method = request.getMethod(); String pathInfo = request.getPathInfo(); if (pathInfo.equals(getPathInfoBase() + "setRequestHeader")) { @@ -76,25 +78,24 @@ } } - protected void doHead(HttpServletRequest request, HttpServletResponse response) - throws ServletException, IOException { + @Override + protected void doHead(HttpServletRequest request, HttpServletResponse response) { response.setStatus(HttpServletResponse.SC_OK); } - protected void doPost(HttpServletRequest request, HttpServletResponse response) - throws ServletException, IOException { - BufferedReader reader = request.getReader(); - String content = reader.readLine(); - response.getWriter().print("POST"); - if (content.equals("method=test+request")) { + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) { + String parameter = request.getParameter("method"); + if ("test request".equals(parameter)) { response.setStatus(HttpServletResponse.SC_OK); } else { response.setStatus(HttpServletResponse.SC_BAD_REQUEST); } } + @Override protected void doPut(HttpServletRequest request, HttpServletResponse response) - throws ServletException, IOException { + throws IOException { BufferedReader reader = request.getReader(); String content = reader.readLine(); if (content.equals("<html><body>Put Me</body></html>")) { @@ -103,6 +104,4 @@ response.setStatus(HttpServletResponse.SC_BAD_REQUEST); } } - - private int count; }