mule studio 学习笔记 (一): test006-loanbroker-simple

10 篇文章 0 订阅

payload与message:

注:浏览器输入为http://localhost:11081/?name=happy&ssn=123&amount=1000&term=4。使用echo输出payload,logger指定输出message。

具体结果如下:

INFO  2014-07-15 14:04:43,063 [[test008_copy006].connector.http.mule.default.receiver.02] org.mule.component.simple.LogComponent:
********************************************************************************
* Message received in service: test008_copy006Flow1. Content is:               *
*<span style="color:#FF0000;"> '/?name=happy&ssn=123&amount=1000&term=4'   </span>                                 *
********************************************************************************

INFO  2014-07-15 14:04:43,063 [[test008_copy006].connector.http.mule.default.receiver.02] org.mule.api.processor.LoggerMessageProcessor: http message is:
org.mule.DefaultMuleMessage
{
  id=ea152cef-0be5-11e4-a9c6-1de65c70d752
 <span style="color:#FF0000;"> payload=java.lang.String</span>
  correlationId=<not set>
  correlationGroup=-1
  correlationSeq=-1
  encoding=UTF-8
  exceptionPayload=<not set>

Message properties:
  INVOCATION scoped properties:
  INBOUND scoped properties:
    Accept=text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
    Accept-Encoding=gzip, deflate
    Accept-Language=zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3
    Cache-Control=max-age=0
    Connection=true
    Host=localhost:11082
    Keep-Alive=true
    MULE_ORIGINATING_ENDPOINT=endpoint.http.0.0.0.0.11082
    MULE_REMOTE_CLIENT_ADDRESS=/127.0.0.1:2694
    User-Agent=Mozilla/5.0 (Windows NT 5.1; rv:30.0) Gecko/20100101 Firefox/30.0
   <span style="color:#FF0000;"> amount=1000</span>
    http.context.path=/
    http.context.uri=http://0.0.0.0:11082
    http.headers={Accept-Language=zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3, Host=localhost:11082, Accept-Encoding=gzip, deflate, User-Agent=Mozilla/5.0 (Windows NT 5.1; rv:30.0) Gecko/20100101 Firefox/30.0, Keep-Alive=true, Connection=true, Accept=text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8, Cache-Control=max-age=0}
    http.method=GET
    http.query.params={amount=1000, term=4, name=happy, ssn=123}
    http.query.string=name=happy&ssn=123&amount=1000&term=4
    http.relative.path=
    http.request=/?name=happy&ssn=123&amount=1000&term=4
    http.request.path=/
    http.version=HTTP/1.1
   <span style="color:#FF0000;"> name=happy
    ssn=123
    term=4</span>
  OUTBOUND scoped properties:
    MULE_ENCODING=UTF-8
  SESSION scoped properties:
}

注意:payload类型为String,故不能直接用payload['name']提取出name参数,但message.inboundProperties.name可以实现

payload['name'] 不是payload . ['name']  !!!

可使用Body to Parameter Map,使用后效果payload如下

********************************************************************************
* Message received in service: test008_copy006Flow1. Content is:               *
* '{amount=1000, term=3, name=happy, ssn=123}'                                 *
********************************************************************************

至此,payload['name']方式可用。


修改payload为自定义类


payload默认类型为String,仍可以定义为自定义类。

<expression-component doc:name="create customer request"><span style="color:#FF6600;"><![CDATA[</span>
                        import org.mule.model.CustomerQuoteRequest;
                        import org.mule.model.Customer;

                        payload = new CustomerQuoteRequest(
                                         new Customer(payload['name'], Integer.parseInt(payload['ssn'])), 
                                         Integer.parseInt(payload['amount']),
                                         Integer.parseInt(payload['term']));
                   <span style="color:#FF6600;">]]></span>
</expression-component>


返回浏览器会出现乱码,火狐会启动运行保存文件弹跳窗(原因未知?)。(详见例子test008)

INFO  2014-07-15 15:50:40,720 [[test008_copy006].connector.http.mule.default.receiver.02] org.mule.api.processor.LoggerMessageProcessor: 
org.mule.DefaultMuleMessage
{
  id=b77521ce-0bf4-11e4-95a1-f17dcd1155db
  <span style="color:#FF0000;">payload=org.mule.model.CustomerQuoteRequest</span>
  correlationId=<not set>
  correlationGroup=-1
  correlationSeq=-1
  encoding=UTF-8
  exceptionPayload=<not set>
  ......

实现类CustomerQuoteRequest和Customer

都需implements Serializable并指定private static final longserialVersionUID =
否则:

ERROR 2014-07-15 16:19:45,563 [[test008_copy006].connector.http.mule.default.receiver.02] org.mule.exception.DefaultMessagingExceptionStrategy:

********************************************************************************
Message               : Could not find a transformer to transform "SimpleDataType{type=org.mule.model.CustomerQuoteRequest, mimeType='*/*'}" to "SimpleDataType{type=org.mule.api. transport.OutputHandler, mimeType='*/*'}".
Code                  : MULE_ERROR-236
--------------------------------------------------------------------------------
Exception stack is:
1. Could not find a transformer to transform "SimpleDataType{type=org.mule.model.CustomerQuoteRequest, mimeType='*/*'}" to "SimpleDataType{type=org.mule.api.transport.OutputHandler, mimeType='*/*'}". (org.mule.api.transformer.TransformerException)
  org.mule.registry.MuleRegistryHelper:252 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/transformer/TransformerException.html)
--------------------------------------------------------------------------------

因为:

java 序列化技术可以使你将一个对象的状态写入一个Byte 流里,并且可以从其它地方把该Byte 流里的数据读出来。重新构造一个相同的对象。这种机制允许你将对象通过网络
进行传播
,并可以随时把对象持久化到数据库、文件等系统里。Java的序列化机制是RMI、EJB、JNNI等技术的技术基础。

serialVersionUID checks if the data read from the input stream is compatible with the current definition of the class.

内嵌于object中,可在更改后,改变serialVersionUID,类似于版本号,某次修改数据后,对应修改serialVersionUID。否则,可不设置serialVersionUID项。

ObjectOutputStream writes every time the value ofserialVersionUID to the output stream. ObjectInputStream reads it back and if the value read from the stream does not agree with theserialVersionUID value in the current version of the class, then it throws theInvalidClassException. Moreover, if there is no serialVersionUID officially declared in the class to be serialized, compiler automatically adds it with a value generated based on the fields declared in the class.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值