How to catch a external HttpRequest (GET or POST) in a vaadin app

Hi,

I checked the dont-push-ozonelayer demoapp. Now I want to Trigger a Client update from ServerSide by HttpRequest .

My Qestion now:

How can I catch a external HttpRequest (GET or POST) in a vaadin app, and react on this event like on Button click event?

friendly regrades
Kai

Ok forget about dont-push-ozonelayer, and focus on the main question.

How can I catch a external HttpRequest (GET or POST) in a vaadin app and handle it?

After some recherche I found HttpServletRequestListener . Is there more options?

Inside your Vaadin application, you can use
HttpServletRequestListener
as you’ve found. Since that gives you complete access to the request and response objects, I don’t know what else you would need. It might help to know what it is you’re trying to do.

Outside of your application, you could add something like a
servlet filter
to have access to that information. Here is
more info on filters
.

Cheers,
Bobby

Hi Bobby,

thanx for your Answer.

Ok, lets try to explain what Solution I am looking for.
I have a Vaadin Application. The Vaadin serverpart is triggered from a external http request . It could be a JavaHttpClient ( not the same browser) .
The vaadin backend is catching the Request and pushes a notification to the vaadin frontend.

External application ----http------> vaadinbackend ----push(z.B websocket)—> vaadin frontend

The push part is solved (dont-push-ozonelayer or vaadin 7).
The firstpart is still open. I thought abut a ApplicationRecource or a HttpServletRequestListener.
Do you have an Idea how to realize the chain?

Kai

Are you saying that, depending on the client, you don’t want the request to get to the Vaadin application? In that case, you could add a separate servlet to your app that talks to the same back end (e.g. database) that the Vaadin app is using.

If you want to implement the filter chain, however, you can just add a class that implements Filter. In EE 6, you can add an annotation to the class so that the container picks it up. Otherwise, you can add text to your web.xml file so that it’s found. Implementing the filter class is very simple.

Here is more info on using filters
in EE6
and in
EE 5
.

Cheers,
Bobby

Hi Bobby,

Ok, using a filter to change the app is ok. My problem that I have to react on the external trigger event right the way and change the vaadin app frontend.
So I the way over the database might be to slow.

So the best way to describe the feature I want to solve a external vaadin remote control via http requests.

What do you think about following idea: Implementing a filter / servlet . Here I get the Vaddin AppObject from ApplicationContext and change it there. Push the changes to the frontend.

Kai

I’m really not sure how that would work out for you. Generally, if you want some external process to affect the UI a user sees, the external process should change some data somewhere – it could be in memory accessible to all sessions or a DB or something else. Then the UI checks this data during a request.

If you’re trying to intercept a browser request that’s on the way to the Vaadin servlet and try to change some data in the application, I would guess that this would cause a synchronization error. But maybe not if you’re changing the actual data Vaadin uses to detect these issues. Give it a try I guess, but I’m sorry I’m still not really understanding your use case.

Cheers,
Bobby

If running in the same JVM and from the same WAR, you should be able to synchronize to the application instance even if receiving the requests with a separate servlet or a servlet filter. You could also override AbstractApplicationServlet.service() to intercept requests before they are processed by Vaadin and associated with sessions, but that easily gets messy.

Also, consider using some light-weight event bus mechanism - they can also handle distribution of events to multiple applications cleanly, make sure the messages are delivered etc.

Hi Henri,

thanx for joining us.

Would you tell some more about your Idea of a “light-weight event bus mechanism”.

fg
Kai

Hello I’m also trying to implement something same like this thread. I’ve put my questions in the following thread:
https://vaadin.com/forum#!/thread/15896058
Thanks in advance