I am getting Errors while JMS consuming in wso2esb - wso2

I am using wso2esb4.7.0 and ActiveMQ5.8.0 http://docs.wso2.org/display/ESB470/ESB+as+a+JMS+Producer and http://docs.wso2.org/display/ESB470/ESB+as+a+JMS+Consumer
according to the document i have done my messages are passing well to queue.Even storing also well .While conuming the messages in to the queue Wso2esb giving issues like formats
ERROR - JMSMessageReceiver Unknown error processing message
org.apache.axiom.om.OMException: com.ctc.wstx.exc.WstxUnexpectedCharException: Unexpected character '{' (code 123) in prolog; expected '<'
at [row,col {unknown-source}]: [1,1]
why this happening is there any message format issue i am passing just sample json like
curl -v -H "Accept: application/json" -H "Content-Type:application/json" -H "ModifiedOn:0" -H "username:vikaash|21405735755158656" -H "password:gbin" -d '{"name":"youtility tech","mail":"faisal.shaik#youtility.in"}' http://youtility2-desktop:8282/services/JmsStore
how we can send response to client
http://stackoverflow.com/questions/18440789/how-to-give-a-response-to-client-using-wso2esb-jmsqueue

Reason for this is, if you haven't specifically configure JMS Proxy to accept messages in a particular message format, it will always treat messages are in the text/xml format.
So when you send the message in application/json format you will get this exception while building the message. So if you want to accept messages in json format from a JMS queue you have to define 'transport.jms.ContentType' parameter as follows in the proxy service configuration.
<parameter name="transport.jms.ContentType">
<rules>
<jmsProperty>contentType</jmsProperty>
<default>application/json</default>
</rules>
</parameter>
Following is a sample proxy configuration.
<proxy name="StockQuoteProxy" transports="jms">
<target>
<inSequence>
<property action="set" name="OUT_ONLY" value="true"/>
</inSequence>
<endpoint>
<address uri="http://localhost:9000/services/SimpleStockQuoteService"/>
</endpoint>
<outSequence>
<send/>
</outSequence>
</target>
<publishWSDL uri="file:repository/samples/resources/proxy/sample_proxy_1.wsdl"/>
<parameter name="transport.jms.ContentType">
<rules>
<jmsProperty>contentType</jmsProperty>
<default>application/json</default>
</rules>
</parameter>
</proxy>

Related

Error while building Passthrough stream First Element must contain the local name, Envelope , but found alerts

