没有任何数据可供显示
开源项目社区 | 当前位置 : |
|
www.trustie.net/open_source_projects | 主页 > 开源项目社区 > gwt-rpc-annotation |
gwt-rpc-annotation
|
0 | 0 | 4 |
贡献者 | 讨论 | 代码提交 |
IntroductionThe gwt-rpc-annotation library simplifies the development of GWT-RPC services through the use of a JSR-269 annotation processor.
It was initially developed at Solium Capital and Solium is happy to contribute it back to the community.
OverviewNormally, when implementing a GWT-RPC service, three files must be maintained
A class to implement the service An interface for the service which defines all the exposed methods An asynchronous interface, which is used when the service is called from the client side
With this annotation processor, you simply need to implement the class which implements the service. You can then use an annotation to mark a method as something which should be exposed, and the annotation processor will automatically generate both interfaces for you.
In other words, all you have to do is write a method and annotate it like follows:
@GwtRpcServlet
public class FooServiceImpl extends RemoteServiceServlet implements FooService {
@GwtRpcMethod
public String foo() {
return "bar";
}
}And the annotation processor will automatically generate the interface classes for you:
public interface FooService extends RemoteService {
String foo() {
}
public interface FooServiceAsync {
void foo(AsyncCallback async);
}UsageTo use this library:
Annotate methods to be exposed with the @GwtRpcMethod annotation Servlets which contain methods to be exposed need be annotated with the @GwtRpcServlet annotation. This annotation has an optional remoteServiceRelativePath argument - if specified, it will put the value in the @RemoteServiceRelativePath annotation in the generated interface
A sample is provided in the sample directory - update build.properties with the location of your GWT install.
Java 6 is required, as JSR-269 was only introduced in Java 6.
ConfigurationThe generation of these classes can be configured by creating a custom implementation of the GwtRpcAnnotationConfig. This custom implementation is passed to the annotation processor via the gwtRpcAnnotation.config parameter. By implementing this class, you can:
Control the package name of the generated interfaces Add standard exceptions to all exposed GWT-RPC methods. GWT-RPC requires that all exceptions thrown by a method are declared in the interface. We use this to add in exceptions that aren't necessarily thrown by the method itself, but are instead thrown by generic code in RemoteServiceServlet.onAfterRequestDeserialized which implements some cross-cutting-concerns Add any additional common code to all interfaces, for example if you want a common static variable in all your interfaces.