Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #6936
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!nuzba.szn.dk!news.szn.dk!pnx.dk!dotsrc.org!filter.dotsrc.org!news.dotsrc.org!not-for-mail |
|---|---|
| Date | Tue, 09 Aug 2011 20:07:51 -0400 |
| From | Arne Vajhøj <arne@vajhoej.dk> |
| User-Agent | Mozilla/5.0 (Windows NT 6.1; WOW64; rv:5.0) Gecko/20110624 Thunderbird/5.0 |
| MIME-Version | 1.0 |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: How to start a server and a webservice at the same time? |
| References | <63292a5b-70f4-4789-82a2-891eb06a0009@g9g2000yqb.googlegroups.com> <alpine.DEB.2.00.1108092238550.20857@urchin.earth.li> |
| In-Reply-To | <alpine.DEB.2.00.1108092238550.20857@urchin.earth.li> |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| Lines | 58 |
| Message-ID | <4e41cbdc$0$302$14726298@news.sunsite.dk> (permalink) |
| Organization | SunSITE.dk - Supporting Open source |
| NNTP-Posting-Host | 72.192.23.157 |
| X-Trace | news.sunsite.dk DXC=i]EID^@33H;@g6i]76MRQ6YSB=nbEKnk;_Q=jj^c=Yo<JPe3\kP5EU1KBm9cfh9BS4M2;kT<[:>[19`eXSIBc>46KI4n6Pl];`> |
| X-Complaints-To | staff@sunsite.dk |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:6936 |
Show key headers only | View raw
On 8/9/2011 6:11 PM, Tom Anderson wrote: > On Tue, 9 Aug 2011, Iain Adams wrote: >> I am building an application that requires both a Server/Client socket >> connection to multiple clients AND also exposing multiple webservices. >> >> If I was to deploy my application on a Java container (JBoss/Tomcat >> etc) is there a way I can get it to a) start the webservices and b) >> start the server (so that it can listen on a specific port for >> incoming connections)? > > Yes. > > For the web services, things are pretty simple. You can create a web > service using JAX-WS, annotating an interface and a class with > @WebService, then mapping the class as a servlet (even though it isn't > really a servlet). Geronmio has a good example: > > https://cwiki.apache.org/GMOxDOC20/simple-web-service-with-jax-ws.html > > The container will then take care of binding the HTTP port, supplying > handler threads, and so on. > > The raw server socket is marginally trickier. > > For a start, the J2EE specification specifically provides that most code > in the container (including servlets and EJBs) might not be allowed to > open a server socket or create a thread (that's supposed to the > container's job!). The only code that is officially allowed to open a > server socket is code which is part of a resource adapter; resource > adapters also get access to thread pools. So, if you want to be > squeaky-clean J2EE compliant, you will need to write a resource adapter; > i have never done it, but my impression is that it is not a fun experience. > > However, i think it's usually the case that opening server sockets and > creating threads is actually allowed in all parts of the container > (JBoss has never stopped me doing it, for example). So, your path of > least resistance might be to commit the venial sin of deviation from the > spec, and just set up your server in application code. > > I would suggest staging your deviation in a servlet. You can write a > servlet which will never actually handle a request, but whose init > method binds a socket and starts a listener thread. You can then mark > that servlet to be started on startup, by adding a load-on-startup > element inside the servlet element in the web.xml. If it is worth doing then it is likely worth doing the correct way. Meaning JCA for the socket listening and threading. Few people have experience with JCA, so it is not so easy to find good information, but the necessary code is actually not that advanced. Arne
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar
How to start a server and a webservice at the same time? Iain Adams <iain.adams.1985@gmail.com> - 2011-08-09 09:38 -0700
Re: How to start a server and a webservice at the same time? Tom Anderson <twic@urchin.earth.li> - 2011-08-09 23:11 +0100
Re: How to start a server and a webservice at the same time? Arne Vajhøj <arne@vajhoej.dk> - 2011-08-09 20:07 -0400
Re: How to start a server and a webservice at the same time? Arne Vajhøj <arne@vajhoej.dk> - 2011-08-09 20:04 -0400
csiph-web