//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

==== Http Service

Apache Karaf supports several Http Services:

* `http` feature installs Http Service powered by Pax Web
* `felix-http` feature installs Http Service powered by Apache Felix HTTP

===== Installing the Http Service

If you want to use Pax Web Http Service, you have to install the `http` feature:

----
root@karaf()> feature:install http
----

NB: the HTTP service will be actually bound only when at least one web application will use it.

If you want to use Apache Felix Http Service, you have to install `felix-http` feature:

----
root@karaf()> feature:install felix-http
----

If you want to test the HTTP service, you can install the `webconsole` feature:

----
root@karaf()> feature:install webconsole
----

Then, you can test the HTTP service by accessing the Apache Karaf WebConsole pointing your browser to [http://localhost:8181/system/console].

===== Configuring the HTTPService

By default the HTTPService listens on port 8181 you can change the port by creating a file `etc/org.ops4j.pax.web.cfg` (if you use the Pax Web Http Service) with the following content:

----
org.osgi.service.http.port=8181
----

or by typing:
----
root@karaf> config:property-set -p org.ops4j.pax.web org.osgi.service.http.port 8181
----

If the http feature is already installed the change will take effect immediately.

If you use Apache Felix Http Service, it's basically the same but the configuration is `etc/org.apache.felix.http.cfg`.

===== Registering a servlet with the HttpService manually

See the Apache Karaf Servlet example: https://github.com/apache/karaf/tree/master/examples/karaf-servlet-example/karaf-servlet-example-registration

===== Using the Pax Web whiteboard extender

The Pax Web whiteboard extender is an enhancement of the http feature. So use the following command to install:

----
root@karaf> feature:install http-whiteboard
----

NB: `felix-http` feature installs whiteboard by default in the feature.

You can take a look on a full example using whiteboard here: https://github.com/apache/karaf/tree/master/examples/karaf-servlet-example

For commands take a look at the command section in the link:webcontainer[webcontainer] chapter.
