Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
langxml
<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 :

Code Block
langjava

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:jb@nanthrax.net">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 :

Code Block
langxml

<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)

...