我目前正在编写一个使用基本身份验证的相当简单的 mule-flow
<custom-transformer class="com.org.HttpRequestToMyRequest" name="HttpRequestToMyRequest" doc:name="Java"/>
<flow name="Input_Flow" doc:name="Input_Flow">
<http:inbound-endpoint exchange-pattern="request-response" host="http://12.23.34.45" port="1234" path="/foo">
<mule-ss:http-security-filter realm="mule-realm"/>
</http:inbound-endpoint>
<flow-ref name="Sorting_Flow" doc:name="Sorting flow"/>
</flow>
<sub-flow name="Sorting_Flow" doc:name="Sorting_Flow">
<transformer ref="HttpRequestToMyRequest" doc:name="Transform Http Request to POJO with interesting methods"/>
<enricher target="#[variable:authorized]">
<http:outbound-endpoint exchange-pattern="request-response" host="12.34.45.56" port="1234" path="foo/bar" method="GET" disableTransportTransformer="true"
responseTransformer-refs="ObjectToString" doc:name="Authorization Service"/>
</enricher>
<choice doc:name="Choice">
<when expression="header:INVOCATION:authorized=true">
<processor-chain>
<component class="com.org.MyClass"/>
<transformer ref="MyObjToString"/>
<http:response-builder status="200" contentType="text/xml" doc:name="HTTP Response Builder"/>
</processor-chain>
</when>
<when SOMETHING ELSE>
DO SOMETHING ELSE
</when>
</choice>
</sub-flow>
如果我删除了 http-security-filter,则此流程按预期工作,并且 MuleMessage 中的有效负载属于 HttpRequestToMyRequest 转换器返回的 MyRequest 类型。但是,一旦我添加了安全过滤器,浓缩器就会将我的有效负载从预期的类型更改为字节 []。如果我将 byte[] 转换为 String,那么它就是 MyRequest 的实例名(com.org.MyRequest@15ae9009)。
任何帮助或想法将不胜感激。
编辑
只是要清楚。这是三个流 xml 片段,其中两个表现良好,最后一个具有我不理解的奇怪行为。
这个流程(我已在入站端点上注释掉安全过滤器)按预期工作,并且 ClassNameLogger 语句按顺序打印出 String、MyRequest、MyRequest。
<custom-transformer class="com.org.HttpRequestToMyRequest" name="HttpRequestToMyRequest" doc:name="Java"/>
<custom-transformer class="com.org.ClassNameLogger" name="ClassNameLogger" doc:name="Java"/>
<flow name="Input_Flow" doc:name="Input_Flow">
<http:inbound-endpoint exchange-pattern="request-response" host="http://12.23.34.45" port="1234" path="/foo">
<!-- <mule-ss:http-security-filter realm="mule-realm"/> -->
</http:inbound-endpoint>
<flow-ref name="Sorting_Flow" doc:name="Sorting flow"/>
</flow>
<sub-flow name="Sorting_Flow" doc:name="Sorting_Flow">
<transformer ref="ClassNameLogger" doc:name="Logs The Class Name of MuleMessage payload"/>
<transformer ref="HttpRequestToMyRequest" doc:name="Transform Http Request to POJO with interesting methods"/>
<transformer ref="ClassNameLogger" doc:name="Logs The Class Name of MuleMessage payload"/>
<enricher target="#[variable:authorized]">
<http:outbound-endpoint exchange-pattern="request-response" host="12.34.45.56" port="1234" path="foo/bar" method="GET" disableTransportTransformer="true"
responseTransformer-refs="ObjectToString" doc:name="Authorization Service"/>
</enricher>
<transformer ref="ClassNameLogger" doc:name="Logs The Class Name of MuleMessage payload"/>
<choice doc:name="Choice">
<when expression="header:INVOCATION:authorized=true">
<processor-chain>
<component class="com.org.MyClass"/>
<transformer ref="MyObjToString"/>
<http:response-builder status="200" contentType="text/xml" doc:name="HTTP Response Builder"/>
</processor-chain>
</when>
<when SOMETHING ELSE>
DO SOMETHING ELSE
</when>
</choice>
</sub-flow>
这个流程,我已经注释掉了浓缩器,按预期工作,除了它没有进入选择,因为浓缩器设置的变量没有定义。ClassNameLogger 语句按顺序打印出 String、MyRequest、MyRequest。
<custom-transformer class="com.org.HttpRequestToMyRequest" name="HttpRequestToMyRequest" doc:name="Java"/>
<custom-transformer class="com.org.ClassNameLogger" name="ClassNameLogger" doc:name="Java"/>
<flow name="Input_Flow" doc:name="Input_Flow">
<http:inbound-endpoint exchange-pattern="request-response" host="http://12.23.34.45" port="1234" path="/foo">
<mule-ss:http-security-filter realm="mule-realm"/>
</http:inbound-endpoint>
<flow-ref name="Sorting_Flow" doc:name="Sorting flow"/>
</flow>
<sub-flow name="Sorting_Flow" doc:name="Sorting_Flow">
<transformer ref="ClassNameLogger" doc:name="Logs The Class Name of MuleMessage payload"/>
<transformer ref="HttpRequestToMyRequest" doc:name="Transform Http Request to POJO with interesting methods"/>
<transformer ref="ClassNameLogger" doc:name="Logs The Class Name of MuleMessage payload"/>
<!-- <enricher target="#[variable:authorized]">
<http:outbound-endpoint exchange-pattern="request-response" host="12.34.45.56" port="1234" path="foo/bar" method="GET" disableTransportTransformer="true"
responseTransformer-refs="ObjectToString" doc:name="Authorization Service"/>
</enricher> -->
<transformer ref="ClassNameLogger" doc:name="Logs The Class Name of MuleMessage payload"/>
<choice doc:name="Choice">
<when expression="header:INVOCATION:authorized=true">
<processor-chain>
<component class="com.org.MyClass"/>
<transformer ref="MyObjToString"/>
<http:response-builder status="200" contentType="text/xml" doc:name="HTTP Response Builder"/>
</processor-chain>
</when>
<when SOMETHING ELSE>
DO SOMETHING ELSE
</when>
</choice>
</sub-flow>
这个流程,其中我有丰富器和安全过滤器,没有按预期工作,ClassNameLogger 语句按顺序打印出,String,MyRequest,byte[]。
<custom-transformer class="com.org.HttpRequestToMyRequest" name="HttpRequestToMyRequest" doc:name="Java"/>
<custom-transformer class="com.org.ClassNameLogger" name="ClassNameLogger" doc:name="Java"/>
<flow name="Input_Flow" doc:name="Input_Flow">
<http:inbound-endpoint exchange-pattern="request-response" host="http://12.23.34.45" port="1234" path="/foo">
<mule-ss:http-security-filter realm="mule-realm"/>
</http:inbound-endpoint>
<flow-ref name="Sorting_Flow" doc:name="Sorting flow"/>
</flow>
<sub-flow name="Sorting_Flow" doc:name="Sorting_Flow">
<transformer ref="ClassNameLogger" doc:name="Logs The Class Name of MuleMessage payload"/>
<transformer ref="HttpRequestToMyRequest" doc:name="Transform Http Request to POJO with interesting methods"/>
<transformer ref="ClassNameLogger" doc:name="Logs The Class Name of MuleMessage payload"/>
<enricher target="#[variable:authorized]">
<http:outbound-endpoint exchange-pattern="request-response" host="12.34.45.56" port="1234" path="foo/bar" method="GET" disableTransportTransformer="true"
responseTransformer-refs="ObjectToString" doc:name="Authorization Service"/>
</enricher>
<transformer ref="ClassNameLogger" doc:name="Logs The Class Name of MuleMessage payload"/>
<choice doc:name="Choice">
<when expression="header:INVOCATION:authorized=true">
<processor-chain>
<component class="com.org.MyClass"/>
<transformer ref="MyObjToString"/>
<http:response-builder status="200" contentType="text/xml" doc:name="HTTP Response Builder"/>
</processor-chain>
</when>
<when SOMETHING ELSE>
DO SOMETHING ELSE
</when>
</choice>
</sub-flow>
编辑 2
HttpRequestToMyRequest 转换器中的代码
public class HttpRequestToMyRequest extends AbstractMessageTransformer{
@Override
public Object transformMessage(MuleMessage message, String outputEncoding) throws TransformerException {
if("/foo".equals(message.getInboundProperty("http.request.path")){
return new MyFooRequest();
}
if("/bar".equals(message.getInboundParameter("http.request.path")){
return new MyBarRequest();
}
else return new MyEmptyRequest();
}
}
编辑 3
显然这是 Mule 3.3 特有的。一旦我升级到 3.4,一切都开始按预期工作。