You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@servicemix.apache.org by Liav Ezer <li...@gmail.com> on 2008/12/30 12:15:23 UTC

Re: [CONF] Apache ServiceMix: servicemix-http new endpoints (page edited)

Hi Jean,
 
i was refered by someone to the new servicemix-http endpoint called
http:soap-consumer. 

I can add a ListedSoapConsumerMarshaler bean to it in order to filter
predefined ip's from consuming my service. 

My questions are: 
 
1. Can i interfere in the Java code (detailed in
http://servicemix.apache.org/servicemix-http-new-endpoints.html) of this
bean in order to query the URI of the client or to query the SOAP header
request of the client?

2. Where do i put this Java file? in <su-directory>\src\main\resources ?
 
Thanks. 


confluence-2 wrote:
> 
> 
> 
>     
>     
> 
> 
> 
> 
> 
> 
> 
>     
>         
>             Page Edited :
>             SM  :
>             servicemix-http new endpoints 
>         
>     
> 
>      
>         servicemix-http new endpoints 
>         has been edited by             Jean-Baptiste Onofré 
>             (Nov 25, 2008).
>      
>     
>      
>                  (View changes) 
>      
> 
>     Content: 
>     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. 
> 
> 
> 	http:consumer 
> 
> 
> 
> Simple examples
> 
> 
> &lt;http:consumer service="my:ConsumerService"
>                endpoint="jbi"
>                targetService="t2:ProviderService"
>                targetEndpoint="ep"
>                locationURI="http://0.0.0.0:8192/person/" /&gt; 
> 
> 
> 
> &lt;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" /&gt; 
> 
> 
> 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 
> 
> 
> &nbsp;
> &nbsp;
> &nbsp;
> &nbsp;
> &nbsp;
> 
> 
>  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 
> 
> 
> &nbsp;
> &nbsp;
> &nbsp;
> &nbsp;
> &nbsp;
> 
> 
>  authMethod 
>  String 
>  no 
> &nbsp;
>  no 
> 
> 
>  locationURI 
>  String 
>  no 
> &nbsp;
>  yes 
> 
> 
>  ssl 
>  SslParameters 
>  yes 
> &nbsp;
>  no 
> 
> 
>  marshaler 
>  HttpConsumerMarshaler 
>  yes 
> &nbsp;
>  no 
> 
> 
>  timeout 
>  long 
>  no 
> &nbsp;
>  no 
> 
> 
>  defaultMep 
>  URI 
>  no 
> &nbsp;
>  no (defaults to InOut) 
> 
> 
> 
> The following additional properties are available for the SOAP consumer
> endpoint: 
> 
> 
> 
>  Name 
>  Type 
>  Bean 
>  Description 
>  Required 
> 
> 
>  wsdl 
>  Resource 
>  no 
> &nbsp;
>  yes 
> 
> 
>  useJbiWrapper 
>  boolean 
>  no 
> &nbsp;
>  no (defaults to true) 
> 
> 
>  validateWsdl 
>  boolean 
>  no 
> &nbsp;
>  no (defaults to true) 
> 
> 
>  policies 
>  Policy[] 
>  yes 
> &nbsp;
>  no 
> 
> 
> 
> Provider endpoints
> 
> Simple examples
> 
> 
> &lt;http:provider service="t2:ProviderService"
>                endpoint="ep"
>                locationURI="http://192.168.0.12:8080" /&gt; 
> 
> 
> 
> &lt;http:soap-provider service="t2:ProviderService"
>                     endpoint="ep"
>                     wsdl="classpath:service.wsdl" /&gt; 
> 
> 
> 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 &lt;a href="mailto:jb@nanthrax.net"&gt;Jean-Baptiste
> Onofré&lt;/a&gt;
>  * @version $Revision: 1.1 $
>  */
> public class ListedSoapConsumerMarshaler extends HttpSoapConsumerMarshaler
> {
> 	private static final String IP_REJECTED = "IP_REJECTED";
> 
> 	private List&lt;String&gt; whitelist = new ArrayList&lt;String&gt;();
> 	private List&lt;String&gt; blacklist = new ArrayList&lt;String&gt;();
> 
> 	/**
> 	 * @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 &amp;&amp;
> 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)) &amp;&amp;
> !blacklist.contains(ip));
> 	}
> 
> 	private List&lt;String&gt; parseAndConvertAsList(String ipList) {
> 		List&lt;String&gt; res = new ArrayList&lt;String&gt;();
> 		log.debug("Parsing IP list", ipList);
> 		if (ipList != null) {
> 			String[] ips = ipList.split("\\,");
> 			for (String s : ips) {
> 				String ip = s.trim();
> 				if (ip.length() &gt; 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 : 
> 
> 
> &lt;http:soap-consumer service="myService:HttpConsumer"
>                     endpoint="myService:Soap"
>                     targetService="fsb:Service"
>                     targetEndpoint="fsb:ServiceImpl"
>                     locationURI="http://0.0.0.0:8181/myService"&gt;
> 
>   &lt;http:marshaler&gt;
>     &lt;bean
> class="org.apache.servicemix.samples.ListedSoapConsumerMarshaler&gt;
>        &lt;property name="whitelist" value="192.168.1.2"/&gt;
>        &lt;property name="blacklist" value="192.168.1.10"/&gt;
>     &lt;/bean&gt;
>   &lt;/http:marshaler&gt;
> 
> &lt;/http:soap-consumer&gt; 
> 
> 
> 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 
> 
> 
> &nbsp;
> &nbsp;
> &nbsp;
> &nbsp;
> &nbsp;
> 
> 
>  marshaler 
>  HttpProviderMarshaler 
>  yes 
> &nbsp;
>  no 
> 
> 
>  locationURI 
>  String 
>  no 
> &nbsp;
>  no 
> 
> 
>  clientSoTimeout 
>  int 
>  no 
> &nbsp;
>  no (defaults to 60000) 
> 
> 
>  ssl 
>  SslParameters 
>  yes 
> &nbsp;
>  no 
> 
> 
> &nbsp;
> &nbsp;
> &nbsp;
> &nbsp;
> &nbsp;
> 
> 
>  proxyHost 
>  String 
>  no 
> &nbsp;
>  no 
> 
> 
>  proxyPort 
>  int 
>  no 
> &nbsp;
>  no (defaults to 80) 
> 
> 
>  proxyUsername 
>  String 
>  no 
> &nbsp;
>  no 
> 
> 
>  proxyPassword 
>  String 
>  no 
> &nbsp;
>  no 
> 
> 
> &nbsp;
> &nbsp;
> &nbsp;
> &nbsp;
> &nbsp;
> 
> 
>  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 
> &nbsp;
>  yes 
> 
> 
>  useJbiWrapper 
>  boolean 
>  no 
> &nbsp;
>  no (defaults to true) 
> 
> 
>  validateWsdl 
>  boolean 
>  no 
> &nbsp;
>  no (defaults to true) 
> 
> 
>  policies 
>  Policy[] 
>  yes 
> &nbsp;
>  no 
> 
> 
>  soapAction 
>  String 
>  no 
> &nbsp;
>  no 
> 
> 
> 
> 
> 
> 
> 
> 
> 
>     
>         
>     
> 
> 
> 
>     Powered by
>     Atlassian Confluence 
>     (Version: 2.2.9 Build:#527 Sep 07, 2006)
>     -
>     Bug/feature request 
>     
>     Unsubscribe or edit your notifications preferences 
> 
> 
> 
> 
> 
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/-CONF--Apache-ServiceMix%3A-servicemix-http-new-endpoints-%28page-edited%29-tp20681448p21215830.html
Sent from the ServiceMix - Dev mailing list archive at Nabble.com.