2

我想在不更改有效负载的情况下从 http 请求中检索请求上下文,所以我使用了丰富器,但似乎丰富器不能是 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;
    }
}
4

3 回答 3

0

我认为您不能传入消息,因此我会为您想要添加到扩充中的每个标头值设置多个扩充器。

默认情况下,有效负载将作为源传递给丰富器

例如

<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>

希望有帮助!

于 2013-08-29T12:01:54.323 回答
0

正如异常所暗示的,尝试更改您的组件以使其实现 org.mule.api.lifecycle.Callable,您将收到一个 MuleEvent。

于 2013-08-29T14:08:42.743 回答
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;
    }    
}

然后修改enricher,将payload(这里是requestContext)设置为flowVariable。

<enricher source="#[payload]" target="#[flowVars['requestContext']]" doc:name="Message Enricher">
    <component doc:name="Build request context">
        <spring-object bean="requestContextBuilder"/>
    </component>
</enricher>

希望这可以帮助。

于 2013-08-30T12:26:37.423 回答