tomcat - start & stop RESTful service from Java Application -


this question implementing restful listener service, provide background first provide context.

i have existing java application & swing ui takes directory , database file input. after these set button imports pdf forms within directory database. there small jframe window in ui buttons , logging output. works well.

i want java app connect our exchange mail server, listen new emails pdfs attached, save them directory , import using application above.

to connect our exchange server (imap, pop etc not enabled) going use ews-java api https://github.com/officedev/ews-java-api

however requires client wants push notifications exchange mail server (via rest) 3 things:

1) connect exchange server (i can this)

exchangeservice newservice = new exchangeservice(exchangeversion.exchange2010_sp2); newservice.seturl("https://myurl/ews/exchange.asmx"); exchangecredentials credentials = new webcredentials("user","password"); newservice.setcredentials(credentials); 

2) subscribe push notifications , setup callback uri (i can this)

    @override public pushsubscription subscribetopushnotifications(){  uri callback = null; pushsubscription pushsubscription = null; try{     logger.info("subscribing push notifications.. endpoint listener uri = " + config.getnotificationlisteneruri());     callback = new uri(config.getnotificationlisteneruri());     pushsubscription = service.subscribetopushnotifications(             getfoldersforsubscription(), callback , 5, null,              eventtype.newmail, eventtype.created, eventtype.deleted, eventtype.modified, eventtype.moved);      logger.info("done! --> pushsubscription id= " + pushsubscription.getid()); }catch(urisyntaxexception e){     logger.error("ews ==> invalid notification listener url = " + config.getnotificationlisteneruri() +". please, verify <integration-modules>");     throwables.propagate(e); }catch (exception e){     logger.error("ews ==> error subscribing push notifications", e);     throwables.propagate(e); }  return pushsubscription; } 

3) setup listener service new-email notifications (help needed here)

similar : exchange web services java api + restful push notifications listener

@path("/emailnotification") public class exchangenotificationlistener {  private static final log logger = logfactory.getlog(exchangenotificationlistener.class);  @path("/incomingevent") @post() @produces(mediatype.text_xml) public response onnotificationreceived() throws exception {     logger.info("received ews notification !!!"); return response.ok().build(); }  @get @path("/{param}") public response getmsg(@pathparam("param") string msg) {     string output = "jersey : " + msg;     return response.status(200).entity(output).build();     } } 

it appears listener , jax-rs needs run within container tomcat step 3 , these web services run within tomcat , started tomcat.

is there way have existing application start / stop listener or have convert whole thing web service project? far have managed step 3 standalone web project able start stop existing app.

ideally have exchangenotificationlistener started after subscription email notifications in step two.

could class starts subscription extend exchangenotificationlistener class this?

or should using other tomcat?

thanks

i not aware of way run swing application , servlet in same java process. if there 1 kind of hack.

if think it, find there 2 separate concepts involved. swing gui desktop application, , desktop applications run in context of users session because require graphical desktop environment. started after user has logged in , closed before user logs out.

on other hand "listener" application web application, needs network connection , maybe file system access otherwise knows nothing graphical desktop environment. web applications longer running system services started when server booted , run long server running.

if try combine them single application indicates problem design.

i instead recommend different approach. create 3 parts subscription, push-callback-registration , listener inside web application. can deploy application in servlet container, install regular system service , configure start when system boots up.

next need think mails receive in servlet. either store them somewhere , process them when swing app started, or move processing logic web application, preferably moving code own library can access both gui application , servlet.

depending on option choose, when start swing application either mails in database , can access them, or can process mails servlet has stored while app not running.


Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -