[gwt-rpc-plus] r151 committed - Fixing generation of exception types on the wire. The exceptions weren...

0 views
Skip to first unread message

gwt-rp...@googlecode.com

unread,
Mar 23, 2010, 11:34:26 PM3/23/10
to dotspots-o...@googlegroups.com
Revision: 151
Author: mmastrac
Date: Tue Mar 23 20:33:15 2010
Log: Fixing generation of exception types on the wire. The exceptions
weren't getting added as part of the result struct, so we never wrote them
out. There were also some issues with how exceptions were processed on the
client.

Also improved the tests here to check for the presence and values of the
exceptions.
http://code.google.com/p/gwt-rpc-plus/source/detail?r=151

Modified:

/trunk/gwt-rpc-plus/codegen/com/dotspots/rpcplus/codegen/thrift/CodeGen.java

/trunk/gwt-rpc-plus/codegen/com/dotspots/rpcplus/codegen/thrift/RpcMethod.java

/trunk/gwt-rpc-plus/example/gen-java-gwt/com/dotspots/rpcplus/example/torturetest/client/TortureTestApi.java

/trunk/gwt-rpc-plus/example/gen-java-gwt/com/dotspots/rpcplus/example/torturetest/client/TortureTestApi_testDeclaresAnException_result.java

/trunk/gwt-rpc-plus/example/gen-java-gwt/com/dotspots/rpcplus/example/torturetest/client/TortureTestApi_testThrowsAnException_result.java

/trunk/gwt-rpc-plus/example/gen-java-gwt/com/dotspots/rpcplus/example/torturetest/client/TortureTestApi_testThrowsAnUnpositionedException_result.java

/trunk/gwt-rpc-plus/example/gen-java-gwt/com/dotspots/rpcplus/example/torturetest/client/TortureTestApi_testThrowsTwoExceptions_args.java

/trunk/gwt-rpc-plus/example/gen-java-gwt/com/dotspots/rpcplus/example/torturetest/client/TortureTestApi_testThrowsTwoExceptions_result.java

/trunk/gwt-rpc-plus/example/gen-javabean/com/dotspots/rpcplus/example/torturetest/TortureTestApi.java

/trunk/gwt-rpc-plus/example/gen-json-server/com/dotspots/rpcplus/example/torturetest/TortureTestApiJson.java

/trunk/gwt-rpc-plus/example/server-example/com/dotspots/rpcplus/example/jsonrpc/thrift/ExampleService.java
/trunk/gwt-rpc-plus/example/torturetest.thrift

/trunk/gwt-rpc-plus/gwt/com/dotspots/rpcplus/client/jsonrpc/thrift/ThriftClientStub.java

/trunk/gwt-rpc-plus/test/gwt-test/com/dotspots/rpcplus/test/client/TestThriftRPC.java

=======================================
---
/trunk/gwt-rpc-plus/codegen/com/dotspots/rpcplus/codegen/thrift/CodeGen.java
Fri Nov 27 15:34:18 2009
+++
/trunk/gwt-rpc-plus/codegen/com/dotspots/rpcplus/codegen/thrift/CodeGen.java
Tue Mar 23 20:33:15 2010
@@ -82,6 +82,9 @@
System.out.println("gwt-rpc-plus Thrift Compiler:
http://code.google.com/p/gwt-rpc-plus/");
System.out.println();

+ // args = new String[]
{ "--server", "--output", "example/gen-json-server", "--idl",
+ // "example/torturetest.thrift" };
+
Options options = new Options();
options.addOption("server", false, "Generate server code");
options.addOption("client", false, "Generate client code");
@@ -106,11 +109,6 @@
doHelp(options);
return;
}
-
- //
- // final RpcThriftParser thriftParser = new RpcThriftParser(new
FileInputStream(
-
// "/Users/matthew/Documents/dotspots/trunk/com.dotspots.thrift/thrift/dot.thrift"),
- //
Arrays.asList("/Users/matthew/Documents/dotspots/trunk/com.dotspots.thrift/thrift"));

if (line.hasOption("idldir")) {
File dir = new File(line.getOptionValue("idldir"));
=======================================
---
/trunk/gwt-rpc-plus/codegen/com/dotspots/rpcplus/codegen/thrift/RpcMethod.java
Thu Aug 6 15:02:27 2009
+++
/trunk/gwt-rpc-plus/codegen/com/dotspots/rpcplus/codegen/thrift/RpcMethod.java
Tue Mar 23 20:33:15 2010
@@ -28,28 +28,31 @@
} else {
result = typeFactory.get(func.getReturnType().getType().getMyType());
}
+
+ final boolean isVoid = result.getTypeKey() == RpcTypeKey.VOID;

argType = new RpcStruct(typeFactory, iface.getClassName() + "$" +
func.getName() + "_args", func.getNamespace(), false,
func.getFieldList().getChildren());

exceptionTypes = new ArrayList<RpcStruct>();
+
+ ArrayList<RpcField> resultFields = new ArrayList<RpcField>();
+ if (!isVoid) {
+ resultFields.add(new RpcField(0, 0, "success", result));
+ }
+
if (func.getExceptions() != null) {
for (DynamicSerDeField field : func.getExceptions().getChildren()) {
// Assume exception types have to be structures
RpcTypeStruct struct = (RpcTypeStruct)
typeFactory.get(field.getFieldType().getMyType());
exceptionTypes.add(struct.getStruct());
+
+ resultFields.add(new RpcField(field.getFieldValue(),
resultFields.size(), field.getName(), struct));
}
}
-
- final boolean isVoid = result.getTypeKey() == RpcTypeKey.VOID;
-
- RpcField[] resultFields = new RpcField[isVoid ? 0 : 1];
- if (!isVoid) {
- resultFields[0] = new RpcField(0, 0, "success", result);
- }

resultStruct = new RpcStruct(typeFactory, iface.getClassName() + "$" +
func.getName() + "_result", func.getNamespace(), false,
- resultFields);
+ resultFields.toArray(new RpcField[resultFields.size()]));

}

=======================================
---
/trunk/gwt-rpc-plus/example/gen-java-gwt/com/dotspots/rpcplus/example/torturetest/client/TortureTestApi.java
Mon Nov 30 10:50:09 2009
+++
/trunk/gwt-rpc-plus/example/gen-java-gwt/com/dotspots/rpcplus/example/torturetest/client/TortureTestApi.java
Tue Mar 23 20:33:15 2010
@@ -57,8 +57,8 @@
call(3, "testDeclaresAnException",
TortureTestApi_testDeclaresAnException_args.create(), callback);
};

- public void testThrowsTwoExceptions(AsyncCallback<String> callback) {
- call(4, "testThrowsTwoExceptions",
TortureTestApi_testThrowsTwoExceptions_args.create(), callback);
+ public void testThrowsTwoExceptions(int which, AsyncCallback<String>
callback) {
+ call(4, "testThrowsTwoExceptions",
TortureTestApi_testThrowsTwoExceptions_args.create(which), callback);
};

public void
testExceptionPassthru(com.dotspots.rpcplus.example.torturetest.client.SimpleException
ex,
AsyncCallback<com.dotspots.rpcplus.example.torturetest.client.SimpleException>
callback) {
=======================================
---
/trunk/gwt-rpc-plus/example/gen-java-gwt/com/dotspots/rpcplus/example/torturetest/client/TortureTestApi_testDeclaresAnException_result.java
Mon Nov 30 10:50:09 2009
+++
/trunk/gwt-rpc-plus/example/gen-java-gwt/com/dotspots/rpcplus/example/torturetest/client/TortureTestApi_testDeclaresAnException_result.java
Tue Mar 23 20:33:15 2010
@@ -16,8 +16,8 @@
}

/* Factory method, strongly dependent on order of fields */
- public static native TortureTestApi_testDeclaresAnException_result
create(String success) /*-{
- return [success];
+ public static native TortureTestApi_testDeclaresAnException_result
create(String success,
com.dotspots.rpcplus.example.torturetest.client.SimpleException ex) /*-{
+ return [success,ex];
}-*/;

public native String getSuccess() /*-{
@@ -36,4 +36,20 @@
delete this[0];
}-*/;

-}
+ public native
com.dotspots.rpcplus.example.torturetest.client.SimpleException getEx() /*-{
+ return this[1];
+ }-*/;
+
+ public native void
setEx(com.dotspots.rpcplus.example.torturetest.client.SimpleException ex)
/*-{
+ this[1] = ex;
+ }-*/;
+
+ public native boolean isSetEx() /*-{
+ return this[1] != null;
+ }-*/;
+
+ public native void unsetEx() /*-{
+ delete this[1];
+ }-*/;
+
+}
=======================================
---
/trunk/gwt-rpc-plus/example/gen-java-gwt/com/dotspots/rpcplus/example/torturetest/client/TortureTestApi_testThrowsAnException_result.java
Mon Nov 30 10:50:09 2009
+++
/trunk/gwt-rpc-plus/example/gen-java-gwt/com/dotspots/rpcplus/example/torturetest/client/TortureTestApi_testThrowsAnException_result.java
Tue Mar 23 20:33:15 2010
@@ -16,8 +16,8 @@
}

