GWTP REST-Dispatch - What is the new usage for rest dispach, since the removal of the RestService interface in 1.5 release - rest

Hi everybody,
I encounter implementation issues with the rest-dispatch module of the gwtp framework.
If i follow the current documentation, the resource interface defining what a service provide should be as follow:
#Path(FOO)
#Produces(MediaType.APPLICATION_JSON)
public interface FooResource {
#GET
RestAction<FooDTO> getFoo();
}
On the client side (without delegate extension):
#Inject RestDispatch dispatcher;
#Inject FooResource fooResource;
...
dispatcher.execute(fooResource.getFoo(), new AsyncCallback<FooDTO>() {
#Override
public void onFailure(Throwable throwable) {
}
#Override
public void onSuccess(FooDTO fooDto) {
}
});
...
Question
The RestDispatch is waiting for method that return RestAction, but since the RestService interface has been remove from 1.5 release:
How can i implements the FooResource ?
Moreover
In the carstore sample project, the only resource that uses RestAction is:
https://github.com/ArcBees/GWTP-Samples/blob/master/carstore/src/main/java/com/gwtplatform/carstore/shared/api/StatisticsResource.java
But it's implementation, is in fact not an implementation in that case:
https://github.com/ArcBees/GWTP-Samples/blob/master/carstore/src/main/java/com/gwtplatform/carstore/server/api/StatisticsResourceImpl.java
Should i follow this example, and what is the purpose of an non-implemented Interface ?
I assume that my question is very specific and it is maybe principally directed to the authors of gwtp.
And i thank in advance those who will respond.

The rest-dispatch is a client-library, and the interface that describes the services are not to use on the server side.
I was attempting to do something not intended by the authors of GWTP.
Yet, the DelegateResource extension is a solution, if you want to use the interface on the server side too. It comes with a drawback: the anability to have type safe callback on the client side.
To go further, here the exchange i had with the team on github:
https://github.com/ArcBees/GWTP-Samples/issues/92

Related

How to write tests for tracking event flows in eventbus?

Long description:
In our gwt with mvp4g app we have pretty complicated flow of events in eventbus. One event like LOGIN produces multiple others as a reaction from presenters/handlers. Currently we have great difficulties with understanding how events interrelated i.e. which events must follow this particular one.
We have tests for presenters and views, but we are lacking tests which would clearly show/model event flows, preferably without usage of real views and services.
Short description:
New tests on eventBus(?) should be developed which should clearly describe and test event flows.
I have few rud ideas but they all sounds not satisfactory:
Write custom implementation(could be ugly) of mvp4g eventbus and:
use real presenters
use mock(?) views
mock services
verify all produced service calls
Why not cool: (a) In this case test would not verify produced events directly but only that ones which have services. (b)
EventBus implementation would look rather scarry - it must create each presenter with mocked services and views
Find a way to use some magical mvp4g mechanism to create eventBus in test and mock vies, services.
Why not cool : same as prev - only indirect verification through services is possible, and I cannot find how to create eventBus manually and solve all problems with GIN, inter GWT module dependencies and so. I guess there is no simple way to do it.
Is there any general solution for problem of tracking event tree in tests? Guess I'm not the first person to stare at complicated eventbus event flows.
Do you want to test the eventBus? Or do you want to track all event which are fired?
If you want to track your events, maybe some kind of EventMonitor could help you? A class that implements all necessary EventHandler and log every event that occurs.
Something like that? Just instance that class before your tests starts.
import java.util.logging.Logger;
import com.google.gwt.event.shared.GwtEvent;
import com.google.web.bindery.event.shared.EventBus;
public class EventMonitor implements AEventHandler, BEventHandler /* , ... */{
private static int event_count = 1;
private final Logger logger = Logger.getLogger(this.getClass().getName());
public EventMonitor(EventBus eventBus) {
eventBus.addHandler(AEvent.getType(), this);
eventBus.addHandler(BEvent.getType(), this);
// [...]
}
private void logEvent(GwtEvent<?> event) {
logger.info(event_count + " useful information");
event_count++;
}
#Override
public void onAEvent(AEvent event) {
logEvent(event);
}
#Override
public void onBEvent(BEvent event) {
logEvent(event);
}
}

Multiple REST interfaces in Play! 2 application

We have a Play! application where we need to expose a set of REST interfaces to an intranet and a set of REST interfaces we have to expose to the public internet. They share a data layer so we would like to run them together if possible. My assumption is that they will be running on different ports. Being new to Play!, I don't know if this is possible to do within a single Play! instance. I have looked at modules but that didn't seem to fit what we are doing. Has anyone had any experience with this sort of scenario?
Forgot to mention we are using Play! 2.
You could restrict/permit access to resources by checking the ip.
public class IPLocalSecurity extends Controller {
#Before
public static void checkAccess() throws Exception {
if (!request.remoteAddress.matches("192\.168\.1\.*")) {
forbidden();
}
}
}
and use that in the resources controller.
#With(IPLocalSecurity.class)
public class IntranetController extends Controller{
....
}

