GWT development mode is quiet - gwt

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)

Related

What are the limitations of #Transactional in CDI?

I am trying to use a #Transactional method inside a CDI class, instead of an EJB:
#javax.inject.Named
// fails #javax.enterprise.context.ApplicationScoped
// fails #javax.enterprise.context.SessionScoped
// works #javax.ejb.Singleton
// works #javax.ejb.Stateless
public class SomeClass {
#javax.persistence.PersistenceContext
private EntityManager em;
#javax.annotation.PostConstruct
#javax.transaction.Transactional
public void someMethod() {
em.persist(someEntity);
}
}
When I annotate SomeClass with #Singleton or #Stateless, everything works.
When I annotate SomeClass with #ApplicationScoped or #SessionScoped, WildFly 13 displays the following error message:
Transaction is required to perform this operation (either use a transaction or extended persistence context)
I was under the impression that #Transactional works with CDI since Java EE 7. Have I been mistaken? Or am I simply missing some additional configuration?
I'll try to give a short list of things to look when trying to make #Transactional work with CDI, so as to give the answer a bit more value than the comment:
We are discussing javax.transaction.Transactional, not javax.ejb.TransactionAttribute, which works for EJBs!
It does NOT work out-of-the-box in non-JEE applications!
And by JEE applications we mean those running a full JEE application server; Tomcat out-of-the-box does NOT support it!
Beware of classpath problems, specifically make sure no jar containing the annotation javax.transaction.Transactional exists e.g. in WEB-INF/lib, when running in a full JEE application server. If you want to utilize it in a non-full-JEE environment, you will need to have it in the classpath.
#Transactional is implemented as a CDI interceptor by the latest JTA specifications. As such:
It's not there in JEE < 7!
It has the same limitations as any interceptor. E.g. it cannot be called for initializer methods - #PostConstruct [THIS WAS THE PROBLEM IN THIS QUESTION], and it is NOT activated when invoking methods of this object, BEWARE!!!
I am quite confident that more errors may exist!!!

DI and inheritance