Scenario
I've created a proxy service which calls an endpoint. The endpoints gives XML response. I'm using Foreach Mediator to iterate through the XML response using the defined XPath expression. Finally, each record will be inserted to the database using the DB Report Mediator.
Proxy Service
<?xml version="1.0" encoding="UTF-8"?>
<proxy name="alertsIoscoProxy" startOnLoad="true" statistics="enable" trace="enable" transports="http https" xmlns="http://ws.apache.org/ns/synapse">
<target>
<inSequence>
<send>
<endpoint>
<address uri="https://www.XXXXXX/investor_protection/investor_alerts/xml-feed">
<suspendOnFailure>
<initialDuration>-1</initialDuration>
<progressionFactor>1</progressionFactor>
</suspendOnFailure>
<markForSuspension>
<retriesBeforeSuspension>0</retriesBeforeSuspension>
</markForSuspension>
</address>
</endpoint>
</send>
</inSequence>
<outSequence>
<foreach expression="//alerts/alert" id="foreach_alert">
<sequence>
<dbreport>
<connection>
<pool>
<driver>org.postgresql.Driver</driver>
<url>jdbc:postgresql://localhost:5432/postgres</url>
<user>postgres</user>
<password>admin</password>
</pool>
</connection>
<statement>
<sql><![CDATA[insert into IOSCO_RESPONSE (ID, DATE_POSTED, COMPANY,REGULATOR, JURISDICTION, LINK, SUBJECT) values (?,?,?,?,?,?,?)]]></sql>
<parameter expression="//id" type="VARCHAR" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"/>
<parameter expression="//datePosted" type="VARCHAR" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"/>
<parameter expression="//company" type="VARCHAR" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"/>
<parameter expression="//regulator" type="VARCHAR" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"/>
<parameter expression="//jurisdiction" type="VARCHAR" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"/>
<parameter expression="//link" type="VARCHAR" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"/>
<parameter expression="//subject" type="VARCHAR" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"/>
</statement>
</dbreport>
</sequence>
</foreach>
<log level="custom">
<property name="add" value="Records added!!!!"/>
</log>
<sequence key="Lookup"/>
<respond/>
</outSequence>
<faultSequence/>
</target>
</proxy>
Sample XML
<alerts>
<message>Results are capped at 500 records.</message>
<alert>
<id>23091</id>
<datePosted>20221209</datePosted>
<company>Trado Banco</company>
<regulator>Financial Conduct Authority</regulator>
<jurisdiction>United Kingdom</jurisdiction>
<link>https://www.fca.org.uk/news/warnings/trado-banco</link>
<subject>Regarding fraudulent or manipulative practices (insider dealing, market manipulation, misrepresentation of material information, etc.)<br /><br />Regarding registration of issuance, offer or sale of securities/derivatives, and reporting requirements<br /><br />Regarding market intermediaries (investment and trading advisers, collective investment schemes, brokers, dealers, and transfer agents)<br /><br />Regarding markets, exchanges, and clearing and settlement entities<br /><br />Miscellaneous</subject>
<comments/>
<attachments/>
</alert>
.
.
.
</alerts>
Error
[2022-12-13 23:42:55,323] INFO {TRACE_LOGGER} - {proxy:alertsIoscoProxy} Proxy Service alertsIoscoProxy received a new message...
[2022-12-13 23:42:55,323] INFO {TRACE_LOGGER} - {proxy:alertsIoscoProxy} Message To: null
[2022-12-13 23:42:55,323] INFO {TRACE_LOGGER} - {proxy:alertsIoscoProxy} SOAPAction: null
[2022-12-13 23:42:55,323] INFO {TRACE_LOGGER} - {proxy:alertsIoscoProxy} WSA-Action: null
[2022-12-13 23:42:55,324] INFO {TRACE_LOGGER} - Setting specified anonymous fault-sequence for proxy
[2022-12-13 23:42:55,324] INFO {TRACE_LOGGER} - {proxy:alertsIoscoProxy} Using the anonymous in-sequence of the proxy service for mediation
[2022-12-13 23:42:55,878] INFO {TRACE_LOGGER} - Setting specified anonymous fault-sequence for proxy
[2022-12-13 23:42:57,175] ERROR {RelayUtils} - Error while building Passthrough stream org.apache.axiom.soap.SOAPProcessingException: First Element must contain the local name, Envelope , but found alerts
at org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder.constructNode(StAXSOAPModelBuilder.java:305)
at org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder.createOMElement(StAXSOAPModelBuilder.java:252)
at org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder.createNextOMElement(StAXSOAPModelBuilder.java:234)
at org.apache.axiom.om.impl.builder.StAXOMBuilder.next(StAXOMBuilder.java:249)
at org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder.getSOAPEnvelope(StAXSOAPModelBuilder.java:204)
at org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder.<init>(StAXSOAPModelBuilder.java:154)
at org.apache.axiom.om.impl.AbstractOMMetaFactory.createStAXSOAPModelBuilder(AbstractOMMetaFactory.java:73)
at org.apache.axiom.om.impl.AbstractOMMetaFactory.createSOAPModelBuilder(AbstractOMMetaFactory.java:79)
at org.apache.axiom.om.OMXMLBuilderFactory.createSOAPModelBuilder(OMXMLBuilderFactory.java:196)
at org.apache.axis2.builder.SOAPBuilder.processDocument(SOAPBuilder.java:65)
at org.apache.synapse.transport.passthru.util.DeferredMessageBuilder.getDocument(DeferredMessageBuilder.java:153)
at org.apache.synapse.transport.passthru.util.RelayUtils.buildMessage(RelayUtils.java:169)
at org.apache.synapse.transport.passthru.util.RelayUtils.buildMessage(RelayUtils.java:122)
at org.apache.synapse.transport.util.PassThroughMessageHandler.buildMessage(PassThroughMessageHandler.java:103)
at org.apache.synapse.mediators.AbstractListMediator.buildMessage(AbstractListMediator.java:155)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:96)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:72)
at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:158)
at org.apache.synapse.core.axis2.Axis2SynapseEnvironment.injectMessage(Axis2SynapseEnvironment.java:377)
at org.apache.synapse.core.axis2.SynapseCallbackReceiver.handleMessage(SynapseCallbackReceiver.java:627)
at org.apache.synapse.core.axis2.SynapseCallbackReceiver.receive(SynapseCallbackReceiver.java:208)
at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:180)
at org.apache.synapse.transport.passthru.ClientWorker.run(ClientWorker.java:298)
at org.apache.axis2.transport.base.threads.NativeWorkerPool$1.run(NativeWorkerPool.java:172)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:834)
Question
Why proxy Service is considering the response as Soap while its HTTP response with xml based formatting? How could I solve this issue?
One reason for this issue is, your response coming from https://www.XXXXXX/investor_protection/investor_alerts/xml-feed maybe having the Content-Type set to text/xml which is by default considered as a SOAP message and built with the SOAPMessageBuilder. If you can change the backend to send application/xml as the content type this would resolve the issue. Else you will have to change the Message Builder configurations to build text/xml messages with ApplicationXMLBuilder. For that you need to add the following to the deployment.toml.
[[custom_message_builders]]
content_type = "text/xml"
class="org.apache.axis2.builder.ApplicationXMLBuilder"
Note that this will affect all the SOAP 1.1 calls as well, which use text/xml content type. To avoid this you can create a custom message builder as well. More details are on the aforementioned doc.

