Writing on a text file using VFS in WSO2 ESB 4.8.1

懵懂的女人 提交于 2019-12-08 05:10:05

问题


I am using VFS transport to poll a simple text file and then i send the text of a file to a queue. This flow works fine but in case of error scenario when fault sequence is executed , i want to write my error message to a simple text file and it is not Working.

Note:

I am using WSO2 ESB Version 4.8.1. I have enabled the VFS transport in my "axis2.xml" file. I have also tried all the solutions provided in this question which is related to mine.

My Service Code:

<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
       name="FileWriteTest"
       transports="vfs"
       statistics="disable"
       trace="disable"
       startOnLoad="true">
   <target>
      <inSequence>
         <log level="full"
              separator="******************FileWrite In Sequence Start*************"/>
      </inSequence>
      <outSequence/>
      <faultSequence>

         <payloadFactory media-type="xml">
            <format>
               <MessageFormat xmlns="">
                  <ECode>$1</ECode>
                  <EMsg>$2</EMsg>
                  <EDetail>$3</EDetail>
                  <EException>$4</EException>
               </MessageFormat>
            </format>
            <args>
               <arg evaluator="xml" expression="get-property('ERROR_CODE')"/>
               <arg evaluator="xml" expression="get-property('ERROR_MESSAGE')"/>
               <arg evaluator="xml" expression="get-property('ERROR_DETAIL')"/>
               <arg evaluator="xml" expression="get-property('ERROR_EXCEPTION')"/>
            </args>
         </payloadFactory>
         <property name="OUT_ONLY" value="true" scope="default" type="STRING"/>
         <property name="ClientApiNonBlocking" scope="axis2" action="remove"/>
         <send>
            <endpoint>
               <address uri="vfs:file:///home/omerkhalid/Documents/WSO2Test/FileWrite/Errorlog.txt"/>
            </endpoint>
         </send>
      </faultSequence>
      <endpoint>
         <address uri="jms:/FileWriterResponse?transport.jms.ConnectionFactoryJNDIName=QueueConnectionFactory&amp;java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory&amp;java.naming.provider.url=tcp://localhost:6616&amp;transport.jms.DestinationType=queue"/>
      </endpoint>
   </target>
   <parameter name="transport.PollInterval">10</parameter>
   <parameter name="transport.vfs.FileURI">file://home/omerkhalid/Documents/WSO2Test/FileWrite/InTest</parameter>
   <parameter name="transport.vfs.MoveAfterProcess">file://home/omerkhalid/Documents/WSO2Test/FileWrite/DoneTest</parameter>
   <parameter name="transport.vfs.FileNamePattern">.*.txt</parameter>
   <parameter name="transport.vfs.ContentType">text/plain</parameter>
   <parameter name="transport.vfs.ActionAfterFailure">MOVE</parameter>
   <parameter name="serviceType">proxy</parameter>
   <description/>
</proxy>

Problem Area:
The problem is in the following area of code, where i am defining my endpoint for Fault Sequence. It does create an file on that particular location but that file remains empty.

<send>
<endpoint>
<address uri="vfs:file:///home/omerkhalid/Documents/WSO2Test/FileWrite/Errorlog.txt"/>
</endpoint>
</send>

Exception:

org.apache.axis2.AxisFault: The system cannot infer the transport information from the file:///home/omerkhalid/Documents/WSO2Test/FileWrite/Errorlog.txt URL.
    at org.apache.axis2.description.ClientUtils.inferOutTransport(ClientUtils.java:81)
    at org.apache.axis2.client.OperationClient.prepareMessageContext(OperationClient.java:288)
    at org.apache.axis2.description.OutOnlyAxisOperationClient.executeImpl(OutOnlyAxisOperation.java:249)
    at org.apache.axis2.client.OperationClient.execute(OperationClient.java:149)
    at org.apache.synapse.core.axis2.Axis2FlexibleMEPClient.send(Axis2FlexibleMEPClient.java:482)
    at org.apache.synapse.core.axis2.Axis2Sender.sendOn(Axis2Sender.java:59)
    at org.apache.synapse.core.axis2.Axis2SynapseEnvironment.send(Axis2SynapseEnvironment.java:338)
    at org.apache.synapse.endpoints.AbstractEndpoint.send(AbstractEndpoint.java:333)
    at org.apache.synapse.endpoints.AddressEndpoint.send(AddressEndpoint.java:59)
    at org.apache.synapse.mediators.builtin.SendMediator.mediate(SendMediator.java:97)
    at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:77)
    at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:47)
    at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:131)
    at org.apache.synapse.mediators.MediatorFaultHandler.onFault(MediatorFaultHandler.java:85)
    at org.apache.synapse.FaultHandler.handleFault(FaultHandler.java:54)
    at org.apache.synapse.endpoints.AbstractEndpoint.invokeNextFaultHandler(AbstractEndpoint.java:640)
    at org.apache.synapse.endpoints.AbstractEndpoint.onFault(AbstractEndpoint.java:475)
    at org.apache.synapse.endpoints.AddressEndpoint.onFault(AddressEndpoint.java:43)
    at org.apache.synapse.FaultHandler.handleFault(FaultHandler.java:102)
    at org.apache.synapse.core.axis2.AsyncCallback.onError(AsyncCallback.java:67)
    at org.apache.axis2.engine.AxisEngine$TransportNonBlockingInvocationWorker.run(AxisEngine.java:643)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:744)

回答1:


Change your message in payloadFactory from your faultSequence : The root node of your message must be : <text xmlns="http://ws.apache.org/commons/ns/payload">

and the content of this node will be the text value sent to your file



来源:https://stackoverflow.com/questions/27856089/writing-on-a-text-file-using-vfs-in-wso2-esb-4-8-1

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