How to call webservice in WSO2 proxy - wso2

how I can call web service inside of proxy? Proxy itself works fine, and I added call of logging web service in "in" sequence. I create call using payload factory + send.
Problem is, that proxy now returns result of this logging web service instead of
what web service should return. There is address end point defined in "out" sequence.
I am using WSO2 ESB 4.6.0.

This is the simple example of calling web service inside of the proxy. You need to up back-end service before create the proxy
<proxy xmlns="http://ws.apache.org/ns/synapse" name="customPro" transports="https,http" statistics="disable" trace="disable" startOnLoad="true">
<target>
<inSequence>
<send>
<endpoint>
<address uri="http://localhost:9000/services/SimpleStockQuoteService"/>
</endpoint>
</send>
</inSequence>
<out-sequence>
<send/>
</outSequence>
</target>
<publishWSDL uri="http://localhost:9000/services/SimpleStockQuoteService?wsdl"/>
<description></description>
</proxy>
You need to define web service url within the end-point in tag
As well as, this kind of send mediator return end-point response to outSequence
by default.
You can get good understanding of these if you go through the ESB documentation from following url
http://docs.wso2.org/display/ESB460/Samples
If you need further help, feel free to ask here

There are two ways you can achieve the logs
1. Log ESB incoming and outgoing messages through wire log.
To enable debug mode for wire logs;
- ESB console > Configure > Logging
- Set “org.apache.synapse.transport.http.wire” level to “DEBUG”.
In the log, it indicates >> incoming messages to ESB
<< outgoing messages from ESB
2. Use Logs at the appropriate place
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="TestProxy"
transports="https,http"
statistics="disable"
trace="disable"
startOnLoad="true">
<target>
<inSequence>
<log level="full">
<property name="test" value="incomming to ESB-----------------------"/>
</log>
<send>
<endpoint>
<address uri="http://localhost:9000/services/SimpleStockQuoteService"/>
</endpoint>
</send>
<log level="full">
<property name="test" value="outcomming from ESB-----------------------"/>
</log>
</inSequence>
<outSequence>
<log level="full">
<property name="test" value="incomming to ESB-----------------------"/>
</log>
<send/>
<log level="full">
<property name="test" value="outcomming from ESB-----------------------"/>
</log>
</outSequence>
</target>
<publishWSDL uri="http://localhost:9000/services/SimpleStockQuoteService?wsdl"/>
<description/>
</proxy>
If it is resolve your problem, please flag as answered.

Related

javax.naming.NameNotFoundException: Name [dynamicQueues/myqueue] is not bound in this Context. Unable to find [dynamicQueues]

I've created JMS sender in WSO2 ESB 4.9.0 as below and configured JMS sender in axis2.xml file. I'm getting the below exception when I run the proxy service. Using Websphere MQ JMS queues.
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="StockQuoteProxy"
transports="http"
statistics="disable"
trace="disable"
startOnLoad="true">
<target>
<inSequence>
<property name="OUT_ONLY" value="true"/>
<send>
<endpoint>
<address uri="jms:/myquue?transport.jms.ConnectionFactory=ConnectionFactory"/>
</endpoint>
</send>
</inSequence>
<outSequence>
<send/>
</outSequence>
</target>
<description/>
</proxy>
javax.naming.NameNotFoundException: Name [dynamicQueues/myqueue] is not bound in this Context. Unable to find [dynamicQueues]
In my scenario using the WSO2 MB, the correct endpoint it´s this:
<address uri="jms:/MyQueue?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"/>
Your proxy config use:
<property name="OUT_ONLY" value="true"/>
So, no response is sent to the client.
You need to specify a WSDL in the proxy config with an operation that does not have a response message or return a status = 200 with:
<property name="FORCE_SC_ACCEPTED" value="true" scope="axis2"/>

WSO2 ESB Proxy Basic Service Chaining

