Author: [email protected] Date: Thu Mar 5 09:29:25 2009 New Revision: 4941 Modified: trunk/user/src/com/google/gwt/user/client/rpc/impl/RemoteServiceProxy.java trunk/user/src/com/google/gwt/user/server/rpc/RemoteServiceServlet.java trunk/user/test/com/google/gwt/user/client/rpc/RemoteServiceServletTest.java trunk/user/test/com/google/gwt/user/client/rpc/RemoteServiceServletTestService.java trunk/user/test/com/google/gwt/user/client/rpc/RemoteServiceServletTestServiceAsync.java trunk/user/test/com/google/gwt/user/server/rpc/RemoteServiceServletTestServiceImplBase.java
Log: Add the permutation's strong name to the HTTP headers of GWT RPC requests. http://gwt-code-reviews.appspot.com/9804 Patch by: bobv Review by: rjrjr Modified: trunk/user/src/com/google/gwt/user/client/rpc/impl/RemoteServiceProxy.java ============================================================================== --- trunk/user/src/com/google/gwt/user/client/rpc/impl/RemoteServiceProxy.java (original) +++ trunk/user/src/com/google/gwt/user/client/rpc/impl/RemoteServiceProxy.java Thu Mar 5 09:29:25 2009 @@ -15,6 +15,7 @@ */ package com.google.gwt.user.client.rpc.impl; +import com.google.gwt.core.client.GWT; import com.google.gwt.core.client.JavaScriptObject; import com.google.gwt.http.client.Request; import com.google.gwt.http.client.RequestBuilder; @@ -34,6 +35,12 @@ */ public abstract class RemoteServiceProxy implements SerializationStreamFactory, ServiceDefTarget { + + /** + * NB: Keep in sync with RemoteServiceServlet. + */ + private static final String STRONG_NAME_HEADER = "X-GWT-Permutation"; + /** * A global id to track any given request. */ @@ -300,6 +307,7 @@ getServiceEntryPoint()); rb.setHeader("Content-Type", "text/x-gwt-rpc; charset=utf-8"); + rb.setHeader(STRONG_NAME_HEADER, GWT.getPermutationStrongName()); rb.setCallback(responseHandler); rb.setRequestData(requestData); return rb; Modified: trunk/user/src/com/google/gwt/user/server/rpc/RemoteServiceServlet.java ============================================================================== --- trunk/user/src/com/google/gwt/user/server/rpc/RemoteServiceServlet.java (original) +++ trunk/user/src/com/google/gwt/user/server/rpc/RemoteServiceServlet.java Thu Mar 5 09:29:25 2009 @@ -40,6 +40,11 @@ public class RemoteServiceServlet extends HttpServlet implements SerializationPolicyProvider { + /** + * NB: Keep in sync with RemoteServiceProxy. + */ + private static final String STRONG_NAME_HEADER = "X-GWT-Permutation"; + private final ThreadLocal<HttpServletRequest> perThreadRequest = new ThreadLocal<HttpServletRequest>(); private final ThreadLocal<HttpServletResponse> perThreadResponse = new ThreadLocal<HttpServletResponse>(); @@ -285,6 +290,16 @@ ServletContext servletContext = getServletContext(); RPCServletUtils.writeResponseForUnexpectedFailure(servletContext, getThreadLocalResponse(), e); + } + + /** + * Returns the strong name of the permutation, as reported by the client that + * issued the request, or <code>null</code> if it could not be determined. + * This information is encoded in the {...@value #STRONG_NAME_HEADER} HTTP + * header. + */ + protected final String getPermutationStrongName() { + return getThreadLocalRequest().getHeader(STRONG_NAME_HEADER); } /** Modified: trunk/user/test/com/google/gwt/user/client/rpc/RemoteServiceServletTest.java ============================================================================== --- trunk/user/test/com/google/gwt/user/client/rpc/RemoteServiceServletTest.java (original) +++ trunk/user/test/com/google/gwt/user/client/rpc/RemoteServiceServletTest.java Thu Mar 5 09:29:25 2009 @@ -100,6 +100,25 @@ assertTrue(req.isPending()); } + public void testPermutationStrongName() { + RemoteServiceServletTestServiceAsync service = getAsyncService(); + + delayTestFinish(TEST_DELAY); + + assertNotNull(GWT.getPermutationStrongName()); + service.testExpectPermutationStrongName(GWT.getPermutationStrongName(), + new AsyncCallback<Void>() { + + public void onFailure(Throwable caught) { + TestSetValidator.rethrowException(caught); + } + + public void onSuccess(Void result) { + finishTest(); + } + }); + } + public void testServiceInterfaceLocation() { RemoteServiceServletTestServiceAsync service = getAsyncService(); Modified: trunk/user/test/com/google/gwt/user/client/rpc/RemoteServiceServletTestService.java ============================================================================== --- trunk/user/test/com/google/gwt/user/client/rpc/RemoteServiceServletTestService.java (original) +++ trunk/user/test/com/google/gwt/user/client/rpc/RemoteServiceServletTestService.java Thu Mar 5 09:29:25 2009 @@ -16,10 +16,13 @@ package com.google.gwt.user.client.rpc; /** - * TODO: document me. + * A RemoteService for testing the details of the "over-HTTP" part of + * RPC-over-HTTP. */ public interface RemoteServiceServletTestService extends RemoteService { void test(); void testExpectCustomHeader(); + + void testExpectPermutationStrongName(String expectedStrongName); } Modified: trunk/user/test/com/google/gwt/user/client/rpc/RemoteServiceServletTestServiceAsync.java ============================================================================== --- trunk/user/test/com/google/gwt/user/client/rpc/RemoteServiceServletTestServiceAsync.java (original) +++ trunk/user/test/com/google/gwt/user/client/rpc/RemoteServiceServletTestServiceAsync.java Thu Mar 5 09:29:25 2009 @@ -19,10 +19,13 @@ import com.google.gwt.http.client.RequestBuilder; /** - * TODO: document me. + * Async peer of {...@link RemoteServiceServletTestService}. */ public interface RemoteServiceServletTestServiceAsync { Request test(AsyncCallback<Void> callback); RequestBuilder testExpectCustomHeader(AsyncCallback<Void> callback); + + void testExpectPermutationStrongName(String expectedStrongName, + AsyncCallback<Void> callback); } Modified: trunk/user/test/com/google/gwt/user/server/rpc/RemoteServiceServletTestServiceImplBase.java ============================================================================== --- trunk/user/test/com/google/gwt/user/server/rpc/RemoteServiceServletTestServiceImplBase.java (original) +++ trunk/user/test/com/google/gwt/user/server/rpc/RemoteServiceServletTestServiceImplBase.java Thu Mar 5 09:29:25 2009 @@ -20,7 +20,8 @@ import javax.servlet.http.HttpServletRequest; /** - * TODO: document me. + * A RemoteService for testing the details of the "over-HTTP" part of + * RPC-over-HTTP. */ public class RemoteServiceServletTestServiceImplBase extends RemoteServiceServlet implements RemoteServiceServletTestService { @@ -32,6 +33,17 @@ HttpServletRequest req = getThreadLocalRequest(); if (!Boolean.parseBoolean(req.getHeader("X-Custom-Header"))) { throw new RuntimeException("Missing header"); + } + } + + public void testExpectPermutationStrongName(String expectedStrongName) { + if (getPermutationStrongName() == null) { + throw new NullPointerException("getPermutationStrongName()"); + } + + if (!expectedStrongName.equals(getPermutationStrongName())) { + throw new RuntimeException(expectedStrongName + " != " + + getPermutationStrongName()); } } } --~--~---------~--~----~------------~-------~--~----~ http://groups.google.com/group/Google-Web-Toolkit-Contributors -~----------~----~----~----~------~----~------~--~---
