31
31
import com .google .gwt .user .client .rpc .SerializationStreamReader ;
32
32
import com .google .gwt .user .client .rpc .SerializationStreamWriter ;
33
33
import com .google .gwt .user .client .rpc .ServiceDefTarget ;
34
+ import com .google .gwt .user .client .rpc .impl .RpcStatsContext ;
34
35
import com .google .gwt .user .client .rpc .impl .RequestCallbackAdapter .ResponseReader ;
35
36
36
37
/**
@@ -54,6 +55,63 @@ public abstract class RemoteServiceProxy implements SerializationStreamFactory,
54
55
* The content type to be used in HTTP requests.
55
56
*/
56
57
private static final String RPC_CONTENT_TYPE = "text/x-gwt-rpc; charset=utf-8" ;
58
+
59
+ /**
60
+ * A helper class that prepares the service to serialize data.
61
+ */
62
+ public class ServiceHelper {
63
+
64
+ private final String fullServiceName ;
65
+ private final String methodName ;
66
+ private final RpcStatsContext statsContext ;
67
+ private SerializationStreamWriter streamWriter ;
68
+
69
+ public ServiceHelper (String serviceName , String methodName ) {
70
+ this .fullServiceName = serviceName + "." + methodName ;
71
+ this .methodName = methodName ;
72
+ this .statsContext = new RpcStatsContext ();
73
+ }
74
+
75
+ /**
76
+ * Finishes the serialization.
77
+ */
78
+ public Request finish (AsyncCallback callback , ResponseReader responseHeader )
79
+ throws SerializationException {
80
+ String payload = streamWriter .toString ();
81
+ boolean toss = statsContext .isStatsAvailable ()
82
+ && statsContext .stats (statsContext .timeStat (fullServiceName , "requestSerialized" ));
83
+ return doInvoke (responseHeader , fullServiceName , statsContext , payload , callback );
84
+ }
85
+
86
+ /**
87
+ * Finishes the serialization and return a RequestBuilder.
88
+ */
89
+ public RequestBuilder finishForRequestBuilder (AsyncCallback callback ,
90
+ ResponseReader responseHeader ) throws SerializationException {
91
+ String payload = streamWriter .toString ();
92
+ boolean toss = statsContext .isStatsAvailable ()
93
+ && statsContext .stats (statsContext .timeStat (fullServiceName , "requestSerialized" ));
94
+ return doPrepareRequestBuilder (
95
+ responseHeader , fullServiceName , statsContext , payload , callback );
96
+ }
97
+
98
+ /**
99
+ * Starts the serialization.
100
+ */
101
+ public SerializationStreamWriter start (String remoteServiceInterfaceName ,
102
+ int paramCount ) throws SerializationException {
103
+ boolean toss = statsContext .isStatsAvailable ()
104
+ && statsContext .stats (statsContext .timeStat (fullServiceName , "begin" ));
105
+ streamWriter = createStreamWriter ();
106
+ if (getRpcToken () != null ) {
107
+ streamWriter .writeObject (getRpcToken ());
108
+ }
109
+ streamWriter .writeString (remoteServiceInterfaceName );
110
+ streamWriter .writeString (methodName );
111
+ streamWriter .writeInt (paramCount );
112
+ return streamWriter ;
113
+ }
114
+ }
57
115
58
116
/**
59
117
* @deprecated use {@link RpcStatsContext}.
@@ -323,9 +381,10 @@ protected <T> Request doInvoke(ResponseReader responseReader,
323
381
try {
324
382
return rb .send ();
325
383
} catch (RequestException ex ) {
326
- InvocationException iex = new InvocationException (
327
- "Unable to initiate the asynchronous service invocation -- check the network connection" ,
328
- ex );
384
+ InvocationException iex = new InvocationException (
385
+ "Unable to initiate the asynchronous service invocation (" +
386
+ methodName + ") -- check the network connection" ,
387
+ ex );
329
388
callback .onFailure (iex );
330
389
} finally {
331
390
if (statsContext .isStatsAvailable ()) {
0 commit comments