this is what I thought would be a fairly straight-forward service chaining scenario.
All I want to do it forward some data to a proxy service, that proxy service will then iterate over the data and use an ID ("entity_id") from that data (which it can successfully retrieve) to look up a resource sitting in WSO2 Data Services Server. Once it has the result of that request, I want to forward it to another application (RequestBin, in this case).
Please take a look at my proxy configuration below:
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="pollService"
transports="https,http"
statistics="disable"
trace="disable"
startOnLoad="true">
<target>
<inSequence>
<log level="full"/>
<iterate id="iter1"
expression="//*[local-name()='Change']"
sequential="true">
<target sequence="anon">
<sequence>
<log level="full"/>
<property name="uri.var.entityid" expression="//*[local-name()='entity_id']"/>
<call>
<endpoint>
<http method="get"
uri-template="http://54.66.155.36:9764/services/civicrm/activity/{uri.var.entityid}"/>
</endpoint>
</call>
<log level="full"/>
<call>
<endpoint>
<http method="post" uri-template="http://requestb.in/1c79v711"/>
</endpoint>
</call>
<log level="full"/>
</sequence>
</target>
</iterate>
</inSequence>
</target>
<description/>
</proxy>
I currently do not get any indication that those two calls have fired at all.
Any assistance would be greatly appreciated.
Thank you.
you can enable the wirelog and verify whether calls have fired or not.
please refer the following blog post to learn about wirelog.
1 http://mytecheye.blogspot.in/2013/09/wso2-esb-all-about-wire-logs.html
Could you also give a sample message (what is going into the proxy) , and to see a finer-grain detail of what is going on in your proxy , go into [esb-home]/repository/conf/ and open the log4j.properties file , and set
log4j.category.org.apache.synapse=DEBUG , also do as #robin suggested. Try putting
<log level="full" category="DEBUG" separator="-----:-----"/>
in your proxy where you want to see the state of the message at that point.

How to call RestFullService using Proxyservice in wso2

I have created a Resful WebApplication and upload it in wso2 as a Restful Service
I want to call this RestFul Service using a proxy service in wso,Is it possible
While doing this ,i am not able to get the response
Below is my Proxy Service configuration
<?xml version="1.0" encoding="UTF-8"?><proxy xmlns="http://ws.apache.org/ns/synapse" name="ProxyService" transports="https,http" statistics="disable" trace="disable" startOnLoad="true">
<target>
<outSequence>
<send/>
</outSequence>
<endpoint>
<http method="get" uri-template="http://10.132.97.131:9763/JerseyJSONExample/rest/jsonServices/print/mahi/"/>
</endpoint>
</target>
<description/>
But while calling this proxy service,i am not able to get the response
If i am simply calling the service
http://10.132.97.131:9763/JerseyJSONExample/rest/jsonServices/print/mahi/
I am getting the response...
Can anyone help me on this what actually is the problem
You can use the following configuration to call a restful service from proxy service
<inSequence>
<property name="HTTP_METHOD" value="GET" scope="axis2" type="STRING"/>
<send>
<endpoint>
<address uri="http://10.132.97.131:9763/JerseyJSONExample/rest/jsonServices/print/mahi/"
format="pox"/></endpoint>
</send>
</inSequence>
More information can be find here

WSO2 ESB: header loss (SamplingProcessor)

