aspose file tools*
The moose likes OO, Patterns, UML and Refactoring and the fly likes listen to events from a servlet in an embedded tomcat Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "listen to events from a servlet in an embedded tomcat" Watch "listen to events from a servlet in an embedded tomcat" New topic
Author

listen to events from a servlet in an embedded tomcat

Yahya Elyasse
Ranch Hand

Joined: Jul 07, 2005
Posts: 510

Hello,
here is my situation:
- i have a desktop application in which i use a ListenerHelper class to handle events.
-my desktop app uses embedded tomcat server and runs a servlet in that embedded container.
-i want my servlet to notify my desktop client once it executes the doGet() method.

what design pattern to use in such a situation? and how to structure my listener and event handling cleanly to address communication between client and embedded servlet?

thanks
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
Well you have two applications. The desktop application and the web application. You can have them communicate by sending messages to each other using a message server or you can create one or more web services and have them communicate with the web services.

Keep in mind that Java servlets are designed for Presentation elements. They shouldn't be coded to send external messages outside of the web container. This should be implemented in a business object.
Yahya Elyasse
Ranch Hand

Joined: Jul 07, 2005
Posts: 510

Jimmy Clark wrote:Well you have two applications. The desktop application and the web application. You can have them communicate by sending messages to each other using a message server or you can create one or more web services and have them communicate with the web services.

Keep in mind that Java servlets are designed for Presentation elements. They shouldn't be coded to send external messages outside of the web container. This should be implemented in a business object.


i did some research & found that using an http://www.eventbus.org/ would be a good solution. what you think of the eventBus design pattern?
I don't want to augment my application complexity with extra webservices or server messages. the embeded web app will be used for a small task in whole application and want it to stay as simple as possible.

can you talle if i have my servlet publish eventbus event would be a clean solution?
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
I don't think anything about the "eventBus" design pattern. I never heard of it and am not interested in it.

I don't want to augment my application complexity with extra webservices or server messages. the embeded web app will be used for a small task in whole application and want it to stay as simple as possible.


It is unclear why you want to have a small web application anyway, since it will only be used for a small task. A better design would be to move the functionality of the web application into the desktop application. Your current design sounds confusing and overly complicated.
Yahya Elyasse
Ranch Hand

Joined: Jul 07, 2005
Posts: 510

my application needs to authenticate user with Google oauth. this can only be done on the web.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18882
    
    8

Yahya Elyasse wrote:-i want my servlet to notify my desktop client once it executes the doGet() method.


But that's just the plain old HTTP request and response process. Your desktop client would send an HTTP request to that servlet and wait for it to send a response. Which it would do naturally as part of the doGet() method. I don't see any need to drag in anything more than that.
Yahya Elyasse
Ranch Hand

Joined: Jul 07, 2005
Posts: 510

Paul Clapham wrote:
Yahya Elyasse wrote:-i want my servlet to notify my desktop client once it executes the doGet() method.


But that's just the plain old HTTP request and response process. Your desktop client would send an HTTP request to that servlet and wait for it to send a response. Which it would do naturally as part of the doGet() method. I don't see any need to drag in anything more than that.

the issue is when to send servlet http request from client? before invoking my embedded web browser? . b/c the oauth process is done in many steps and it calls many servlets untill last callback servlet.
so if i send a http request to my callback servlet . it will wait untill my callback servlet is done and then return to client? i though http client request returns immediately. so if i call my callback servlet before oauth process is done it will returns nothing ! and i can't know exactly when the callback servlet will be called by Google service.
i hope i explained well the issue. it is about doing oauth process in an embeded server and try notifying client when process is done.
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
my application needs to authenticate user with Google oauth. this can only be done on the web.


The desktop application can send a HTTP request and can receive the response directly. There is no need to create a separate web application simply to send a single HTTP request.

The application can wait for a response in the background and continue processing. Or, it can wait in the foreground and not do anything until it recieves the response.

And maybe if there are more requirements for Internet activity, then it seems like it should not be a desktop application but a 100% web application.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18882
    
    8

Jimmy Clark wrote:
my application needs to authenticate user with Google oauth. this can only be done on the web.


The desktop application can send a HTTP request and can receive the response directly. There is no need to create a separate web application simply to send a single HTTP request.


I was going to say exactly that. But then I did some googling and I found Using OAuth with the Google Data APIs, which said this:

Google wrote:Note: Though the OAuth protocol supports the desktop/installed application use case, Google only supports OAuth for web applications.


So I didn't say that.

However this note really means "Sure, you can try using OAuth from your desktop app, but you're on your own, buddy. Don't ask us for help." So if I were a beginner I would take it seriously; although what we see is that a beginner can't work around this restriction anyway.
Yahya Elyasse
Ranch Hand

Joined: Jul 07, 2005
Posts: 510

Jimmy Clark wrote:
my application needs to authenticate user with Google oauth. this can only be done on the web.


The desktop application can send a HTTP request and can receive the response directly. There is no need to create a separate web application simply to send a single HTTP request.

The application can wait for a response in the background and continue processing. Or, it can wait in the foreground and not do anything until it recieves the response.

And maybe if there are more requirements for Internet activity, then it seems like it should not be a desktop application but a 100% web application.

it seems you have no Idea about oauth. user should interactively grant access to Google scopes . can we do Grant feature using HTTP requests?!!

maybe before giving your opinion try reading about how google oauth works:
http://code.google.com/apis/accounts/docs/OAuth.html
http://code.google.com/apis/accounts/docs/OAuthForInstalledApps.html

Yahya Elyasse
Ranch Hand

Joined: Jul 07, 2005
Posts: 510

Paul Clapham wrote:
Jimmy Clark wrote:
my application needs to authenticate user with Google oauth. this can only be done on the web.


The desktop application can send a HTTP request and can receive the response directly. There is no need to create a separate web application simply to send a single HTTP request.


I was going to say exactly that. But then I did some googling and I found Using OAuth with the Google Data APIs, which said this:

Google wrote:Note: Though the OAuth protocol supports the desktop/installed application use case, Google only supports OAuth for web applications.


So I didn't say that.

However this note really means "Sure, you can try using OAuth from your desktop app, but you're on your own, buddy. Don't ask us for help." So if I were a beginner I would take it seriously; although what we see is that a beginner can't work around this restriction anyway.

beginner?!! you and your other mate are insulting me al through this thread and i don't know why?

I don't need help from such people who are disrespectful and more over don't know what they are talking about. your opinions are misleading and reveal your ignorance regarding google oauth.
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
Note: Though the OAuth protocol supports the desktop/installed application use case, Google only supports OAuth for web applications.




Interesting. I wonder how the Google application (OAuth) can distinguish between a HTTP Request sent from a "web application on a web server" and a HTTP Request sent from a desktop application.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18882
    
    8

Yahya Elyasse wrote:beginner?!! you and your other mate are insulting me al through this thread and i don't know why?

I don't need help from such people who are disrespectful and more over don't know what they are talking about. your opinions are misleading and reveal your ignorance regarding google oauth.


I meant no disrespect when I referred to you as a "beginner". Your question about servlets seemed to indicate that you were a beginner in servlets, as far as I could see. So if you considered that as an insult, then I apologize. For myself, of course. Jimmy Clark isn't my "mate" in any way but I don't see anything to complain about in his posts.

As for my ignorance regarding OAuth, there's no question about that. Everything I know about it is what I googled this afternoon.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: listen to events from a servlet in an embedded tomcat