【问题标题】:How to call wso2 esb proxy service from wso2 esb schedular如何从 wso2 esb schedular 调用 wso2 esb 代理服务
【发布时间】:2015-03-27 12:38:02
【问题描述】:

我想通过定时任务调用代理服务,下面是我的调度器,

public class SchedularTask implements Task, ManagedLifecycle {

    /**
     * Synapse environment.
     */
    private SynapseEnvironment synapseEnvironment;

    /**
     * Endpoint Url.
     */
    private String endPointUrl;

    /**
     * Phone number.
     */
    private String phoneNumber;

    /**
     * License key.
     */
    private String licenseKey;

    /**
     * Initializing the Life cycle.
     */
    @Override
    public void init(SynapseEnvironment synapseEnvironmentParam) {
        this.synapseEnvironment = synapseEnvironmentParam;
    }

    /**
     * Executing the task.
     */
    @Override
    public void execute() {
        MessageContext messageContext = synapseEnvironment
                .createMessageContext();
        messageContext.setProperty("phoneNumber", this.phoneNumber);
        messageContext.setProperty("licenseKey", this.licenseKey);
        messageContext.setTo(new EndpointReference(endPointUrl));
        synapseEnvironment.injectMessage(messageContext);
    }

    /**
     * Destroying.
     */
    @Override
    public void destroy() {

    }

    /**
     * @return the endPointUrl
     */
    public final String getEndPointUrl() {
        return endPointUrl;
    }

    /**
     * @param endPointUrl
     *            the endPointUrl to set
     */
    public final void setEndPointUrl(final String endPointUrl) {
        this.endPointUrl = endPointUrl;
    }

    /**
     * @return the phoneNumber
     */
    public final String getPhoneNumber() {
        return phoneNumber;
    }

    /**
     * @param phoneNumber
     *            the phoneNumber to set
     */
    public final void setPhoneNumber(final String phoneNumber) {
        this.phoneNumber = phoneNumber;
    }

    /**
     * @return the licenseKey
     */
    public final String getLicenseKey() {
        return licenseKey;
    }

    /**
     * @param licenseKey
     *            the licenseKey to set
     */
    public final void setLicenseKey(final String licenseKey) {
        this.licenseKey = licenseKey;
    }

}

我将 endpoinUrl 作为 http://{ip}:8290/services/a 传递,这是一个名为 a 的代理服务的端点。

但我在 esb 控制台中找不到任何自定义日志,我已将其按代理服务的顺序放置,(这意味着代理服务未命中) 但是esb控制台中有如下计划任务的日志

[2015-03-21 18:15:18,934]  INFO - LogMediator To: http://{ip}:8290/services/a, MessageID: urn:uuid:c527c357-564f-4b58-804e-54e8e7a6a3f5, Direction: request, Envelope: <?xml version="1.0" encoding="utf-8"?><soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"><soapenv:Body></soapenv:Body></soapenv:Envelope>

我还尝试在调度程序中使用日志记录,我尝试了 log4j 和 apache commons,但没有成功。是否有任何配置可以激活日志记录。

【问题讨论】:

    标签: proxy wso2 scheduled-tasks wso2esb


    【解决方案1】:

    您可以使用代理检查以下示例调度程序任务。

     <task name="SampleInjectToProxyTask"
             class="org.apache.synapse.startup.tasks.MessageInjector"
             group="synapse.simple.quartz">
          <trigger count="5" interval="5"/>
          <property xmlns:task="http://www.wso2.org/products/wso2commons/tasks"
                    name="soapAction"
                    value="getQuote"/>
          <property xmlns:task="http://www.wso2.org/products/wso2commons/tasks"
                    name="format"
                    value="soap11"/>
          <property xmlns:task="http://www.wso2.org/products/wso2commons/tasks"
                    name="injectTo"
                    value="proxy"/>
          <property xmlns:task="http://www.wso2.org/products/wso2commons/tasks" name="message">
             <m0:getQuote xmlns:m0="http://services.samples">
                <m0:request>
                   <m0:symbol>IBM</m0:symbol>
                </m0:request>
             </m0:getQuote>
          </property>
          <property xmlns:task="http://www.wso2.org/products/wso2commons/tasks"
                    name="proxyName"
                    value="testProxy"/>
       </task>
    
     <proxy name="testProxy"
              transports="https http"
              startOnLoad="true"
              trace="disable">
          <description/>
          <target>
             <inSequence>
              <send >
                <endpoint key="StockQuoteEpr"/> 
              </send>
             </inSequence>
          </target> 
       </proxy>
    
    <endpoint name="StockQuoteEpr">
         <address uri="http://localhost:9000/services/SimpleStockQuoteService"/>
     <sequence name="main">
          <in>
             <log level="full"/>
             <filter source="get-property('To')" regex="http://localhost:9000.*">
                <send/>
             </filter>
          </in>
          <out>
             <send/>
          </out>
          <description>The main sequence for the message mediation</description>
       </sequence>
       </endpoint>
    

    【讨论】:

      猜你喜欢
      • 2012-06-15
      • 1970-01-01
      • 2015-09-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多