1

您好,我通过 Carbon Studio 创建了以下类调解器:

 package my.mediation;

    import org.apache.synapse.MessageContext; 
    import org.apache.synapse.mediators.AbstractMediator;

    public class Auth extends AbstractMediator { 


        public boolean mediate(MessageContext context) { 
            // TODO Implement your mediation logic here 

            context.setProperty("message","hello world!" );

            return true;
        }

}

顺序如下:

<inSequence xmlns="http://ws.apache.org/ns/synapse">
   <property name="message" value="nothing" scope="default" />
   <class name="my.mediation.Auth" />
   <log>
      <property name="Message******" expression="get-property('message')" />
   </log>
</inSequence

> 问题是它总是打印文本“nothing”而不是打印 Message: "HelloWorld"...有什么建议吗?

4

2 回答 2

3

您的方案是完全有效的,您的配置似乎也很好。

我已经绑定了你的场景,它对我来说很好。

以下是我的配置。

班级调解员:

package org.wso2.mediator;

import org.apache.synapse.MessageContext; 
import org.apache.synapse.mediators.AbstractMediator;

public class SampleMediator extends AbstractMediator { 

    public boolean mediate(MessageContext context) { 
        context.setProperty("Message", "HelloWorld!");
        return true;
    }
}

我的代理服务:

<proxy xmlns="http://ws.apache.org/ns/synapse" name="SimpleProxy"
    statistics="disable" trace="disable" transports="http,https">
    <target>
        <inSequence>
            <log category="INFO" level="simple" separator=","/>
            <property action="set" name="Message" scope="default"
                type="STRING" value="DefaultMessage"/>
            <class name="org.wso2.mediator.SampleMediator"/>
            <log category="INFO" level="simple" separator=",">
                <property expression="get-property('Message')" name="===========Message Value=========="/>
            </log>
            <drop/>
        </inSequence>
    </target>
</proxy>

当我在没有类中介的情况下调用代理服务时,它会打印

INFO - LogMediator To: /services/SimpleProxy.SimpleProxyHttpSoap12Endpoint,WSAction: urn:mediate,SOAPAction: urn:mediate,MessageID: urn:uuid:81150094-cbc4-44f7-83eb-251e28149564,Direction: request,===========Message Value========== = DefaultMessage

当我使用它打印的类中介调用代理服务时,

INFO - LogMediator To: /services/SimpleProxy.SimpleProxyHttpSoap12Endpoint,WSAction: urn:mediate,SOAPAction: urn:mediate,MessageID: urn:uuid:e3a04341-907c-40fe-9f58-5a10d2ce346a,Direction: request,===========Message Value========== = HelloWorld!

希望这可以帮助!

哈沙娜

于 2012-09-08T00:15:29.343 回答
1

问题基于log4j.properties。您的课程在 my.mediation 包中;这在 log4j.properties 中不存在。您需要转到YOUR_WSO2/lib/log4j.properties并为您的命名空间/包添加日志级别:

...
log4j.logger.org.wso2=INFO
log4j.logger.my.mediation=DEBUG

在这里,您还看到了为什么来自 Harashana 的示例有效 - 他只是将包更改为 org.wso2 - 您不应该为自己的自定义调解器这样做。

于 2012-09-10T08:17:33.127 回答