blob: d4e7e67a94160a8efd6e671947f1e26ab6276bf5 [file] [log] [blame]
== Camel Servlet REST and Karaf Jaas example
=== Introduction
This example shows how to use Servlet REST to define REST endpoints in Camel routes using the Rest DSL. REST endpoint protected by Basic Auth, delegate user/password authentication to Karaf Jaas Service
=== Build
You will need to compile this example first:
mvn install
=== Copy security configuration file
copy src/main/resources/org.ops4j.pax.web.context-camelrestdsl.cfg
to $KARAF_HOME/etc folder
=== Run
To install Apache Camel in Karaf you type in the shell (we use version
feature:repo-add camel ${camel.version}
feature:install camel
First you need to install the following features in Karaf/ServiceMix
feature:install camel-servlet
feature:install camel-jackson
feature:install war
Then you can install the Camel example:
install -s mvn:org.apache.camel.example/camel-example-servlet-rest-karaf-jaas/${camel.version}
And you can see the application running by tailing the logs
And you can use ctrl+c to stop tailing the log.
There is a user REST service that supports the following operations
* GET /user/\{id} - to view a user with the given id
* GET /user/final - to view all users
* PUT /user - to update/create an user
The view operations are HTTP GET, and update is using HTTP PUT.
From a web browser you can access the first two services using the
following links(need to input karaf/karaf as user/password in the pop up dialog)
http://localhost:8181/camel-example-servlet-rest-blueprint/rest/user/123 - to view the user with id 123
http://localhost:8181/camel-example-servlet-rest-blueprint/rest/user/findAll - to list all users
From the command shell you can use curl to access the service as shown
curl -X GET -H "Accept: application/json" --basic -u karaf:karaf http://localhost:8181/camel-example-servlet-rest-blueprint/rest/user/123
curl -X GET -H "Accept: application/json" --basic -u karaf:karaf http://localhost:8181/camel-example-servlet-rest-blueprint/rest/user/findAll
curl -X PUT -d "{ \"id\": 666, \"name\": \"The devil\"}" -H "Accept: application/json" --basic -u karaf:karaf http://localhost:8181/camel-example-servlet-rest-blueprint/rest/user
=== Configuration
This example is implemented in XML DSL in the
`+src/main/resources/OSGI-INF/blueprint/camel.xml+` file.
=== Help and contributions
If you hit any problem using Camel or have some feedback, then please[let us know].
We also love contributors, so[get involved] :-)
The Camel riders!