Você está na página 1de 4

Apache Felix + Restful Web Service using BNDTools

Jars Required:
1.
2.
3.
4.
5.
6.

jackson-core-asl-1.8.11.jar
jackson-mapper-asl-1.8.11.jar
org.amdatu.web.rest.jaxrs-1.0.0.jar
org.amdatu.web.rest.wink-1.0.0.jar
org.apache.felix.dependencymanager-3.1.0.jar
org.apache.felix.http.whiteboard-2.2.1.jar

Step -1: Create New BndTools OSGI Project

New BNDTools OSGI Project (e.g z.main.agenda) a Component Development Project.


Go To launch.bndrun, and add jars. To Run Requirments

Resolve the jars. Save and Run OSGI.


Jetty server logs.

____________________________
Welcome to Apache Felix Gogo
g! Sep 12, 2014 11:34:24 AM org.apache.wink.server.internal.servlet.RestServlet
getApplication
INFO: Using application classes /conf/application.properties named in init-param
applicationConfigLocation
Sep 12, 2014 11:34:24 AM
org.apache.wink.common.internal.application.SimpleWinkApplication loadImplAppConfigFiles
WARNING: Could not find /conf/application.properties Ignoring.
[DEBUG] Ignoring Servlet Service [javax.servlet.Servlet], alias is missing or empty
2014-09-12 11:34:24.109:INFO:oejsh.ContextHandler:started
o.e.j.s.ServletContextHandler{/,null}
Sep 12, 2014 11:34:24 AM
org.apache.wink.common.internal.application.ApplicationFileLoader <init>
INFO: Loading application from bundle://5.0:6/META-INF/wink-application
Sep 12, 2014 11:34:24 AM org.apache.wink.server.internal.servlet.RestServlet
getApplication

INFO: Using application classes /conf/application.properties named in init-param


applicationConfigLocation
Sep 12, 2014 11:34:24 AM
org.apache.wink.common.internal.application.SimpleWinkApplication loadImplAppConfigFiles
WARNING: Could not find /conf/application.properties Ignoring.
Sep 12, 2014 11:34:24 AM
org.apache.wink.common.internal.application.ApplicationFileLoader <init>
INFO: Loading application from bundle://5.0:6/META-INF/wink-application
[INFO] Detected extended HttpService. Filters enabled.
[INFO] Started jetty 6.1.x at port(s) HTTP:8080
2014-09-12 11:34:24.281:INFO:oejs.AbstractConnector:Started
SelectChannelConnector@0.0.0.0:8080
[INFO] Started Jetty 7.6.13.v20130916 at port(s) HTTP:8080 on context path /

Step-2: Create a REST project

Create another BNDTools OSGI Projetc ( e.g. z.main.rest) Empty Project.


Add Jars to Class Path.

Create a HelloWorldResource Class, and Add Restfull web service code


Create a new Class (e.g Activator) extends DependencyActivatorBase
Registering bundle of the HelloWorldResource rest service in Activator class as:
o @Override
o public void init(BundleContext arg0, DependencyManager manager)
o
throws Exception {
o manager.add(createComponent()
o .setInterface(Object.class.getName(), null)
o .setImplementation(HelloWorldResource.class)
o );
o }

Add the Activator class in the Bundle Contents of the project. (bnd.bnd file)

Step-3: Add the rest to the component.

Add the second project (e.g. z.main.rest) bundle to the First Project (e.g. z.main.agenda).
In the Run Requirments, add z.main.rest bundle.
Resolve and Save ALL
In the Browser type http://localhost:8080/rest

GET-POST RestFul Calls

Você também pode gostar