Warning

This component has been deprecated in favor to servicemix-http component.

We support both a client side HTTP (capable of invoking requests on remote HTTP servers) and a server side HTTP binding (for exposing JBI components over HTTP). Note that both these 2 components are pure HTTP bindings; they assume that a REST or SOAP service creates the inbound request first. So they just deal with the HTTP transport and do not perform any protocol encoding such as SOAP 1.1 or SOAP 1.2; they pass along the XML they are given.

Client side HTTP invocation

This JBI component uses Commons HttpClient to perform client side HTTP invocations. Here is a typical example of a JBI component which performs a HTTP invocation when it is invoked.

<sm:activationSpec componentName="httpSender" service="foo:httpSender">
  <sm:component><bean class="org.apache.servicemix.components.http.HttpInvoker">
    <property name="url" value="http://localhost:8912"/>
  </bean></sm:component>
</sm:activationSpec>

Server side HTTP binding

This JBI component will expose another JBI component over HTTP on some port and HTTP configuration. We use an embedded Jetty component for this, though we also have a BindingServlet which can be configured from inside any web.xml in a Servlet WAR.

Here's an example of configuring the default HTTP connector.

<sm:activationSpec componentName="httpReceiver" service="foo:httpBinding" destinationService="foo:httpSender2">
  <sm:component><bean class="org.apache.servicemix.components.http.HttpConnector">
    <property name="host" value="localhost"/>
    <property name="port" value="8912"/>
  </bean></sm:component>
</sm:activationSpec>

Using HTTP binding in a WAR

You may wish to configure ServiceMix's HTTP binding inside a WAR. To do this you need to register one or more instances of the SpringBindingServlet in your web.xml then map the servlet to the URI you wish.

Here's an example

Error formatting macro: snippet: java.lang.IndexOutOfBoundsException: Index: 20, Size: 20

Notice that the web.xml then refers to the endpoint name httpBinding in the ServiceMix configuration file. e.g. this component

Error formatting macro: snippet: java.lang.IndexOutOfBoundsException: Index: 20, Size: 20

Example of using the HTTP binding in a WAR

The ServiceMix WAR comes with an example of using a HTTP GET or POST to invoke a JBI operation. To run the example get the latest checkout then perform the following

cd tooling/servicemix-web
maven run

Then point your browser to http://localhost:8080/examples/

You should see the simple demo which performs a HTTP GET/POST into the JBI container and shows the result in your browser. This example renders better in FireFox which handles XML response types nicer than Safari.

An alternative is to use your existing Servlet engine and type this instead

maven war

Then deploy the war into your servlet engine. You'll typically need to use a different URL then such as http://localhost:8080/servicemix-web/examples/

More detail

See the WAR Deployment