/* Factory method, strongly dependent on order of fields */
- public static native TortureTestApi_testThrowsAnException_result
create(String success) /*-{
- return [success];
+ public static native TortureTestApi_testThrowsAnException_result
create(String success,
com.dotspots.rpcplus.example.torturetest.client.SimpleException ex) /*-{
+ return [success,ex];
}-*/;

public native String getSuccess() /*-{
@@ -36,4 +36,20 @@
delete this[0];
}-*/;

-}
+ public native
com.dotspots.rpcplus.example.torturetest.client.SimpleException getEx() /*-{
+ return this[1];
+ }-*/;
+
+ public native void
setEx(com.dotspots.rpcplus.example.torturetest.client.SimpleException ex)
/*-{
+ this[1] = ex;
+ }-*/;
+
+ public native boolean isSetEx() /*-{
+ return this[1] != null;
+ }-*/;
+
+ public native void unsetEx() /*-{
+ delete this[1];
+ }-*/;
+
+}
=======================================
---
/trunk/gwt-rpc-plus/example/gen-java-gwt/com/dotspots/rpcplus/example/torturetest/client/TortureTestApi_testThrowsAnUnpositionedException_result.java
Mon Nov 30 10:50:09 2009
+++
/trunk/gwt-rpc-plus/example/gen-java-gwt/com/dotspots/rpcplus/example/torturetest/client/TortureTestApi_testThrowsAnUnpositionedException_result.java
Tue Mar 23 20:33:15 2010
@@ -12,12 +12,12 @@

/* Factory method */
public static TortureTestApi_testThrowsAnUnpositionedException_result
create() {
- return
com.google.gwt.core.client.JavaScriptObject.createArray().cast();
+ return
com.google.gwt.core.client.JavaScriptObject.createObject().cast();
}

/* Factory method, strongly dependent on order of fields */
- public static native
TortureTestApi_testThrowsAnUnpositionedException_result create(String
success) /*-{
- return [success];
+ public static native
TortureTestApi_testThrowsAnUnpositionedException_result
create(com.dotspots.rpcplus.example.torturetest.client.SimpleException ex,
String success) /*-{
+ return {"-1": ex, "0": success, };
}-*/;

public native String getSuccess() /*-{
@@ -36,4 +36,20 @@
delete this[0];
}-*/;

-}
+ public native
com.dotspots.rpcplus.example.torturetest.client.SimpleException getEx() /*-{
+ return this[-1];
+ }-*/;
+
+ public native void
setEx(com.dotspots.rpcplus.example.torturetest.client.SimpleException ex)
/*-{
+ this[-1] = ex;
+ }-*/;
+
+ public native boolean isSetEx() /*-{
+ return this[-1] != null;
+ }-*/;
+
+ public native void unsetEx() /*-{
+ delete this[-1];
+ }-*/;
+
+}
=======================================
---
/trunk/gwt-rpc-plus/example/gen-java-gwt/com/dotspots/rpcplus/example/torturetest/client/TortureTestApi_testThrowsTwoExceptions_args.java
Mon Nov 30 10:50:09 2009
+++
/trunk/gwt-rpc-plus/example/gen-java-gwt/com/dotspots/rpcplus/example/torturetest/client/TortureTestApi_testThrowsTwoExceptions_args.java
Tue Mar 23 20:33:15 2010
@@ -12,7 +12,28 @@

