How we can write a data in to text file using wso2esb

帅比萌擦擦* 提交于 2019-12-23 03:20:56

问题


i am getting a data or string from front end i am setting the data or string in one property that property data i need to send in text file every time they will send the data i need keep the data in same file without override how can i do i have done using VFS transport i uncommented sender section of vfs in configuration file even though its not working fine below configuration

    <?xml version="1.0" encoding="UTF-8"?>
    <proxy xmlns="http://ws.apache.org/ns/synapse"
           name="FileWrite"
           transports="https http"
           startOnLoad="true"
           trace="disable">
       <description/>
       <target>
          <inSequence>
             <property name="error" expression="//error/text()" scope="default"/>
             <log level="full"/>
          </inSequence>
          <outSequence>
             <log>
 <property name="error" expression="get-property('error')" scope="default"/>
                <property name="OUT_ONLY" value="true"/>
             </log>
             <payloadFactory>
                <format>
                   <error>$1</error>
                </format>
                <args>
                   <arg expression="get-property('error')"/>
                </args>
             </payloadFactory>
             <log level="full"/>
             <send>
                <endpoint>
                   <address uri="vfs:file:///home/youtility2/Desktop/Errorlog.text"/>
                </endpoint>
             </send>
             <log level="full"/>
          </outSequence>
       </target>
       <parameter name="transport.vfs.Append">true</parameter>
    </proxy> 

i created text file on desktop but data is not writing in text file and also not giving any exception also will refer something for this


回答1:


You have to enable VFS Transport for the Proxy service. In proxy creation/edit wizard you can select necessary transports. Once you have enabled VFS transport in axis2.xml, VFS will apear as an available transport for services. So if it is to use in a proxy service it should be enabled to that particular service as well.

So in your proxy element, transport attribute will be transports="https http vfs"

In order to append to the same file, define the transport.vfs.Append parameter with the file URI as described in the doc[2]

[2]http://docs.wso2.org/wiki/display/ESB450/VFS+Transport

    <?xml version="1.0" encoding="UTF-8"?>
    <proxy xmlns="http://ws.apache.org/ns/synapse"
           name="FileWrite"
           transports="https http vfs"
           startOnLoad="true"
           trace="disable">
       <description/>
       <target>
          <inSequence>
             <property name="OUT_ONLY" value="true"/>
             <property name="error" expression="//error/text()" scope="default"/>
             <log level="full"/>
          </inSequence>
          <outSequence>
             <log>
 <property name="error" expression="get-property('error')" scope="default"/>
                <property name="OUT_ONLY" value="true"/>
             </log>
             <payloadFactory>
                <format>
                   <error>$1</error>
                </format>
                <args>
                   <arg expression="get-property('error')"/>
                </args>
             </payloadFactory>
             <log level="full"/>
             <send>
                <endpoint>
                   <address uri="vfs:file:///home/youtility2/Desktop/Errorlog.text?transport.vfs.Append=true"/>
                </endpoint>
             </send>
             <log level="full"/>
          </outSequence>
       </target>
       <parameter name="transport.vfs.Append">true</parameter>
    </proxy> 



回答2:


Below code shows the capability to insert payload into a file. You don't need to use vfs as transport.

<proxy xmlns="http://ws.apache.org/ns/synapse"
       name="WriteIntoFile"
       transports="https,http"
       statistics="disable"
       trace="disable"
       startOnLoad="true">
   <target>
      <inSequence>
         <property name="OUT_ONLY" value="true" scope="default" type="STRING"/>
         <property name="transport.vfs.ReplyFileName"
                   expression="fileName.xml')"
                   scope="transport"/>
         <send>
            <endpoint>
               <address uri="vfs:ftp://admin:admin@localhost:21/srcFolder?vfs.passive=true"/>
            </endpoint>
         </send>
      </inSequence>
   </target>
</proxy>



回答3:


  1. You have to set VFS as a transport in your proxy to use vfs.
  2. The way you define transport.vfs.Append parameter is wrong

it should be as In URL

vfs:file:///home/user/test/out? transport.vfs.Append=true " 

as Parameter

<parameter name="transport.vfs.ReplyFileURI">file:///home/user/test/out? transport.vfs.Append=true </parameter>
  1. vfs parameters are missing in your configuration.

For vfs service level parameters you can refer [1].

I just roughly edit your proxy try with this.

 <?xml version="1.0" encoding="UTF-8"?>
    <proxy xmlns="http://ws.apache.org/ns/synapse"
           name="FileWrite"
           transports="vfs" statistics="disable" trace="disable" startOnLoad="true">
       <description/>
       <target>
          <inSequence>
             <property name="error" expression="//error/text()" scope="default"/>
             <log level="full"/>
          </inSequence>
          <outSequence>
             <log>
 <property name="error" expression="get-property('error')" scope="default"/>
                <property name="OUT_ONLY" value="true"/>
             </log>
             <payloadFactory>
                <format>
                   <error>$1</error>
                </format>
                <args>
                   <arg expression="get-property('error')"/>
                </args>
             </payloadFactory>
             <log level="full"/>
             <send>
                <endpoint>
                   <address uri="vfs:file:///home/youtility2/Desktop/Errorlog? transport.vfs.Append=true"/>
                </endpoint>
             </send>
             <log level="full"/>
          </outSequence>
       </target>
       <parameter name="transport.PollInterval">10</parameter>
       <parameter name="transport.vfs.FileURI">file:///home/youtility2/Desktop/Errorlog.text</parameter>
       <parameter name="transport.vfs.FileNamePattern">.*.xml</parameter>
       <parameter name="transport.vfs.ContentType">text/xml</parameter>
       <parameter name="transport.vfs.ActionAfterFailure">MOVE</parameter>
    </proxy> 

[1].http://docs.wso2.org/wiki/display/ESB460/VFS+Transport




回答4:


you can also try class mediator in wso2esb.In java class Using FileWriter it is possible to write into text file like this:

FileWriter(File file, boolean append) 

or

FileWriter(String fileName, boolean append)


来源:https://stackoverflow.com/questions/15803063/how-we-can-write-a-data-in-to-text-file-using-wso2esb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!