Paul Clapham wrote:You don't start a servlet. The servlet is part of a web application installed in a web application server, in your case Jersey. The application server manages the servlet, including initializing it, and it's not the responsibility of any other code to manage it.
I suspect that isn't the answer to the question you wanted to ask, though.
I'm not quite familiar with the programming style you're using, but I think that if you want to cause that servlet's onNotificationReceived() method to be called then you would have to send a POST request to localhost:8080/com.vogella.jersey.first/rest/emailnotification/incomingevent -- was that what you wanted to ask, or am I still off course?
Al Grant wrote:I guess ultimately the guy who wrote that stack exchange post presumably has a way of starting his listener, and stopping it?
I already have a little application in java, and want to be able to start listening for new emails (then doing business logic to do with saving attachments) and be able to stop listening.
How would I go about this?
Paul Clapham wrote:
Al Grant wrote:I guess ultimately the guy who wrote that stack exchange post presumably has a way of starting his listener, and stopping it?
I suppose so... did they explicitly say they were using a servlet to encapsulate the listener? I ask because if you're looking for push notifications then why would you use a servlet? A servlet is designed to send you data only when you request that data, which is not what push notification is at all.
I already have a little application in java, and want to be able to start listening for new emails (then doing business logic to do with saving attachments) and be able to stop listening.
How would I go about this?
An application... that's a much better idea. You put steps (1) and (2) into the application's initialization code, which it sounds like you did that already. Then, well I'm not too clear on how you get a listener from the subscription or how you attach a listener to it. My guess is that you have to write your own class which subclasses, or implements, ExchangeNotificationListener, or something like that, and add it to the subscription using a method named something like addListener. Your onNotificationReceived method is then going to be called whenever a notification is received and your method can then do whatever it wants. Although I would have expected that method to include a parameter containing the details of the notification which it's telling you was received.
Sorry to be so vague, but doesn't the place you got that code from expand it to a simple application to listen for and report on notifications?
Paul Clapham wrote:I would go looking for the actual documentation for that product, tutorials for it, and so on. Trying to write an entire program based on a single question about the product isn't the best way to proceed.