WSO2 guaranteed delivery message In memory store

Trying to make workable solution for guaranteed delivery In memory.
Create InMemoryStore InMemMessageStore, create and point InsertInvoice
create API so code looking like this :
Sequence:
<?xml version="1.0" encoding="UTF-8"?> <sequence name="InMMSsequence" xmlns="http://ws.apache.org/ns/synapse">
<log level="custom">
<property name="STATE" value="message is sent to InMemMessageStore"/>
</log>
<property name="FORCE_SC_ACCEPTED" scope="axis2" type="STRING" value="True"/>
<axis2ns12:store messageStore="InMemMessageStore" xmlns:axis2ns12="http://ws.apache.org/ns/synapse"/> </sequence>
my API looks like :
<resource methods="POST" uri-template="/sendMessage">
<inSequence>
<sequence key="InMMSsequence"/>
</inSequence>
<outSequence/>
<faultSequence/>
</resource>
Message Processor :
<messageProcessor name="MySMessageProcessor" class="org.apache.synapse.message.processor.impl.forwarder.ScheduledMessageForwardingProcessor" targetEndpoint="InsertInvoice" messageStore="InMemMessageStore" xmlns="http://ws.apache.org/ns/synapse">
<parameter name="interval">1000</parameter>
<parameter name="client.retry.interval">1000</parameter>
<parameter name="max.delivery.attempts">4</parameter>
<parameter name="is.active">true</parameter>
<parameter name="max.delivery.drop">Disabled</parameter>
<parameter name="member.count">1</parameter>
</messageProcessor>
And point :
<endpoint xmlns="http://ws.apache.org/ns/synapse"
name="InsertInvoice">
<http uri-template="http://xxxx.xxx.xxx.xxx/InsertInvoiceVehicleList"
method="post">
<suspendOnFailure>
<progressionFactor>1.0</progressionFactor>
</suspendOnFailure>
<markForSuspension>
<retriesBeforeSuspension>0</retriesBeforeSuspension>
<retryDelay>0</retryDelay>
</markForSuspension> </http> </endpoint>
PROBLEMS:
over PostMan I'm sending the request in JSON format but when I open InMemMessageStore message is in XML ?!? Why?
Endpoint expecting message in JSON format. Probably this is the reason of failure BUT on log I see something like
Failed to send the message through the fault sequence. Sequence name does not Exist.
Is the fault sequence mandatory or it is complaining because I don't have any default error sequence defines at all ?
also
Unable to sendViaPost to url[http://xxx.xxx.xx.xx/InsertInvoiceVehicleList/sendMessage]
Why the 'sendMessage' (This is uritemplate that is defined in API is added on endpoint url ?!?!)
so : Biggest issue here is how to keep message in JSON format and how to keep endpoint url intact ...
I found the problem and I wanted to share it with others ...
1. call end point from API adds postfix on end gives the error
By default, URI template 'sendMessage' will get appended to the target URL when sending messages out. You need to use following property in your sequence to remove URI template from target URL
<property action="remove" name="REST_URL_POSTFIX" scope="axis2"/>.
2. message processor fails to send message to end point
My end point was api .net web service and issue was with HTTP 1.1 chunking,had to disable it since .NET service doesn’t support it.
This setting is in axis2_blocking_client.xml and axis2_client.xml
<parameter name="Transfer-Encoding">chunked</parameter>
3. message processor fails to send message to end point
my seccond End point was servicestack web service and I used end point like
http://xxxx.xxx.xxx.xxx/TMSALSvc/UpdateStatus
but problem was that I needed to specify the reponce format. Once when I put a EndPoint delaration like
http://xxx.xxx.xxx.xx/TMSALSvc/json/reply/UpdateStatus
everything forked
I hope that this can same some times for other facing the same issues

How to send wso2 esb error message or exception to my client

I provoke an error in wso2ESB in order to have control in the client of some errors, while the esb console displays:
ERROR {org.wso2.carbon.identity.entitlement.mediator.EntitlementMediator} - Error occurred while evaluating the policy {org.wso2.carbon.identity.entitlement.mediator.EntitlementMediator}
org.apache.axis2.AxisFault: Access Denied. Authentication failed - Invalid credentials provided.
...
...
the client console displays:
org.apache.axiom.soap.SOAPProcessingException: Transport level information does not match with SOAP Message namespace URI
I'm seeing different errors in consoles, I need to take the esb error message so that the client code can catch the same error esb
At this moment i have my sequence 'fault' configured like this:
<sequence xmlns="http://ws.apache.org/ns/synapse" name="fault" trace="enable">
<makefault version="soap12">
<code xmlns:soap12Env="http://www.w3.org/2003/05/soap-envelope" value="soap12Env:Receiver"/>
<reason xmlns:ns="http://org.apache.synapse/xsd" expression="get-property('ERROR_MESSAGE')"/>
</makefault>
<send/>
</sequence>
and a sequence in sequence to my proxy service configured like this:
<sequence xmlns="http://ws.apache.org/ns/synapse" name="InSequence" trace="enable">
<entitlementService remoteServiceUrl="https://localhost:9443/services/" remoteServiceUserName="srxxx" remoteServicePassword="kiytr">
<onReject/>
<onAccept/>
<advice/>
<obligations/>
</entitlementService>
<header xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" name="wsse:Security" action="remove"/>
<send/>
<drop/>
</sequence>
I've tried several ways to get the error in my client without success if anyone can help me I would appreciate so much
Configure a faultSequence inside your proxy service as shown in below. In your case you have to use the fault mediator inside the faultSequence.
<faultSequence>
<makefault version="soap12">
<code xmlns:soap12Env="http://www.w3.org/2003/05/soap-envelope" value="soap12Env:Receiver"/>
<reason xmlns:ns="http://org.apache.synapse/xsd" expression="get-property('ERROR_MESSAGE')"/>
</makefault>
<send/>
</faultSequence>
For more information needed for sending the error message to the client use following documentations
[1] http://docs.wso2.org/wiki/display/ESB460/Error+Handling+and+Error+Codes
[2] http://docs.wso2.org/wiki/display/ESB460/Fault+Mediator

Can we store a string in a text file in wso2esb?

I have a text file on my local system I wish to append the data in particular file as synchronously.
I have tried many ways, but it's not working.
ESB has this future in Oracle SOA. We can add in FILE ADAPTER. In ESB it's neither giving errors nor expected result.
My configuration is like this:
<proxy xmlns="http://ws.apache.org/ns/synapse" name="FileWrite" transports="http,vfs" statistics="disable" trace="disable" startOnLoad="true">
<target>
<inSequence>
<log>
<property name="OUT_ONLY" value="true"/>
</log>
</inSequence>
<outSequence>
<log>
<property name="OUT_ONLY" value="true"/>
</log>
<payloadFactory>
<format>
<error>error404</error>
</format>
</payloadFactory>
<send>
<endpoint>
<address uri="vfs:file:///home/youtility2/Desktop/Errorlog"/>
</endpoint>
</send>
</outSequence>
</target>
<parameter name="transport.vfs.ReplyFileURI">file:///home/user/test/out? transport.vfs.Append=true</parameter>
<parameter name="transport.PollInterval">10</parameter>
<parameter name="transport.vfs.FileNamePattern">Errorlog.text</parameter>
<parameter name="transport.vfs.ContentType">text/xml</parameter>
<parameter name="transport.vfs.ActionAfterFailure">MOVE</parameter>
<parameter name="transport.vfs.ReplyFileName">Errorlog.xml</parameter>
<description></description>
</proxy>
Actually I kept a log mediator in outSequence. The inSequence mediator is not sending the data in to the outSequence process not forwarding into outSequence. That's why I think that the above configuration is not working.
Any reference for this?
I tried above configuration in inSequence also. It's giving errors like this:
ERROR - Axis2Sender Unexpected error during sending message out
org.apache.axis2.AxisFault:
The VFS transport doesn't support synchronous responses. Please use
the appropriate (out only) message exchange pattern
Please refer to this link.
The issue is, you are setting a property inside a log mediator which is a predefined property, (ie:OUT_ONLY) which is used to indicate the request is only the "out-only" request. So, system, wont expect the response back. That is why, you are not getting anything in your outsequence.
DO NOT USE the predefined properties in the Log mediator,which will cause issues.
Keep some text in the log meditaor to indictae the flow of the message.
eg:
<inSequence>
<log>
<property name="INSEQUENCEEEEEEE" value="********"/>
</log>
</inSequence>
Like wise keep different descriptive log in the outsequence and see whether you are getting the message there, without any issue.

Scheduled Message Forwarding Processor does not deactivate after X delivery attempts

I'm running WSO2 ESB 4.5.1 with Sun Java SE 1.6.0_33 on Red Hat 2.6.32 using Apache ActiveMQ 5.5.1 as persistent storage to the ESB.
I’m trying to write a flow that:
1. reads address information from XML file
2. save each address in MQ queue
3. have a Message Processor read from MQ and attempt delivery to a JMS Endpoint
4. if the delivery fails the Message Processor is to attempt one more delivery before deactivating itself
When the JMS Endpoint (another ActiveMQ instance running on another server) is up everything works great, but if I stop the ActiveMQ that is acting as the JMS Endpoint the Message Processor does not deactivate as I expect after one retry but continually attempts to resend the same messages from Message Store. What is going wrong?
Here is the flow I have:
Proxy:
<proxy xmlns="http://ws.apache.org/ns/synapse" name="AddressPxy" transports="vfs" statistics="disable" trace="disable" startOnLoad="true">
<target>
<inSequence>
<property name="OUT_ONLY" value="true" scope="default" type="STRING"/>
<property name="target.endpoint" value="AddressesEP" scope="default" type="STRING"/>
<log level="full"/>
<iterate expression="//addresses/address">
<target>
<sequence>
<store messageStore="AddressesMS"/>
</sequence>
</target>
</iterate>
</inSequence>
</target>
<parameter name="transport.vfs.ActionAfterProcess">MOVE</parameter>
<parameter name="transport.PollInterval">15</parameter>
<parameter name="transport.vfs.MoveAfterProcess">file:///home/esb/sent</parameter>
<parameter name="transport.vfs.FileURI">file:///home/esb/addresses.xml</parameter>
<parameter name="transport.vfs.MoveAfterFailure">file:///home/esb/fail</parameter>
<parameter name="transport.vfs.ContentType">application/xml</parameter>
<parameter name="transport.vfs.ActionAfterFailure">MOVE</parameter>
<description></description>
</proxy>
Message Store:
<messageStore name="AddressesMS" class="org.wso2.carbon.message.store.persistence.jms.JMSMessageStore" xmlns="http://ws.apache.org/ns/synapse">
<parameter name="java.naming.factory.initial">org.apache.activemq.jndi.ActiveMQInitialContextFactory</parameter>
<parameter name="java.naming.provider.url">tcp://localhost:61616</parameter>
<parameter name="store.jms.JMSSpecVersion">1.1</parameter>
<parameter name="store.jms.cache.connection">false</parameter>
</messageStore>
Message Processor:
<messageProcessor name="AddressesMP" class="org.apache.synapse.message.processors.forward.ScheduledMessageForwardingProcessor" messageStore="AddressesMS" xmlns="http://ws.apache.org/ns/synapse">
<parameter name="interval">10000</parameter>
<parameter name="max.delivery.attempts">1</parameter>
</messageProcessor>
Endpoint:
<endpoint xmlns="http://ws.apache.org/ns/synapse" name="AddressesEP">
<address uri="jms:/Addresses?transport.jms.ConnectionFactoryJNDIName=QueueConnectionFactory&java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory&java.naming.provider.url=tcp://rhdev001:61616&transport.jms.DestinationType=queue">
</address>
</endpoint>
I see this error message in wso2carbon.log:
TID: [0] [ESB] [2012-11-07 02:58:07,396] ERROR {org.apache.axis2.transport.jms.JMSSender} - Unable to create a JMSMessageSender for : null {org.apache.axis2.transport.jms.JMSSender}
javax.jms.JMSException: Could not connect to broker URL: tcp://rhdev001:61616. Reason: java.net.ConnectException: Connection refused
TID: [0] [ESB] [2012-11-07 02:58:07,398] ERROR {org.apache.synapse.message.processors.forward.BlockingMessageSender} - Error sending Message to url : jms:/Addresses?transport.jms.ConnectionFactoryJNDIName=QueueConnectionFactory&java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory&java.naming.provider.url=tcp://rhdev001:61616&transport.jms.DestinationType=queue {org.apache.synapse.message.processors.forward.BlockingMessageSender}
org.apache.axis2.AxisFault: Unable to create a JMSMessageSender for : null
TID: [0] [ESB] [2012-11-07 02:58:07,399] ERROR {org.apache.synapse.message.processors.forward.ForwardingJob} - Error Forwarding Message {org.apache.synapse.message.processors.forward.ForwardingJob}
java.lang.Exception: Error while Sending Message
Hope someone can help me!
In this version of ESB There is a slight problem with "max.delivery.attempts" parameter in the message processor. But you can make this work by going to source view and changing "max.delivery.attempts" to "max.deliver.attempts".