Integrate r10482 into GWT 2.4 branch. Issue 6628. git-svn-id: https://google-web-toolkit.googlecode.com/svn/releases/2.4@10483 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/src/com/google/web/bindery/requestfactory/server/SimpleRequestProcessor.java b/user/src/com/google/web/bindery/requestfactory/server/SimpleRequestProcessor.java index 078ad2a..b84b3d6 100644 --- a/user/src/com/google/web/bindery/requestfactory/server/SimpleRequestProcessor.java +++ b/user/src/com/google/web/bindery/requestfactory/server/SimpleRequestProcessor.java
@@ -126,7 +126,6 @@ try { process(req, responseBean.as()); } catch (ReportableException e) { - e.printStackTrace(); // Create a new response envelope, since the state is unknown responseBean = FACTORY.response(); responseBean.as().setGeneralFailure(createFailureMessage(e).as()); @@ -200,7 +199,12 @@ final RequestState source = new RequestState(service); // Make sure the RequestFactory is valid - service.resolveRequestFactory(req.getRequestFactory()); + String requestFactoryToken = req.getRequestFactory(); + if (requestFactoryToken == null) { + // Tell old clients to go away + throw new ReportableException("The client payload version is out of sync with the server"); + } + service.resolveRequestFactory(requestFactoryToken); // Apply operations processOperationMessages(source, req);
diff --git a/user/test/com/google/web/bindery/requestfactory/gwt/client/RequestFactoryTest.java b/user/test/com/google/web/bindery/requestfactory/gwt/client/RequestFactoryTest.java index fdff661..9bcbc55 100644 --- a/user/test/com/google/web/bindery/requestfactory/gwt/client/RequestFactoryTest.java +++ b/user/test/com/google/web/bindery/requestfactory/gwt/client/RequestFactoryTest.java
@@ -15,6 +15,7 @@ */ package com.google.web.bindery.requestfactory.gwt.client; +import com.google.web.bindery.autobean.shared.AutoBeanCodex; import com.google.web.bindery.requestfactory.shared.EntityProxy; import com.google.web.bindery.requestfactory.shared.EntityProxyChange; import com.google.web.bindery.requestfactory.shared.EntityProxyId; @@ -23,6 +24,8 @@ import com.google.web.bindery.requestfactory.shared.Receiver; import com.google.web.bindery.requestfactory.shared.Request; import com.google.web.bindery.requestfactory.shared.RequestContext; +import com.google.web.bindery.requestfactory.shared.RequestTransport; +import com.google.web.bindery.requestfactory.shared.RequestTransport.TransportReceiver; import com.google.web.bindery.requestfactory.shared.ServerFailure; import com.google.web.bindery.requestfactory.shared.SimpleBarProxy; import com.google.web.bindery.requestfactory.shared.SimpleBarRequest; @@ -31,7 +34,10 @@ import com.google.web.bindery.requestfactory.shared.SimpleFooRequest; import com.google.web.bindery.requestfactory.shared.SimpleValueContext; import com.google.web.bindery.requestfactory.shared.SimpleValueProxy; +import com.google.web.bindery.requestfactory.shared.impl.MessageFactoryHolder; import com.google.web.bindery.requestfactory.shared.impl.SimpleEntityProxyId; +import com.google.web.bindery.requestfactory.shared.messages.ResponseMessage; +import com.google.web.bindery.requestfactory.shared.messages.ServerFailureMessage; import java.math.BigDecimal; import java.math.BigInteger; @@ -565,6 +571,49 @@ } /** + * Tests the server behavior when an empty JSON object is sent. + */ + public void testEmptyRequestBlankObject() { + delayTestFinish(DELAY_TEST_FINISH); + RequestTransport transport = req.getRequestTransport(); + transport.send("{}", new TransportReceiver() { + @Override + public void onTransportFailure(ServerFailure failure) { + fail(); + } + + @Override + public void onTransportSuccess(String payload) { + ResponseMessage resp = + AutoBeanCodex.decode(MessageFactoryHolder.FACTORY, ResponseMessage.class, payload).as(); + ServerFailureMessage failure = resp.getGeneralFailure(); + assertNotNull(failure); + finishTestAndReset(); + } + }); + } + + /** + * Tests the server behavior when a zero-length payload is sent. + */ + public void testEmptyRequestZeroLength() { + delayTestFinish(DELAY_TEST_FINISH); + RequestTransport transport = req.getRequestTransport(); + transport.send("", new TransportReceiver() { + @Override + public void onTransportFailure(ServerFailure failure) { + // Expect a 500 since the payload is malformed + finishTestAndReset(); + } + + @Override + public void onTransportSuccess(String payload) { + fail("Should not have succeeded"); + } + }); + } + + /** * Tests that enum values used only as method parameters in a RequestContext * are in the EnumMap. This test only applies to GWT-based clients. */