I want to create and deploy a web service to OSGi container. For example, publish the service to the address:
http://localhost:8080/testservice.
I would like to follow up on the answer of Peter Kriens. With @Component
annotations available in the OSGi specification, the example could look like this:
@Component(service = Servlet.class, property = { "osgi.http.whiteboard.servlet.pattern = /hello" })
public class HelloWorldServlet extends HttpServlet { ... }
The @Component
annotation is imported from org.osgi.service.component
and the property that specifies the implemented service has changed its name to service
.
Despite its name, property
can hold multiple properties for example
@Component(service = ..., property = { "a=b", "c=d" })
or you could use properties
to specify one or more properties files like so:
@Component(service = ..., properties = { "OSGI-INF/servlet.properties" } )
The above has been tested with the HttpService
that comes with Apache Felix. The documentation of the Apache Felix HTTP Service can be found here: http://felix.apache.org/documentation/subprojects/apache-felix-http-service.html