Skip navigation

Yesterday I’ve discovered GWTEventService. Today i started to play around with it, after some research in the example-svn and reading the docs, I was able to write my own “Hello World”.

This Hello World is a small chatting application. You are only able to send messages but not set a nickname or something similar.

Here you can see what it will look like:gwteventservice-helloworld1

In this short overview I’ll just show you the parts that are associated with the GWTEventSerice. The whole regular GWT UI/RPC stuff is left out. If you want to see the complete example, you can download it here.

First of all you need an Event:

public class MyEvent implements Event {
	public String message;

	public MyEvent(){}

	public MyEvent(String message) {

	public String getMessage() {
		return message;

	public void setMessage(String message) {
		this.message = message;


This Event gets fired when the server gets a new message from a client.

The next thing you need is a EventListener that gets notified when an Event occures:

public class MyListener implements RemoteEventListener {

	 * This function gets called by EventService
	public void apply(Event anEvent) {
		 * Check if the incoming Event is from the type MyEvent and if so, call the corresponding function
		if(anEvent instanceof MyEvent)

	 * This function gets called when the incomming Event is from the Type MyEvent
	 * @param event
	public void onMyEvent(MyEvent event){}


The Listener receives the Events from the server an processes them.

Now on the client-side you need to register your Listener to the server:

	 * The domain to which we want to register our listener to
	private static final Domain DOMAIN = DomainFactory.getDomain("my_domain");

	public void onModuleLoad() {

		 * Create an EventService
		RemoteEventServiceFactory theEventServiceFactory = RemoteEventServiceFactory.getInstance();
		RemoteEventService theEventService = theEventServiceFactory.getRemoteEventService();

		 * Register our listener to the domain
		theEventService.addListener(DOMAIN, new MyListener(){
			public void onMyEvent(MyEvent event){
				 * Get the message from the event and append it to the allready received messages
				getIncommingMessages().setText( getIncommingMessages().getText() + event.getMessage() + "n" );


On the client-side we just register our Listener, and tell him what to do when an Event occurs.

The last thing that we need is the Server:

public class HelloWorldServiceImpl extends RemoteEventServiceServlet implements HelloWorldService {

	 * The Domain that this Service sends Events to.
	private static final Domain DOMAIN = DomainFactory.getDomain("my_domain");

	 * A normal function that gets called when a client sends a message to the server.
	public void sendMessage(String message) {
		 * We dont save the incomming messages on the server. We just send an MyEvent to all
		 * registered Listeners on the Domain.
		this.addEvent(DOMAIN, new MyEvent(message));


Instead of the default RemoteServiceServlet we extend this one with RemoteEventServiceServlet from the GWTEventService lib. This gives you the ability to send Events to the clients.



  1. I get the following error when I run this. Everything else seems to be working fine, but for some reason, the getDomain isn’t working. At least I think that’s where the problem is. Please respond if you can!

    [ERROR] Client-Error: Error on register client for domain!

    Error 404 NOT_FOUND

    HTTP ERROR: 404


    RequestURI=/gwteventservicehelloworld/gwteventservicePowered by Jetty://

    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(
    at java.lang.reflect.Method.invoke(
    at org.eclipse.swt.internal.carbon.OS.ReceiveNextEvent(Native Method)
    at org.eclipse.swt.widgets.Display.sleep(

  2. got it. just had to change some xml files.

    • I’m facing the same problem.
      Goathanger, what XML files did you have to update?


  3. me too. I have the same problem. I need this chatting application.

  4. try adding this line to the gwt.xml file:

    and adding this to war/WEB-INF/web.xml:



  5. I added in gwt.xml:

    <!– –>
    <!– –>

    and in the web.xml:







    But I have the same erreur:

    ATTENTION: failed HelloWorldServlet
    java.lang.NoClassDefFoundError: de/novanic/eventservice/service/RemoteEventServiceServlet
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at Source)
    at Source)
    at$000(Unknown Source)
    at$ Source)
    at Method)
    at Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at org.mortbay.util.Loader.loadClass(
    at org.mortbay.util.Loader.loadClass(
    at org.mortbay.jetty.servlet.Holder.doStart(
    at org.mortbay.jetty.servlet.ServletHolder.doStart(
    at org.mortbay.component.AbstractLifeCycle.start(
    at org.mortbay.jetty.servlet.ServletHandler.initialize(
    at org.mortbay.jetty.servlet.Context.startContext(
    at org.mortbay.jetty.webapp.WebAppContext.startContext(
    at org.mortbay.jetty.handler.ContextHandler.doStart(
    at org.mortbay.jetty.webapp.WebAppContext.doStart(
    at org.mortbay.component.AbstractLifeCycle.start(
    at org.mortbay.jetty.handler.HandlerWrapper.doStart(
    at org.mortbay.component.AbstractLifeCycle.start(
    at org.mortbay.jetty.handler.HandlerWrapper.doStart(
    at org.mortbay.jetty.Server.doStart(
    at org.mortbay.component.AbstractLifeCycle.start(
    Caused by: java.lang.ClassNotFoundException: de.novanic.eventservice.service.RemoteEventServiceServlet
    at$ Source)
    at Method)
    at Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClassInternal(Unknown Source)
    … 35 more

    • Have you added the gwteventservice jars to you Classpath?

  6. Yes, I added this library on my project.

  7. hi
    i’m about to learn how to use GWT & EventService , each time i try to understand how its work i face a new problem, i asked the community but still there is no answer,so i started to search and found your blog and your source code that is very nice and clean.
    but i still couldn’t compile and run it.
    i tested with GWT 1.5 , 1.7 & 2.0
    none of them works.
    shouldn’t i create a GWT Project and add the eventService to the classpath ? should i make a Java project and add the GWT and eventService to its classPath?
    can you please help me on compiling and running your project

  8. Due to the problems many of you have with this example i have imported the zip-file as a new project in a clean eclipse installation.

    Besides some errors about the unbound GWT_HOME var everything worked fine. Which errors does eclipse show in your problems-view?


  9. thanks for you consideration
    here are the steps that i do :
    1. unzip the folder
    2. import it to the eclipse
    3. right click on the project select run as > Run On server > Tomcat v6 server at localhost > finish
    and here is the image of result :

    should i change the url ?
    can you please help me what should i do

    Bamdad Dashtban

  10. It looks as if you havent enabled GWT for the project.

    Rightclick on the project -> google -> web toolkit settings -> use gwt web toolkit.

    Then you should be able to select “run as web application”

  11. thanks it works.

  12. i was checking your code today ,and i found it works with gwt 1.5 but fails with gwt 1.7 & gwt 2, also the code that returns void for the interface had errors in IDE (HelloWorldService & HelloWorldAsync ) .
    have you checked your code with gwt 2 ?

  13. i’ve ported your example into GWT 2.
    thanks for you greate tutorial.
    here is my code :

  14. Hi, guys

    The tut is really cool but I cannot really make it work. I have GWT 2.3 and each time I start it I get error 500 :S
    I am trying, as an example, make client “Test” (which in one project) sends and receives message just to see how the service works;
    The client invokes sendMessage(String message) method to get message back to my client but that causes an error ;
    I suppose it is all because I use code which returns String but the original one is a void one; But the thing is GWT 2.3 throws that there is no way to return Object type so I cannot use void :X

    AServiceAsync s=(AServiceAsync)GWT.create(AService.class);
    AsyncCallback callback=new AsyncCallback()

    public void onFailure(Throwable caught) {
    // TODO Auto-generated method stub


    public void onSuccess(String result) {



    s.sendMessage(message, callback);

    Has somebody faced the same thing? Can you advice something? How to make it work with GWT 2.3?

  15. I should leave a comment to Thank You.
    You really save my ass, I try to understand the official example but they all complicated.
    However your example is so clear and easy to understand!
    Again, thanks for saving me from my university project.

  16. Reblogged this on Share Coding and commented:
    The most clear and easy understanding Comet(Server-push) Tutorial

  17. Superb, what a blog it is! This website
    gives valuable information to us, keep it up.
    Вклады втб 24 для пенсионеров в
    2013 году Оформить кредитную карту онлайн русский стандарт голд Как получить ипотеку
    в лондоне Кредит на карту кукуруза
    онлайн [] Кредитная карта кукуруза Сбербанк кредитный калькулятор ипотека (sberbank-kreditnyy-kalkulyator-ipoteka. Жк лебединое озеро ипотека Россельхозбанк кредиты
    онлайн заявка Рейтинг банков по вкладам
    2011 Заявка на кредит онлайн русский стандарт
    карта Восточный экспресс банк эмблема
    Потребительский кредит без прописки
    Сбербанк потребительский
    кредит договор Денежные кредиты в русском
    стандарте Деньги в кредит за час Оформить
    кредитную карту за один день Гераклит вклад в
    психологию (geraklit-vklad-v-psihologiyu. Кредит без справок и поручителей тверь Оф сайт хоум
    кредит Вклад в экономику Кредитные карты
    сбербанка россии моментум Хоум кредит банк тюмень [] Банковские вклады для
    пенсионеров Альфа банк воронеж кредитная карта *alfa-bank-voronezh-kreditnaya-karta.* Кредит ипотека под материнский капитал (kredit-ipoteka-pod-materinskiy-kapita. Продажа кредитов ougos Банк
    новосибирск потребительский кредит
    йошкар ола Как активировать кредитную карту ренессанс Что необходимо для получения ипотечного кредита [] Вклады в
    банках беларуси в российских рублях Вклады
    в банках белоруссии Машина в кредит г
    сумы Банк кольцо урала потребительские кредиты ebesucher Просрочка по кредитам в россии (prosrochka-po-kreditam-v-rossii. Роль кредита в развитии экономики его границы

    ru) Государственный кредит государство как заемщик
    Сущность ипотечного кредитования в россии Народный кредит журнал Заявка на кредитную карту сбербанка 2013 Закон
    о кредитных авто (zakon-o-kreditnyh-avto. Если задолженность по кредиту Специалист по автокредитованию без опыта Россельхозбанк кредит
    с 18 лет Тинькофф кредитная карта
    где снять наличные Потребительский кредит по двум документам самара Как заполнить анкету на ипотеку сбербанк Центр
    автокредитования втб 24 спб Вклад имущества в уставный
    капитал Мтс кредит адреса – http://mts-kredit-adresa. – Iphone в кредит минск
    Кредит в сбербанке требования (http:
    // Kredit 1 tag Рефинансирование потребительского кредита втб 24 ярославль Взять кредит в
    сбербанке россии пенсионеру Сумма страхования вкладов физических лиц до
    1 млн Сбербанк потребительский кредит под поручительство физических лиц Ставки по вкладам
    скб банк Социальная ипотека хабаровск куда обращаться
    Тинькофф кредитная карта узнать лимит

  18. I am really enjoying the theme/design of your blog.
    Do you ever run into any web browser compatibility issues?
    A handful of my blog audience have complained about my site not
    operating correctly in Explorer but looks great in Safari.
    Do you have any ideas to help fix this problem?

  19. Aw, this was a very nice post. In thought I want to put in writing like this moreover taking time and actual effort to make an excellent article but what can I say I procrastinate alot and not at all seem to get something done. ceffgdabdkdd

One Trackback/Pingback

  1. […] = "#FFFFFF"; ch_color_text = "#000000"; ch_color_bg = "#FFFFFF"; I am trying to make this example; I just faced a strange error which happens when sendMessage(String msg) method is […]

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: