1

テスト方法があります:

@Test
    public void testHello_with_muleXmlConfig() throws Exception {

        MuleClient client = new MuleClient("mule-config-test.xml");
        client.getMuleContext().start();

        MuleMessage result = client.send("http://127.0.0.1:8080/hello", "some data", null);
        assertNotNull(result);

        assertNull(result.getExceptionPayload());
        assertFalse(result.getPayload() instanceof NullPayload);

        assertEquals("hello", result.getPayloadAsString());
    }

ここ (client.send("http://127.0.0.1:8080/hello", "some data", null)) では、パラメーター/データ = 'some data' を渡しています。

そして、私はクラスを持っています:

public class HelloWorld {
    public String sayHello() {
        return "hello";
    }
}   

これは、mule-config.xml で Spring Bean として公開されます。

<spring:bean id="helloWorld" class="org.mule.application.hello.HelloWorld"/>

<flow name="HelloWorld">
        <inbound-endpoint address="http://127.0.0.1:8080/hello"/>
        <invoke method="sayHello" object-ref="helloWorld"/>
    </flow>

パラメータ「hello」を「sayHello()」メソッドに渡すにはどうすればよいですか。「sayHello(String text)」に変更するだけでは機能しません。

4

3 に答える 3

4

これを呼び出し要素に追加する必要があります。

methodArguments="#[message.getPayload()]" methodArgumentTypes="java.lang.String"
于 2012-10-09T17:40:58.863 に答える
0

どのように/どのように機能するかがわからないinvoke: 代わりに使用することをお勧めしますcomponent

を受け入れるようにメソッドを変更するとString、次のようになります。

public String sayHello(final String text)
{
    return "hello:" + text;
}

object-to-string-transformer次に、 を使用してインバウンド入力ストリームを文字列に逆シリアル化する必要もあります。

<flow name="HelloWorld">
    <inbound-endpoint address="http://127.0.0.1:8080/hello" />
    <object-to-string-transformer />
    <component>
        <spring-object bean="helloWorld" />
    </component>
</flow>
于 2012-10-09T17:53:31.587 に答える
0

これを試して :

  • これをフローに追加します:

<invoke object-ref="helloWorld" method="sayHello" methodArguments="#[message.inboundProperties.'http.query.params'.name]" doc:name="Invoke" />

  • そして、これは呼び出されたメソッドです:

    public String sayHello(String name) { return String.format("Hello %s!", name); }

于 2015-08-17T17:03:21.983 に答える