我想在不改变有效负载的情况下从http请求中检索请求上下文,所以我使用的是richher,但是看起来增强器不能是MuleMessage?我收到以下错误:
org.mule.model.resolvers.EntryPointNotFoundException: Failed to find entry point for component, the following resolvers tried but failed: [
CallableEntryPointResolver: Object "com.ict.cos.transformer.RequestContextBuilder@53dc8cb8" does not implement required interface "interface org.mule.api.lifecycle.Callable"
MethodHeaderPropertyEntryPointResolver: The required property "method" is not set on the event
ReflectionEntryPointResolver: Could not find entry point on: "com.ict.cos.transformer.RequestContextBuilder" with arguments: "{class org.apache.commons.httpclient.ContentLengthInputStream}"
AnnotatedEntryPointResolver: Component: com.ict.cos.transformer.RequestContextBuilder@53dc8cb8 doesn't have any annotated methods, skipping.
]
我的配置:
<enricher source="#[message]" target="#[flowVars['requestContext']]" doc:name="Message Enricher">
<component doc:name="Build request context">
<spring-object bean="requestContextBuilder"/>
</component>
</enricher>
requestContextBuilder:
public class RequestContextBuilder {
public RequestContext build(MuleMessage message) {
RequestContext requestContext = new RequestContext();
requestContext.setMethod(RESTMethod.get((String) message.getInboundProperty("http.method")));
requestContext.setAPI((String) message.getInboundProperty("http.request.path"));
requestContext.setQueryParams((String) message.getInboundProperty("http.query.string"));
return requestContext;
}
}
答案 0 :(得分:0)
我不认为你可以传递消息,所以我会为你想要添加到浓缩的每个标题值添加多个浓缩器。
默认情况下,有效负载将作为源传递给richher
例如
<flow name="orderProcessingFlow">
<inbound-endpoint ref="orderEndpoint"/>
<enricher>
<authorizenet:authorize cardNumber="/order/cc/number" />
<enrich target="#[header:paymentValidated]" source="/authorizenet/authorization/@valid" />
<enrich target="#[header:paymentAuthCode]" source="/authorizenet/authorization/code"/>
</enricher>
<outbound-endpoint ref="orderStep2"/>
</flow>
希望有所帮助!
答案 1 :(得分:0)
如异常所示,尝试更改组件以使其实现org.mule.api.lifecycle.Callable,您将收到MuleEvent。
答案 2 :(得分:0)
代码中的细微变化将是必要的。
首先修改组件类以实现Mule的Callable接口
public class RequestContextBuilder implements Callable {
@Override
public Object onCall(MuleEventContext eventContext) throws Exception {
MuleMessage message = eventcontext.getMessage();
RequestContext requestContext = new RequestContext();
requestContext.setMethod(RESTMethod.get((String) message.getInboundProperty("http.method")));
requestContext.setAPI((String) message.getInboundProperty("http.request.path"));
requestContext.setQueryParams((String) message.getInboundProperty("http.query.string"));
return requestContext;
}
}
然后修改richher以将有效负载(此处为requestContext)设置为flowVariable。
<enricher source="#[payload]" target="#[flowVars['requestContext']]" doc:name="Message Enricher">
<component doc:name="Build request context">
<spring-object bean="requestContextBuilder"/>
</component>
</enricher>
希望这有帮助。