New servicemix-http endpoints

TODO

Consumer endpoints

These endpoints allow you to expose a service in the ESB to the outside world over HTTP. Whenever these endpoints receive an HTTP request, they will interact with the configured services on the ESB to provide the HTTP response.

Simple examples

<http:consumer service="my:ConsumerService"
               endpoint="jbi"
               targetService="t2:ProviderService"
               targetEndpoint="ep"
               locationURI="http://0.0.0.0:8192/person/" />
<http:soap-consumer service="my:ConsumerService"
                    endpoint="jbi"
                    targetService="t2:ProviderService"
                    targetEndpoint="ep"
                    locationURI="http://0.0.0.0:8192/person/"
                    wsdl="classpath:myservice.wsdl" />

Tips

Reference

Name Type Bean Description Required
service QName no The service name of this endpoint yes
endpoint String no The endpoint name of this endpoint yes
interfaceName QName no The interface name of this endpoint no
         
targetService QName no The service name of the target endpoint no (defaults to the service attribute)
targetEndpoint String no The endpoint name of the target endpoint no (defaults to the endpoint attribute)
targetInterface QName no The interface name of the target endpoint no
targetOperation QName no The operation name for the JBI exchange no
targetUri String no The URI of the target endpoint no
         
authMethod String no HTTP authentication method to use, e.g. basic no
locationURI String no   yes
ssl SslParameters yes   no
marshaler HttpConsumerMarshaler yes   no
timeout long no   no
defaultMep URI no   no (defaults to InOut)

The following additional properties are available for the SOAP consumer endpoint:

Name Type Bean Description Required
wsdl Resource no   yes
useJbiWrapper boolean no   no (defaults to true)
validateWsdl boolean no   no (defaults to true)
policies Policy[] yes   no

Provider endpoints

Simple examples

<http:provider service="t2:ProviderService"
               endpoint="ep"
               locationURI="http://192.168.0.12:8080" />
<http:soap-provider service="t2:ProviderService"
                    endpoint="ep"
                    wsdl="classpath:service.wsdl" />

Tips

Using a marshaler

As for the new JMS endpoints definition, you can define your own HTTP Marshaler. This feature is very powerful as you can manipulate directly the HTTP Servlet Request and Response.

For exemple, you can create your own marshaller adding IP addresses blacklist/whitelist support on your HTTP component :

package org.apache.servicemix.samples;

import java.util.ArrayList;
import java.util.List;

import javax.jbi.component.ComponentContext;
import javax.jbi.messaging.ExchangeStatus;
import javax.jbi.messaging.MessageExchange;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.servicemix.http.endpoints.HttpSoapConsumerMarshaler;

/**
 * Works in the same way as the HttpSoapConsumerMarshaler, plus adds the ability to filter incoming
 * request with a blacklist/whitelist mechanism.
 * @author <a href="mailto:[email protected]">Jean-Baptiste Onofré</a>
 * @version $Revision: 1.1 $
 */
public class ListedSoapConsumerMarshaler extends HttpSoapConsumerMarshaler {
	private static final String IP_REJECTED = "IP_REJECTED";

	private List<String> whitelist = new ArrayList<String>();
	private List<String> blacklist = new ArrayList<String>();

	/**
	 * @see org.apache.servicemix.http.endpoints.HttpSoapConsumerMarshaler#createExchange(javax.servlet.http.HttpServletRequest, javax.jbi.component.ComponentContext)
	 */
	public MessageExchange createExchange(HttpServletRequest request, ComponentContext context) throws Exception {
		String requestIp = request.getRemoteAddr();
		MessageExchange m = super.createExchange(request, context);

		if (!isAllowed(requestIp)) {
			m.setStatus(ExchangeStatus.ERROR);
			m.setProperty(IP_REJECTED, Boolean.TRUE);
		}

		return m;
	}

	/**
	 * @see org.apache.servicemix.http.endpoints.HttpSoapConsumerMarshaler#sendError(javax.jbi.messaging.MessageExchange, java.lang.Exception, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
	 */
	public void sendError(MessageExchange exchange, Exception error, HttpServletRequest request, HttpServletResponse response) throws Exception {
		if (exchange != null && Boolean.TRUE.equals(exchange.getProperty(IP_REJECTED))) {
			response.setStatus(HttpServletResponse.SC_FORBIDDEN);
		} else {
			super.sendError(exchange, error, request, response);
		}
	}

	/**
	 * Test if the given ip is allowed to access this service.
	 * @param ip ip address
	 * @throws SecurityException 
	 * 
	 */
	protected boolean isAllowed(String ip) throws SecurityException {
		return ((whitelist.isEmpty() || whitelist.contains(ip)) && !blacklist.contains(ip));
	}

	private List<String> parseAndConvertAsList(String ipList) {
		List<String> res = new ArrayList<String>();
		log.debug("Parsing IP list", ipList);
		if (ipList != null) {
			String[] ips = ipList.split("\\,");
			for (String s : ips) {
				String ip = s.trim();
				if (ip.length() > 0) res.add(ip);
			}
		}
		return res;
	}

	/**
	 * @param w the whitelist to set
	 */
	public void setWhitelist(String w) {
		this.whitelist = parseAndConvertAsList(w);
	}

	/**
	 * @param b the blacklist to set
	 */
	public void setBlacklist(String b) {
		this.blacklist = parseAndConvertAsList(b);
	}
}

You can define your marshaler in the xbean.xml of your component :

<http:soap-consumer service="myService:HttpConsumer"
                    endpoint="myService:Soap"
                    targetService="fsb:Service"
                    targetEndpoint="fsb:ServiceImpl"
                    locationURI="http://0.0.0.0:8181/myService">

  <http:marshaler>
    <bean class="org.apache.servicemix.samples.ListedSoapConsumerMarshaler>
       <property name="whitelist" value="192.168.1.2"/>
       <property name="blacklist" value="192.168.1.10"/>
    </bean>
  </http:marshaler>

</http:soap-consumer>

Reference

Name Type Bean Description Required
service QName no The service name of this endpoint yes
endpoint String no The endpoint name of this endpoint yes
interfaceName QName no The interface name of this endpoint no
         
marshaler HttpProviderMarshaler yes   no
locationURI String no   no
clientSoTimeout int no   no (defaults to 60000)
ssl SslParameters yes   no
         
proxyHost String no   no
proxyPort int no   no (defaults to 80)
proxyUsername String no   no
proxyPassword String no   no
         
gzipRequest boolean no If true, the request content will be gzipped and sent over the wire. The content-encoding http header will also be set to gzip. no (defaults to false)
expectGzippedResponse boolean no If true, the accept-encoding http header will be set to gzip and the response will be un-gzipped. no (defaults to false)

The following additional properties are available for the SOAP provider endpoint:

Name Type Bean Description Required
wsdl Resource no   yes
useJbiWrapper boolean no   no (defaults to true)
validateWsdl boolean no   no (defaults to true)
policies Policy[] yes   no
soapAction String no   no