Reputation: 985
I need to write a server with an embedded Jetty or Tomcat which is capable of exposing a POJO as a webservice using apache CXF programatically, i.e. without deploying it as a .war file. Is this possible with CXF?
Thanks.
Upvotes: 0
Views: 366
Reputation: 2866
Java comes with an embedded server which you can use. It is sufficient to annotate your POJO with @WebService
and you need no additional packaging is required. Simply create an instance of your web service and deploy that using Endpoint.publish()
:
YourPojo service = new YourPojo(); // the class annotated with @WebService
Endpoint.publish("http://localhost:2000/serviceAddress", service);
The embedded server will be fine for simple scenarios, just be aware that it would scale under arbitrary load.
Now if you want to use CXF with this service, you just need to put the CXF libs into its buildpath. The deployment mechanism, the Endpoint
class, remains exactly the same. Here is a tutorial from CXF that explains this example. CXF automatically seems to replace the default server with Jetty. At least this is what CXF prints to my console on startup:
Jun 24, 2013 1:36:29 PM org.eclipse.jetty.server.Server doStart
INFO: jetty-8.1.7.v20120910
Jun 24, 2013 1:36:29 PM org.eclipse.jetty.server.AbstractConnector doStart
INFO: Started SelectChannelConnector@localhost:2000
Upvotes: 2