/* Factory method */
public static TortureTestApi_testThrowsTwoExceptions_args create() {
- return
com.google.gwt.core.client.JavaScriptObject.createArray().cast();
- }
+ return
com.google.gwt.core.client.JavaScriptObject.createObject().cast();
+ }
+
+ /* Factory method, strongly dependent on order of fields */
+ public static native TortureTestApi_testThrowsTwoExceptions_args
create(int which) /*-{
+ return {"-1": which, };
+ }-*/;
+
+ public native int getWhich() /*-{
+ return this[-1];
+ }-*/;
+
+ public native void setWhich(int which) /*-{
+ this[-1] = which;
+ }-*/;
+
+ public native boolean isSetWhich() /*-{
+ return this[-1] != null;
+ }-*/;
+
+ public native void unsetWhich() /*-{
+ delete this[-1];
+ }-*/;

}
=======================================
---
/trunk/gwt-rpc-plus/example/gen-java-gwt/com/dotspots/rpcplus/example/torturetest/client/TortureTestApi_testThrowsTwoExceptions_result.java
Mon Nov 30 10:50:09 2009
+++
/trunk/gwt-rpc-plus/example/gen-java-gwt/com/dotspots/rpcplus/example/torturetest/client/TortureTestApi_testThrowsTwoExceptions_result.java
Tue Mar 23 20:33:15 2010
@@ -16,8 +16,8 @@
}

/* Factory method, strongly dependent on order of fields */
- public static native TortureTestApi_testThrowsTwoExceptions_result
create(String success) /*-{
- return [success];
+ public static native TortureTestApi_testThrowsTwoExceptions_result
create(String success,
com.dotspots.rpcplus.example.torturetest.client.SimpleException ex,
com.dotspots.rpcplus.example.torturetest.client.MoreComplexException ex2)
/*-{
+ return [success,ex,ex2];
}-*/;

public native String getSuccess() /*-{
@@ -36,4 +36,36 @@
delete this[0];
}-*/;

-}
+ public native
com.dotspots.rpcplus.example.torturetest.client.SimpleException getEx() /*-{
+ return this[1];
+ }-*/;
+
+ public native void
setEx(com.dotspots.rpcplus.example.torturetest.client.SimpleException ex)
/*-{
+ this[1] = ex;
+ }-*/;
+
+ public native boolean isSetEx() /*-{
+ return this[1] != null;
+ }-*/;
+
+ public native void unsetEx() /*-{
+ delete this[1];
+ }-*/;
+
+ public native
com.dotspots.rpcplus.example.torturetest.client.MoreComplexException
getEx2() /*-{
+ return this[2];
+ }-*/;
+
+ public native void
setEx2(com.dotspots.rpcplus.example.torturetest.client.MoreComplexException
ex2) /*-{
+ this[2] = ex2;
+ }-*/;
+
+ public native boolean isSetEx2() /*-{
+ return this[2] != null;
+ }-*/;
+
+ public native void unsetEx2() /*-{
+ delete this[2];
+ }-*/;
+
+}
=======================================
---
/trunk/gwt-rpc-plus/example/gen-javabean/com/dotspots/rpcplus/example/torturetest/TortureTestApi.java
Tue Nov 3 15:45:07 2009
+++
/trunk/gwt-rpc-plus/example/gen-javabean/com/dotspots/rpcplus/example/torturetest/TortureTestApi.java
Tue Mar 23 20:33:15 2010
@@ -30,7 +30,7 @@

public String testDeclaresAnException() throws SimpleException,
TException;

- public String testThrowsTwoExceptions() throws SimpleException,
MoreComplexException, TException;
+ public String testThrowsTwoExceptions(int which) throws
SimpleException, MoreComplexException, TException;

public SimpleException testExceptionPassthru(SimpleException ex)
throws TException;

@@ -225,16 +225,17 @@
throw new
TApplicationException(TApplicationException.MISSING_RESULT, "testDeclaresAnException
failed: unknown result");
}

- public String testThrowsTwoExceptions() throws SimpleException,
MoreComplexException, TException
- {
- send_testThrowsTwoExceptions();
+ public String testThrowsTwoExceptions(int which) throws
SimpleException, MoreComplexException, TException
+ {
+ send_testThrowsTwoExceptions(which);
return recv_testThrowsTwoExceptions();
}

- public void send_testThrowsTwoExceptions() throws TException
+ public void send_testThrowsTwoExceptions(int which) throws TException
{
oprot_.writeMessageBegin(new TMessage("testThrowsTwoExceptions",
TMessageType.CALL, seqid_));
testThrowsTwoExceptions_args args = new
testThrowsTwoExceptions_args();
+ args.which = which;
args.write(oprot_);
oprot_.writeMessageEnd();
oprot_.getTransport().flush();
@@ -816,7 +817,7 @@
iprot.readMessageEnd();
testThrowsTwoExceptions_result result = new
testThrowsTwoExceptions_result();
try {
- result.success = iface_.testThrowsTwoExceptions();
+ result.success = iface_.testThrowsTwoExceptions(args.which);
} catch (SimpleException ex) {
result.ex = ex;
} catch (MoreComplexException ex2) {
@@ -2539,8 +2540,19 @@

public static class testThrowsTwoExceptions_args implements TBase,
java.io.Serializable, Cloneable {
private static final TStruct STRUCT_DESC = new
TStruct("testThrowsTwoExceptions_args");
+ private static final TField WHICH_FIELD_DESC = new TField("which",
TType.I32, (short)-1);
+
+ private int which;
+ public static final int WHICH = -1;
+
+ private final Isset __isset = new Isset();
+ private static final class Isset implements java.io.Serializable {
+ public boolean which = false;
+ }

public static final Map<Integer, FieldMetaData> metaDataMap =
Collections.unmodifiableMap(new HashMap<Integer, FieldMetaData>() {{
+ put(WHICH, new FieldMetaData("which", TFieldRequirementType.DEFAULT,
+ new FieldValueMetaData(TType.I32)));
}});

static {
@@ -2549,20 +2561,56 @@

public testThrowsTwoExceptions_args() {
}
+
+ public testThrowsTwoExceptions_args(
+ int which)
+ {
+ this();
+ this.which = which;
+ this.__isset.which = true;
+ }

/**
* Performs a deep copy on <i>other</i>.
*/
public testThrowsTwoExceptions_args(testThrowsTwoExceptions_args
other) {
+ __isset.which = other.__isset.which;
+ this.which = other.which;
}

@Override
public testThrowsTwoExceptions_args clone() {
return new testThrowsTwoExceptions_args(this);
}
+
+ public int getWhich() {
+ return this.which;
+ }
+
+ public void setWhich(int which) {
+ this.which = which;
+ this.__isset.which = true;
+ }
+
+ public void unsetWhich() {
+ this.__isset.which = false;
+ }
+
+ // Returns true if field which is set (has been asigned a value) and
false otherwise
+ public boolean isSetWhich() {
+ return this.__isset.which;
+ }

public void setFieldValue(int fieldID, Object value) {
switch (fieldID) {
+ case WHICH:
+ if (value == null) {
+ unsetWhich();
+ } else {
+ setWhich((Integer)value);
+ }
+ break;
+
default:
throw new IllegalArgumentException("Field " + fieldID + " doesn't
exist!");
}
@@ -2570,6 +2618,9 @@

public Object getFieldValue(int fieldID) {
switch (fieldID) {
+ case WHICH:
+ return new Integer(getWhich());
+
default:
throw new IllegalArgumentException("Field " + fieldID + " doesn't
exist!");
}
@@ -2578,6 +2629,8 @@
// Returns true if field corresponding to fieldID is set (has been
asigned a value) and false otherwise
public boolean isSet(int fieldID) {
switch (fieldID) {
+ case WHICH:
+ return isSetWhich();
default:
throw new IllegalArgumentException("Field " + fieldID + " doesn't
exist!");
}
@@ -2595,6 +2648,15 @@
public boolean equals(testThrowsTwoExceptions_args that) {
if (that == null)
return false;
+
+ boolean this_present_which = true;
+ boolean that_present_which = true;
+ if (this_present_which || that_present_which) {
+ if (!(this_present_which && that_present_which))
+ return false;
+ if (this.which != that.which)
+ return false;
+ }

return true;
}
@@ -2615,6 +2677,14 @@
}
switch (field.id)
{
+ case WHICH:
+ if (field.type == TType.I32) {
+ this.which = iprot.readI32();
+ this.__isset.which = true;
+ } else {
+ TProtocolUtil.skip(iprot, field.type);
+ }
+ break;
default:
TProtocolUtil.skip(iprot, field.type);
break;
@@ -2630,6 +2700,9 @@
validate();

oprot.writeStructBegin(STRUCT_DESC);
+ oprot.writeFieldBegin(WHICH_FIELD_DESC);
+ oprot.writeI32(this.which);
+ oprot.writeFieldEnd();
oprot.writeFieldStop();
oprot.writeStructEnd();
}
@@ -2639,6 +2712,9 @@
StringBuilder sb = new
StringBuilder("testThrowsTwoExceptions_args(");
boolean first = true;

+ sb.append("which:");
+ sb.append(this.which);
+ first = false;
sb.append(")");
return sb.toString();
}
=======================================
---
/trunk/gwt-rpc-plus/example/gen-json-server/com/dotspots/rpcplus/example/torturetest/TortureTestApiJson.java
Thu Nov 5 09:53:20 2009
+++
/trunk/gwt-rpc-plus/example/gen-json-server/com/dotspots/rpcplus/example/torturetest/TortureTestApiJson.java
Tue Mar 23 20:33:15 2010
@@ -221,7 +221,7 @@
TortureTestApi.testThrowsTwoExceptions_args args =
readTortureTestApi_testThrowsTwoExceptions_args(in);
TortureTestApi.testThrowsTwoExceptions_result result = new
TortureTestApi.testThrowsTwoExceptions_result();
try {
- String methodResult = service.testThrowsTwoExceptions();
+ String methodResult =
service.testThrowsTwoExceptions(args.getWhich());
result.setSuccess(methodResult);
out.writeListBegin(null);
out.writeI32(0); // Version
@@ -616,6 +616,11 @@
int fieldId;
while(protocol.hasNext()) {
switch (protocol.readI32()) {
+ case -1: {
+
com.dotspots.rpcplus.example.torturetest.SimpleException value0 =
readSimpleException(protocol);
+ obj.setEx(value0);
+ break;
+ }
case 0: {
String value0 = protocol.readString();
obj.setSuccess(value0);
@@ -635,6 +640,11 @@
return;
}
protocol.writeStructBegin(null);
+ if (obj.isSetEx()) {
+ protocol.writeI32(-1);
+ com.dotspots.rpcplus.example.torturetest.SimpleException
value0 = obj.getEx();
+ writeSimpleException(protocol, value0);
+ }
if (obj.isSetSuccess()) {
protocol.writeI32(0);
String value0 = obj.getSuccess();
@@ -848,6 +858,11 @@
int fieldId;
while(protocol.hasNext()) {
switch (protocol.readI32()) {
+ case -1: {
+ int value0 = protocol.readI32();
+ obj.setWhich(value0);
+ break;
+ }
default:
protocol.skip();
}
@@ -862,6 +877,11 @@
return;
}
protocol.writeStructBegin(null);
+ if (obj.isSetWhich()) {
+ protocol.writeI32(-1);
+ int value0 = obj.getWhich();
+ protocol.writeI32(value0);
+ }
protocol.writeStructEnd();
}

@@ -1178,6 +1198,11 @@
obj.setSuccess(value0);
break;
}
+ case 1: {
+
com.dotspots.rpcplus.example.torturetest.SimpleException value0 =
readSimpleException(protocol);
+ obj.setEx(value0);
+ break;
+ }
default:
protocol.skip();
}
@@ -1197,6 +1222,11 @@
String value0 = obj.getSuccess();
protocol.writeString(value0);
}
+ if (obj.isSetEx()) {
+ protocol.writeI32(1);
+ com.dotspots.rpcplus.example.torturetest.SimpleException
value0 = obj.getEx();
+ writeSimpleException(protocol, value0);
+ }
protocol.writeStructEnd();
}

@@ -1914,6 +1944,16 @@
obj.setSuccess(value0);
break;
}
+ case 1: {
+
com.dotspots.rpcplus.example.torturetest.SimpleException value0 =
readSimpleException(protocol);
+ obj.setEx(value0);
+ break;
+ }
+ case 2: {
+
com.dotspots.rpcplus.example.torturetest.MoreComplexException value0 =
readMoreComplexException(protocol);
+ obj.setEx2(value0);
+ break;
+ }
default:
protocol.skip();
}
@@ -1933,6 +1973,16 @@
String value0 = obj.getSuccess();
protocol.writeString(value0);
}
+ if (obj.isSetEx()) {
+ protocol.writeI32(1);
+ com.dotspots.rpcplus.example.torturetest.SimpleException
value0 = obj.getEx();
+ writeSimpleException(protocol, value0);
+ }
+ if (obj.isSetEx2()) {
+ protocol.writeI32(2);
+ com.dotspots.rpcplus.example.torturetest.MoreComplexException
value0 = obj.getEx2();
+ writeMoreComplexException(protocol, value0);
+ }
protocol.writeStructEnd();
}

@@ -1970,6 +2020,11 @@
obj.setSuccess(value0);
break;
}
+ case 1: {
+
com.dotspots.rpcplus.example.torturetest.SimpleException value0 =
readSimpleException(protocol);
+ obj.setEx(value0);
+ break;
+ }
default:
protocol.skip();
}
@@ -1989,6 +2044,11 @@
String value0 = obj.getSuccess();
protocol.writeString(value0);
}
+ if (obj.isSetEx()) {
+ protocol.writeI32(1);
+ com.dotspots.rpcplus.example.torturetest.SimpleException
value0 = obj.getEx();
+ writeSimpleException(protocol, value0);
+ }
protocol.writeStructEnd();
}

