0

在我的 WSO2 ESB 4.7.0 中,我配置了这个代理:

<proxy xmlns="http://ws.apache.org/ns/synapse" name="SendingByJmsAddressProxy"
     transports="https,http"
     statistics="disable"
     trace="disable"
     startOnLoad="true">
 <target>
    <inSequence>
       <send>
          <endpoint>
             <address uri="http://localhost:8080/RestService/rest/servizio"/>
          </endpoint>
       </send>
    </inSequence>
    <outSequence>
       <log>
          <property name="codice" expression="//codice"/>
       </log>
       <log level="full"/>
       <switch source="//codice">
          <case regex="asd">
             <send/>
          </case>
          <case regex="0">
             <log>
                <property name="codice" value="check1"/>
             </log>
             <send/>
             <payloadFactory media-type="xml">
                <format>
                   <code>$1</code>
                </format>
                <args>
                   <arg xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope" evaluator="xml"
                        expression="//codice"/>
                </args>
             </payloadFactory>
             <property name="messageType" value="application/xml"/>
             <log level="full"/>
             <send>
                <endpoint>
                   <address uri="jms:/testQueue?transport.jms.ConnectionFactoryJNDIName=QueueConnectionFactory&java.naming.factory.initial=org.wso2.andes.jndi.PropertiesFileInitialContextFactory&java.naming.provider.url=repository/conf/jndi.properties&transport.jms.DestinationType=queue"/>
                </endpoint>
             </send>
          </case>
       </switch>
    </outSequence>
 </target>
 <description/>
</proxy>

在 inSequence 中,我将客户端的请求转发给 Rest Service,其响应是一个如下所示的 json 字符串:

{
  "codice":"0",
  "messaggio":"Operazione effettuata 18:12",
  "path":"\/path\/1AASSCOGNOME_NOME.111.2231\/",
  "documenti":[{
            "idAggregatoContenitore":"3508",
            "idDocumento":"016601",
            "idVersione":"17010",
            "numVersione":"1",
            "tipoDocumento":"Documento",
            "autore":"sysadmin",
            "titolo":"prova1",
            "fileName":"FStandard.xml",
            "checkedOut":"false",
            "idDocumentoPadre":"",
            "flagAllegati":"false",
            "flagDaProtocollare":"true",
            "dataCreazione":"11\/02\/2013 19:05",
            "dataChekin":"11\/02\/2013 19:05",
            "mimeType":"text\/xml",
            "empty":"false",
            "data":"1660100000",
            "cache":"false",
            "tipo":"D",
            "nome":"prova1",
            "keyData":"16601",
            "keyNome":"prova1",
            "keyNumero":"",
            "keyTipo":"D",
            "fileExtension":"path\/xml_file.png",
            "evidenza":"false",
            "originalDocumentoPadreId":"",
            "originalDocumentoId":"016601",
            "originalAggregatoContenitoreId":"3508"
          },
          {
            "idAggregatoContenitore":"3508",
            "idDocumento":"016602",
            "idVersione":"17011",
            "numVersione":"1",
            "tipoDocumento":"Documento",
            "autore":"sysadmin",
            "titolo":"123456789",
            "fileName":"HTTP Proxy Server.jmx",
            "checkedOut":"false",
            "idDocumentoPadre":"",
            "flagAllegati":"false",
            "flagDaProtocollare":"true",
            "dataCreazione":"11\/02\/2013 19:19",
            "dataChekin":"11\/02\/2013 19:19",
            "mimeType":"application\/octet-stream",
            "empty":"false",
            "data":"1660200000",
            "cache":"false",
            "tipo":"D",
            "nome":"123456789",
            "keyData":"16602",
            "keyNome":"123456789",
            "keyNumero":"",
            "keyTipo":"D",
            "fileExtension":"path\/Documento.png",
            "evidenza":"false",
            "originalDocumentoPadreId":"",
            "originalDocumentoId":"016602",
            "originalAggregatoContenitoreId":"3508"
          }],
  "data":"350800000",
  "tipoAggregatoEnum":"R",
  "statoEnum":"aperto",
  "keyData":"1360602720000",
  "keyNome":"1aasscognome_nome.111.2231",
  "nomeAggregatoNoNumero":"1AASSCOGNOME_NOME.111.2231",
  "keyNumero":"1AASSCOGNOME_NOME.111.2231",
  "keyTipo":"R",
  "originalAggregatoId":"3508",
  "originalAggregatoPadre":"3108"
}

作为标准行为,ESB 将传入的 json 消息转换为 xml 格式的消息。现在在 outSequence 我想要:

1) 向客户端发回 RestService 响应:由中介

2)然后我想构建一个xml消息,从消息有效负载中提取一些元素,然后通过jms协议将其发送到其他地方。

除了 PayloadFactory 中介之外,代理都可以正常工作。实际上,由 Payload Factory 中介构建的消息的主体是空的:

<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
<Body>
  <code xmlns="http://ws.apache.org/ns/synapse"/>
</Body>
</soapenv:Envelope>

谁能告诉我为什么指定的 arg 标签为空(xpath 表达式似乎是正确的)?怎么了?谢谢

4

1 回答 1

0

也许我已经解决了。最后,我需要发送两条消息:第一条是简单的

<send/> 

应该必须将服务的响应返回给调用客户端。在此之后,我需要向其他地方发送第二条消息。在上面的代码中,我使用了另一个发送调解器......但似乎第一个 () 清空了消息有效负载,因此 arg 表达式因此为空。使用克隆调解器我解决了这个问题:

<outSequence>
     <log>
        <property name="codice" expression="//codice"/>
     </log>
     <log level="full"/>
     <switch source="//codice">
        <case regex="asd">
           <send/>
        </case>
        <case regex="0">
           <log>
              <property name="codice" value="check1"/>
           </log>
           <clone>
              <target>
                 <sequence>
                    <send/>
                 </sequence>
              </target>
              <target>
                 <sequence>
                    <payloadFactory media-type="xml">
                       <format>
                          <messaggio>$1</messaggio>
                       </format>
                       <args>
                          <arg xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope" evaluator="xml"
                               expression="//messaggio"/>
                       </args>
                    </payloadFactory>
                    <property name="messageType" value="application/xml"/>
                    <log level="full"/>
                    <send>
                       <endpoint>
                          <address uri="jms:/NuovoEvento?transport.jms.ConnectionFactoryJNDIName=QueueConnectionFactory&java.naming.factory.initial=org.wso2.andes.jndi.PropertiesFileInitialContextFactory&java.naming.provider.url=repository/conf/jndi.properties&transport.jms.DestinationType=topic"/>
                       </endpoint>
                    </send>
                 </sequence>
              </target>
           </clone>
        </case>
     </switch>
  </outSequence>
于 2013-10-29T10:33:07.590 回答