Mule ESB Configuration Patterns 配置摘要

为了节省时间,就不翻译了,摘抄重点总结下, 本文大部分摘抄自Mule ESB官网入门教程 Guide.pdf这本书中.

常用的配置定式简介

   Simple Service  : Exposes JAX-WS annotated components as SOAP web services. Exposes JAX-RS annotated beans as RESTful components.Can also handle JAXB, XML and raw content with simple POJO components.

   WebService Proxy : Proxies remote web services. Can perform transformations on the SOAP envelope. Can rewrite or redirect remote WSDLs to localones.

   Bridge : Establishes a direct conduit between an inbound endpoint and an outbound endpoint. Supports request-response and one-way bridging. Can perform transformations. Supports transactional bridging of inbound to outbound.

   Validator : Validates inbound messages against a defined acceptance filter. Returns an ACK or NACK response synchronously and dispatches valid messages asynchronously.

下面只总结 simple service 和 webservice proxy 两种常用的配置定式 的常用配置

   Simple service : 把组件发布成 简单的mule service ,包括webservice

   (1) 把pojo定义成simple service

<pattern:simple-service name="maths-service"
address="vm://maths.in"
component-class="org.mule.tck.services.SimpleMathsComponent" />

<!-- 使用引用 -->
<pattern:simple-service name="maths-service"
endpoint-ref="maths-service-endpoint"
component-ref="math-component" />

<!-- 使用transformers -->
<pattern:simple-service name="byte-array-massager"
address="vm://bam.in"
transformer-refs="byte-array-to-string append-bar"
responseTransformer-refs="append-baz string-to-byte-array"
component-class="org.mule.component.simple.EchoComponent" />

<!-- 使用子元素 -->



<pattern:simple-service name="maths-service"component-class="org.mule.tck.services.SimpleMathsComponent"><vm:inbound-endpoint path="maths.in"exchange-pattern="request-response" /><custom-exception-strategy class="com.acme.AcmeExceptionStrategy" /></simple-service>
<!-- 使用Inheritance -->
<pattern:simple-service name="global-exception-strategy"
abstract="true">
<custom-exception-strategy class="com.acme.AcmeExceptionStrategy" />
</pattern:simple-service>
<pattern:simple-service name="inherited-exception-strategy"
parent="global-exception-strategy"
address="vm://maths.in"
component-class="org.mule.tck.services.SimpleMathsComponent" />

<!--发布成JAX-WS Service-->
<pattern:simple-service name="weather-forecaster-ws"
address="http://localhost:6099/weather-forecast"
component-class="org.mule.test.integration.tck.WeatherForecaster"
type="jax-ws" />

<!--发布成JAX-RS Service-->



<pattern:simple-service name="weather-report-rsc"address="http://localhost:6099/rest"component-class="org.mule.test.integration.tck.WeatherReportResource"type="jax-rs" />




  (2)JAXB 支持配置

<pattern:simple-service name="weather-jaxb-consumer"
address="vm://weather-consumer.in"
component-class="org.mule.test.integration.tck.WeatherReportConsumer" />

对应的WeatherReportConsumer类代码,注意:it is required that @Payload, a Mule-specific annotation, is used on the component:

package org.mule.test.integration.tck;
import org.mule.api.annotations.param.Payload;
public class WeatherReportConsumer
{
public String consume(@Payload WeatherReportType weatherReport)
{
return weatherReport.report;
}
}

   (3) XPath 支持配置

<pattern:simple-service name="weather-xpath-consumer"
address="vm://weather-xpath-consumer.in"
component-class="org.mule.test.integration.tck.WeatherReportXpathConsumer" />

对应的WeatherReportXpathConsumer类代码,注意: a Mule annotation, @XPath in this case, is needed for this to work

package org.mule.test.integration.tck;
import org.mule.api.annotations.expression.XPath;
public class WeatherReportXpathConsumer
{
public String consume(@XPath(value = "/weatherReport/report") String report)
{
return report;
}
}

    Web Service Proxy Pattern :  Web Service Proxy在安全和审查等情形下是一种非常通用的实践, 它允许用非常简短和简单的方式去配置一个proxy.

    核心特性:
         add or remove HTTP headers, 添加或移除http协议头
         transform the SOAP envelope (body or header) to add or remove specific entries, 转换soap请求信息,增加或移除特殊条目
         rewrite remote WSDLs so they appear to bind to services inside a corporate firewall, 重写wsdl文件,从而指向防火墙内部的service
         introduce custom error handling. 错误处理

    常用配置

<!--Web Service Proxy-->
<pattern:web-service-proxy name="weather-forecast-ws-proxy"
inboundAddress="http://localhost:8090/weather-forecast"
outboundAddress="http://ws.acme.com:6090/weather-forecast" />

<!--Proxy with Transformers-->
<pattern:web-service-proxy name="weather-forecast-ws-proxy-transformers"
inboundAddress="http://localhost:8090/weather-forecast"
transformer-refs="zip-code-transformer add-credentials-transformer"
responseTransformer-refs="weather-code-transformer"
outboundEndpoint-ref="target-ws-endpoint" />

<!--Child Elements 子元素 -->
<pattern:web-service-proxy name="weather-forecast-ws-proxy">
<http:inbound-endpoint address="http://localhost:8090/weather-forecast" />
<http:outbound-endpoint address="http://ws.acme.com:6090/weather-forecast" />
<custom-exception-strategy class="com.acme.AcmeExceptionStrategy" />
</pattern:web-service-proxy>

<!--Inheritance 继承关系 -->
<pattern:web-service-proxy name="abstract-ws-proxy-zipcode-changer"
abstract="true"
transformer-refs="zip-code-transformer add-credentials-transformer"
responseTransformer-refs="weather-code-transformer" />
<pattern:web-service-proxy name="weather-forecast-ws-proxy"
parent="abstract-ws-proxy-zipcode-changer">
<http:inbound-endpoint address="http://localhost:8090/weather-forecast" />
<http:outbound-endpoint address="http://ws.acme.com/weather-forecast" />
</pattern:web-service-proxy>

<!--Remote WSDL Redirection 以远程方式重定向wsdl文件-->
<pattern:web-service-proxy name="weather-forecast-ws-proxy"
inboundAddress="http://localhost:8090/weather-forecast"
outboundAddress="http://ws.acme.com:6090/weather-forecast"
wsdlLocation="http://ws.acme.com:6090/wsdl/weather-forecast" />

<!--File WSDL Redirection  以指定文件方式重定向wsdl文件-->
<pattern:web-service-proxy name="weather-forecast-ws-proxy"
inboundAddress="http://localhost:8090/weather-forecast"
outboundAddress="http://ws.acme.com:6090/weather-forecast"
wsdlFile="path/to/correct/weather-forecaster.wsdl" />


   

    

   







评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值