GWT development mode is quiet

I'm developing a project with GWT for quite some months but since two weeks or so i get no more feedback in the jetty development mode window when an error occures...
How could that come?? Could it be caused by some missconfiguration of the logging module? Some errors appear on the console of the started jetty application as [INFO].
Try CCleaner Software and clean all Recent files, browser Cache, Temporary files etc. Then just restart eclipse or better restart the entire System. Also, check if you have GWT.log("MESSAGE") method called for Errors/Exceptions.
The strange behaviour with GWT can happen if:
You have "server" (not included source code) class
You have only import to server class
One of your bean used to communication by service is not serializable (or not extends IsSerializable) or any of it attributes is not serializable
Your bean used to communication by service do not have not parameters constructor (or any of parent class)
Your bean used to communication by service has final field
I had almost all from this when I searched why my code is broken. I did not included all cases of course :)
Update
In our project we extends AsyncCallback
public abstract class MyAsyncCallback<T> implements AsyncCallback<T> {
#Override
public final void onFailure(Throwable caught) {
yourLogger.log(caught);
onFailureDefault(caught);
}
protected abstract void onFailureImpl(Throwable caught);
}
You has to replace all your AsyncCallback with this. Now you have control on errors. Sometimes there are suppressed by wrong error handling.
See also GWT.setUncaughtExceptionHandler(GWT.UncaughtExceptionHandler handler)

Serialize aspectj method in GWT

I've try to expose to the client(gwt) an aspectJ method through gwt-rpc, but the gwt client can't find the method defined in an aspect. The class that i expose implements IsSerializable and only it's method are visible to the client interface...the method added by their aspect contrariwise no. How i can fix this? thanks in advice.
p.s. i post a little example for more clarity:
this is the class...
public class Example implements IsSerializable{
private String name;
public setName(String name){
this.name=name
}
}
and this is the aspect...
privileged aspect Example_x{
public int Example.getVersion() {
return this.version;
}
}
The Example.getVersion() method is unavailable on the client side.
TNX
This won't work, as GWT needs access to the source of any Java class that is exposed to the client side. This is necessary to compile them from Java to Javascript. If you modify your classes using AspectJ, the added methods will not be visible to the GWT compiler and therefore not to the client.
I'd say AspectJ is simply the wrong tool for this task. If you want to add some methods to existing classes you could write a (possibly generic) container class that contains an instance of Example as well as the version information from Example_x.

GWT Scaffolding

Is there something similar to Ruby on Rails Scaffolding for creating GWT CRUD?
Spring Roo was announced at Google I/O 2010. That might be what you're looking for.
MyEclipse for Spring 8.6 M2 was just released and it now has GWT scaffolding.
You can download a free 30 day trial here.
GWT isn't a full application stack like Rails, so you might not find a solution that is as integrated and out of the box as Rails. GWT is primarily a view layer - you'd still need a persistence layer.
GWT uses a different paradigm compared to all textbook CRUD frameworks that solve very little IMO. Think of it as a good old Swing. The communication is already built-in (GWT-RPC). The only way to improve it - none of those CRUD frameworks offers - would be to create some patterns (your own richer widget set, etc.) that works on some unified data. And of course the matching code on the server. This way you can use generic GWT-RPC methods and generic data structures to pass data, not millions of methods in all those interfaces. Otherwise GWT-RPC is as good, as any generic CRUD "framework" that'd have those millions methods in the "service facade".
One thing you can do is to "integrate" GWT-RPC with Spring MVC. Only few lines of code - and you can implement your GWT-RPC services as standard Spring #Controllers. They'll have access to all autowired components, etc. What more do you need? You can access absolutely anything through Spring.
So here's how you do it:
public abstract class GwtRpcController extends RemoteServiceServlet implements Controller, ServletConfigAware {
private static Log log = LogFactory.getLog(GwtRpcController.class);
private ServletConfig servletConfig;
#Override
public ServletConfig getServletConfig() {
return servletConfig;
}
#Override
public void setServletConfig(ServletConfig servletConfig) {
try {
this.init(servletConfig);
} catch (ServletException e) {
throw new RuntimeException(e);
}
this.servletConfig = servletConfig;
}
#Override
protected void onAfterRequestDeserialized(RPCRequest rpcRequest) {
super.onAfterRequestDeserialized(rpcRequest);
}
#Override
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
super.doPost(request, response);
return null;
}
#Override
protected void doUnexpectedFailure(Throwable e) {
log.error(e.getMessage(), e);
}
}
And your GWT-RPC service:
#RemoteServiceRelativePath("gwtrpc/xxx")
public interface XxxService extends RemoteService {
...
}
#Controller
#RequestMapping(value = "xxx")
public class XxxServiceImpl extends GwtRpcController implements XxxService {
...
}
Make sure "gwtrpc/*" is mapped to SpringDispatcher servlet in web.xml. Typically you'd map everything ("/") to it and make exceptions for non-Spring resources like CSS, etc. so you don;t need to do anything explicitly.