Another question appeared during my migration from an E3 application to a pure E4.
I got a Structure using inheritance as in the following pic.
There I have an invocation sequence going from the AbstractRootEditor to the FormRootEditor to the SashCompositeSubView to the TableSubView.
There I want to use my EMenuService, but it is null due to it can´t be injected.
The AbstractRootEditor is the only class connected to the Application Model (as a MPart created out of an MPartDescriptor).
I´d like to inject the EMenuService anyway in the AbstractSubView, otherwise I would´ve the need to carry the Service through all of my classes. But I don´t have an IEclipseContext there, due to my AbstractSubView is not connected with Application Model (Do I ?).
I there any chance to get the service injected in the AvstractSubView?
EDIT:
I noticed that injecting this in my AbstractSubView isn´t possible (?), so I´m trying to get it into my TableSubView.
After gregs comment i want to show some code:
in the AbstractRootEditor:
#PostConstruct
public final void createPartControl(Composite parent, #Active MPart mPart) {
...
ContextInjectionFactory.make(TableSubView.class, mPart.getContext());
First I got an Exception, saying that my TableSubView.class got an invalid constructor, so now the Constructor there is:
public TableSubView() {
this.tableInputController=null;
}
as well as my Field-Injection:
#Inject EMenuService eMenuService
This is kind of not working, eMenuService is still null
If you create your objects using ContextInjectionFactory they will be injected. Use:
MyClass myClass = ContextInjectionFactory.make(MyClass.class, context);
where context is an IEclipseContext (so you have to do this for every class starting from one that is injected by Eclipse).
There is also a seconds version of ContextInjectionFactory.make which lets you provide two contexts the second one being a temporary context which can contain additional values.

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

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

How do LogService and LogReaderService in Equinox work along?

I'm developing a OSGi Equinox bundle and I'd like to add some logging to it, mostly to be redirected to the OSGi console, just for debugging purposes.
After discarding the usage of log4j, since there are a couple of logging services in Equinox (LogService and ExtendedLogService), I found this article describing how to use the LogService:
OSGi Log Service
So I came up with an Activator that looks like this:
package org.example.servlet;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import org.osgi.service.log.LogService;
import org.osgi.util.tracker.ServiceTracker;
import org.eclipse.equinox.log.ExtendedLogService;
public class Activator implements BundleActivator {
private static BundleContext context;
private ServiceTracker logServiceTracker;
private LogService logService;
static BundleContext getContext() {
return context;
}
/*
* (non-Javadoc)
* #see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
*/
public void start(BundleContext bundleContext) throws Exception {
Activator.context = bundleContext;
// create a tracker and track the log service
logServiceTracker = new ServiceTracker(context, LogService.class.getName(), null);
logServiceTracker.open();
// grab the service
logService = (LogService) logServiceTracker.getService();
if(logService != null)
logService.log(LogService.LOG_INFO, "Yee ha, I'm logging!");
}
/*
* (non-Javadoc)
* #see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
*/
public void stop(BundleContext bundleContext) throws Exception {
Activator.context = null;
}
Well, I never see the logged message in the OSGi console...looking for some more info, I found this thread:
How to use Equiniox's LogService ?
Some answers suggest that I should implement a LogServiceReader object that actually listens for logging events and (this is just my guess), redirects logged messages to whatever (file, console, etc...)
Now my question, more than how to implement this interface, is how do I do the binding between my implementation of the LogServiceReader and the LogService used in the Activator...
Thanks!
Alex
To answer the question directly:
A LogService is a service responsible for storing log messages.
A LogReaderService is a service responsible for reading these log messages and dispatching them to log listeners.
The binding between these is done automatically.
What you will do yourself is log messages to the LogService on the one side, and possibly bind LogListeners to the LogReaderService, that will write out the logs somewhere, for example the console, on the other side.
To solve your problem of the logs not appearing, you need to do a few additional things.
First of all, did you install a bundle offering an implementation of the LogService and the LogReaderService into your osgi container?
You can check for the presense of an org.osgi.service.log.LogService by adding something like this to your Activator:
if(logService != null){
System.out.println("There is a LogService available");
logService.log(LogService.LOG_INFO, "Yee ha, I'm logging!");
}
else {
System.out.println("There is no LogService available");
}
Or just type "bundles" in the equinox console and look for a bundle offering an org.osgi.service.log.LogService and an org.osgi.service.log.LogReaderService.
If no LogService is available, install one. For example:
install http://oscar-osgi.sf.net/repo/log/log.jar
The org.apache.log4j equinox dependency offers such a service too.
Start and stop your own bundle again. It should now print "There is a LogService available".
Now your messages are logged to the LogService and processed by the LogReaderService, but still, since there might be no LogListeners registered with this service(depending on other bundles started),
You might need to have to add a LogListener yourself in your bundle Activator.
For an example bundle Activator who does this, check http://blog.kornr.net/index.php/2008/12/09/understanding-the-osgi-logging-service.
Well, just in case someone else is interested in the subject. I found a really nice wiki in Google Code explaining how OSGi logging system works that is a 'must read':
Understanding OSGi Logging
Since I only want to use a log to print in console, the solution proposed there works for me. Only problem was finding an implementation of the LogService that worked as expected. The one pointed out in the article actually works, but implements version 1.1 while what current LogService specification is at version 1.3 as far as I know. So what I did was, downloaded the sources from the previous implementation and adapted that implementation to my taste and to latest version (1.3) specification. You can find sources here.
Obviously, you can also use yours or any others implementation of the LogService interfaces, up to you.
Besides, if you plan to use a back-end existing logging service, such as commons-logging, or sl4j, etc...I recommend these links, they provide great info about where to start:
Building backend
OSGi logging overview
This was overkill for me, since all I wanted was a way to print messages in the OSGi console, but without having to use log4j, fragments and the like.
Hope somebody found this useful
Regards,
Alex

Failure at loading GWT library

I am trying to deploy a bigger GWT project to start working on it. After several problems I finally ran into the following, which I am not able to solve:
Here is a random piece of code:
service.getSuggestionOracle(this.suggestionString.getText(), new AsyncCallback<List<Entity>>() {
#Override
public void onSuccess(List<Entity> result) {
suggestionString.setStyleName("searchInput");
processSuggestionOracle(result);
}
#Override
public void onFailure(Throwable caught) {
suggestionString.setStyleName("searchInput");
GWT.log("Suggestion fails.");
}
});
Eclipse complains about the two functions onSuccess and onFailure that:
The method onSuccess(List<Entity>) of type new AsyncCallback<List<Entity>>(){} must override a superclass method
Indeed when I hover over the: new AsyncCallback<List<Entity>>() statement, it tells me that If an RPC is successful, then onSuccess(Object) is called, otherwise onFailure(Throwable) is called.
I conclude that there IS a superclasses with declarations for onSuccess and onFailure, but the compiler doesn't find it.
I use GWT-2.4.0 and the GWT library is added to the classpath.
The code above is just a random example, there are about 150 similar errors all over the
project. Additionally, there are several imports like com.xind.gwt.dom.client.DOM,
that can not be resolved.
Does anybody have an idea what I am missing here?
There are two possibilities that I could think of:
you haven't extended RemoteServiceServlet on the server implementation.
or
In this code,
public void onSuccess(List result) {
}
you have List as the returned object. Is this a list of objects of a user-defined class or java datatype? If the list is a user-defined type, then you must serialize the corresponding class by implementing java.io.serializable;