I'm trying to send a message through WSO2 ESB 4.6.0 using MessageProcessor:
Proxy->Proxy(Store)->Processor->Sequence->Proxy
I set a property ('transport' scope) in Proxy #1, send it to Proxy #2 where I can successfully log it, but then I pass the message to Proxy #3 through Sampling Processor and the property is getting lost.
Is this a bug? How can I send 'transport' property via Processor?
I expect value_1 to appear instead of null in Proxy_3.
<messageProcessor name="Processor_1" class="org.apache.synapse.message.processors.sampler.SamplingProcessor" messageStore="Store_1" xmlns="http://ws.apache.org/ns/synapse">
<parameter name="interval">1000</parameter>
<parameter name="sequence">Sequence_1</parameter>
</messageProcessor>
MessageStore
Store_1 is InMemoryMessageStore
Proxy_1
<proxy xmlns="http://ws.apache.org/ns/synapse" name="Proxy_1" transports="jms" statistics="disable" trace="disable" startOnLoad="true">
<target>
<inSequence>
<property name="my_property_1" value="value_1" scope="transport"/>
</inSequence>
<outSequence>
<send/>
</outSequence>
<faultSequence/>
<endpoint>
<address uri="http://localhost:8280/services/Proxy_2" format="soap11" />
</endpoint>
</target>
<parameter name="transport.jms.Destination">Queue</parameter>
</proxy>
Proxy_2
<proxy xmlns="http://ws.apache.org/ns/synapse" name="Proxy_2" transports="https,http" statistics="disable" trace="disable" startOnLoad="true">
<target>
<inSequence>
<property name="preserveProcessedHeaders" value="true"/>
<log level="custom" separator=",">
<property name="my_property_1" expression="get-property('transport', 'my_property_1')"/>
</log>
<store messageStore="Store_1"/>
</inSequence>
</target>
</proxy>
Sequence_1
<sequence xmlns="http://ws.apache.org/ns/synapse" name="Sequence_1">
<send>
<endpoint>
<address uri="http://localhost:8280/services/Proxy_3" format="soap11"/>
</endpoint>
</send>
</sequence>
Proxy_3
<proxy xmlns="http://ws.apache.org/ns/synapse" name="Proxy_3" transports="https,http" statistics="disable" trace="disable" startOnLoad="true">
<target>
<inSequence>
<log level="custom">
<property name="my_property_1" expression="get-property('transport', 'my_property_1')"/>
</log>
<send/>
</inSequence>
</target>
</proxy>
Transport properties are passed as HTTP headers. But when you store a message in a queue, it only stores what's available in the message payload, with a content type set to XML. There's no standard way to persist all the custom HTTP header information when saving the message to a queue. You have to enhance the existing message store/processor implementation take account of this additional headers. However, an easier solution would be before storing the message to the queue use enrich mediator to set the header value as a payload element in the message. Then from your proxy, before sending, extract it and create a custom header and send.
As chintana said you have to add it to the payload if you use ESB 4.6.0 or 4.7.0. But we have already fix this to keep the header values when we store the message in the store. It will come with next release.

ESB doesn't return anything from the GET service failing with NPE

I've configured a proxy service to run some XSBRL validation stuff that accepts a get request amd return XML validation results. Here's proxy service configuration:
<proxy xmlns="http://ws.apache.org/ns/synapse" name="XBRLValidationRESTService" transports="https,http" statistics="disable" trace="disable" startOnLoad="true">
<target>
<inSequence>
<log level="full"/>
<property name="REST_URL_POSTFIX" value="/example.xbrl/validation/xbrl?media=xml" scope="axis2"/>
<property name="HTTP_METHOD" value="GET" scope="axis2"/>
<send>
<endpoint>
<address uri="http://localhost:10000/rest/xbrl" format="pox"/>
</endpoint>
</send>
</inSequence>
<outSequence>
<log level="full"/>
<send/>
</outSequence>
</target>
<description></description>
</proxy>
In the log file I can see that the underlying service responds with expected response, however the client receives nothing back because ESB fails with NPE for some reason.
Request used from localhost:
curl -k https://localhost:9443/services/XBRLValidationRESTService
Full log: http://pastebin.com/A5jB9wMF
What is the potential reason for that and how that could be fixed.
Thanks,
Vladimir.
Do you run ESB with blocking transport? By default esb uses NIO transport and the port is 8280. your proxy service url, will be;
http://localhost:8280/services/XBRLValidationRESTService
Rather putting log full state, use descriptive logs to identify message paths,