=======================================
---
/trunk/gwt-rpc-plus/example/server-example/com/dotspots/rpcplus/example/jsonrpc/thrift/ExampleService.java
Tue Nov 3 15:45:07 2009
+++
/trunk/gwt-rpc-plus/example/server-example/com/dotspots/rpcplus/example/jsonrpc/thrift/ExampleService.java
Tue Mar 23 20:33:15 2010
@@ -111,8 +111,17 @@
throw new SimpleException("Hey!");
}

- public String testThrowsTwoExceptions() throws SimpleException,
MoreComplexException, TException {
- throw new SimpleException("Hey!");
+ public String testThrowsTwoExceptions(int which) throws SimpleException,
MoreComplexException, TException {
+ if (which == 0) {
+ throw new SimpleException("Hey!");
+ }
+
+ Set<String> set = new HashSet<String>();
+ for (int i = 0; i < 4; i++) {
+ set.add("hi" + i);
+ }
+
+ throw new MoreComplexException("Message!", new
ObjectWithComplexTypes(null, set, null, null));
}

public ContextOut __getContext() throws TException {
=======================================
--- /trunk/gwt-rpc-plus/example/torturetest.thrift Tue Nov 3 15:45:07 2009
+++ /trunk/gwt-rpc-plus/example/torturetest.thrift Tue Mar 23 20:33:15 2010
@@ -62,7 +62,7 @@
string testThrowsAnException() throws (1:SimpleException ex);
string testThrowsAnUnpositionedException() throws (SimpleException ex);
string testDeclaresAnException() throws (1:SimpleException ex);
- string testThrowsTwoExceptions() throws (1:SimpleException ex,
2:MoreComplexException ex2);
+ string testThrowsTwoExceptions(i32 which) throws (1:SimpleException ex,
2:MoreComplexException ex2);
SimpleException testExceptionPassthru(1:SimpleException ex);

string testPositionalArguments(1:i32 int32, 2:string str);
=======================================
---
/trunk/gwt-rpc-plus/gwt/com/dotspots/rpcplus/client/jsonrpc/thrift/ThriftClientStub.java
Fri Nov 27 11:14:24 2009
+++
/trunk/gwt-rpc-plus/gwt/com/dotspots/rpcplus/client/jsonrpc/thrift/ThriftClientStub.java
Tue Mar 23 20:33:15 2010
@@ -98,15 +98,17 @@
responseContext = response.getResponseContext();
int responseCode = response.getResponseCode();
if (responseCode == 0) {
+ final BaseJsRpcObject responseObject = response.getResponseObject();
+
@SuppressWarnings("unchecked")
- final R castResult = (R)
response.getResponseObject().getFieldValue(0);
+ final R castResult = (R) responseObject.getFieldValue(0);
callback.onSuccess(castResult);

return;
}

fireOnAfterCall();
- onException(methodId, callback, responseCode,
response.getResponseContext());
+ onException(methodId, callback, responseCode,
response.getResponseObject());
}
});
}
=======================================
---
/trunk/gwt-rpc-plus/test/gwt-test/com/dotspots/rpcplus/test/client/TestThriftRPC.java
Thu Nov 5 09:53:20 2009
+++
/trunk/gwt-rpc-plus/test/gwt-test/com/dotspots/rpcplus/test/client/TestThriftRPC.java
Tue Mar 23 20:33:15 2010
@@ -4,6 +4,7 @@
import com.dotspots.rpcplus.client.jsonrpc.thrift.CallInterceptor;
import com.dotspots.rpcplus.example.torturetest.client.ContextIn;
import com.dotspots.rpcplus.example.torturetest.client.ContextOut;
+import
com.dotspots.rpcplus.example.torturetest.client.MoreComplexException;
import com.dotspots.rpcplus.example.torturetest.client.ObjectWithEnum;
import com.dotspots.rpcplus.example.torturetest.client.SimpleEnum;
import com.dotspots.rpcplus.example.torturetest.client.SimpleException;
@@ -80,6 +81,48 @@
api.testThrowsAnException(new AsyncCallback<String>() {
public void onFailure(Throwable caught) {
assertTrue("Wrong exception type: " + caught.getClass(), caught
instanceof SimpleException);
+ assertEquals("Hey!", caught.getMessage());
+ finishTest();
+ }
+
+ public void onSuccess(String result) {
+ fail("Shouldn't have succeeded");
+ }
+ });
+ }
+
+ public void testThrowsTwoExceptions() {
+ delayTestFinish(15000);
+
+ api.testThrowsTwoExceptions(1, new AsyncCallback<String>() {
+ public void onFailure(Throwable caught) {
+ assertTrue("Wrong exception type: " + caught.getClass(), caught
instanceof MoreComplexException);
+ assertEquals("Message!", caught.getMessage());
+
+ JsRpcSetString result = ((MoreComplexException)
caught).getData().getSetOfStrings();
+ assertEquals(4, result.countSize());
+ assertTrue(result.contains("hi0"));
+ assertTrue(result.contains("hi1"));
+ assertTrue(result.contains("hi2"));
+ assertTrue(result.contains("hi3"));
+ assertFalse(result.contains("hi4"));
+
+ finishTest();
+ }
+
+ public void onSuccess(String result) {
+ fail("Shouldn't have succeeded");
+ }
+ });
+ }
+
+ public void testThrowsTwoExceptions2() {
+ delayTestFinish(15000);
+
+ api.testThrowsTwoExceptions(0, new AsyncCallback<String>() {
+ public void onFailure(Throwable caught) {
+ assertTrue("Wrong exception type: " + caught.getClass(), caught
instanceof SimpleException);
+ assertEquals("Hey!", caught.getMessage());
finishTest();
}

Reply all
Reply to author
Forward
0 new messages