0

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.

Jeewantha
  • 965
  • 1
  • 11
  • 28
  • Is using Jetty or Tomcat a hard requirement or is any other embedded server ok? If so, you could simply use the server that ships with Java. – joergl Jun 24 '13 at 08:09
  • Well I would like Jetty or Tomcat to be the servlet engine. But I'm open for other options as well. Basically the requirement is to expose the POJO as a web services just with annotations straight away. – Jeewantha Jun 24 '13 at 11:04

1 Answers1

2

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
joergl
  • 2,850
  • 4
  • 36
  • 42