I have published a websocket api as given in the Documentation, So I wanted to call that websocket API through wso2 ESB. So, how to pass the Auth header as I'm getting the following error on the console.
[2018-10-02 18:24:36,503] ERROR - InboundWebsocketSourceHandler Endpoint not found for port : 9099 tenant domain : null
Below is the ESB to call websocket API:
<api context="/test" name="test" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="POST">
<inSequence>
<property name="OUT_ONLY" scope="default" type="STRING" value="true"/>
<log level="full">
<property name="message" value="********************************************input**********************"/>
</log>
<property name="Authorization" scope="transport" type="STRING" value="Bearer cf920eb2-960c-383c-b556-78e9258fd8d3"/>
<send>
<endpoint>
<http method="post" uri-template="ws://localhost:9099/echowebsocket/1.0"/>
</endpoint>
</send>
</inSequence>
<outSequence>
</outSequence>
<faultSequence/>
</resource>
</api>
outflow sequence:
<?xml version="1.0" encoding="UTF-8"?>
<sequence name="outflowDispatchSeq" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
<log level="full">
<property name="message" value="************************************************"/>
</log>
</sequence>
Related
I have created a API in API manager. I can invoke it with
http://localhost:6547/generatereports/1.0/Reports/dcuid/vcid
I am passing two parameters with "dcuid and vcid" at a time but not passing.
reportsapi:
<?xml version="1.0" encoding="UTF-8"?>
<api context="generatereports/1.0/Reports" name="reportsdataapi" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="GET" protocol="http" uri-template="/{dcuid}/{vcid}">
<inSequence>
<property description="http" name="HTTP_SC" scope="axis2" type="STRING" value="404"/>
<log level="full"/>
<send>
<endpoint key="reportsendpoint"/>
</send>
</inSequence>
<outSequence>
<switch source="get-property('axis2','HTTP_SC')">
<case regex="200">
<log description="200log" level="custom">
<property expression="$ctx:ERROR_CODE" name="200reserrorcode"/>
</log>
<send/>
</case>
<default>
<log description="reslog" level="custom">
<property expression="$ctx:ERROR_CODE" name="reserrorcode"/>
<property expression="$ctx:ERROR_MESSAGE" name="reserrormessage"/>
<property expression="get-property('axis2','HTTP_SC')" name="reshttpsc"/>
</log>
</default>
</switch>
<send/>
</outSequence>
<faultSequence>
<switch source="get-property('axis2','HTTP_SC')">
<case regex="200">
<log description="200log" level="custom">
<property expression="$ctx:ERROR_CODE" name="200reserrorcode"/>
</log>
</case>
<default>
<log description="reslog" level="custom">
<property expression="$ctx:ERROR_CODE" name="reserrorcode"/>
<property expression="$ctx:ERROR_MESSAGE" name="reserrormessage"/>
<property expression="get-property('axis2','HTTP_SC')" name="reshttpsc"/>
</log>
</default>
</switch>
<send/>
</faultSequence>
</resource>
</api>
wso2 configuration process with to send the response is other than 200 response code
reportsendpoint:
<?xml version="1.0" encoding="UTF-8"?>
<endpoint name="reporsendpoint" xmlns="http://ws.apache.org/ns/synapse">
<http method="get" uri-template="http://localhost:6547/generatereports/1.0/Reports/{uri.var.dcuid}/{uri.var.vcid}"/>
</endpoint>
I assume you want to send a mail if the status code is other than 200. Then you can use mailto transport or mail connectors such as gmail connector outlook connector and add the configuration in the default section in the configured switch mediator.
In wso2 ESB, I am able to send data to WebSocket but I am not able to receive data.
I tried this with rest api of wso2 esb.
<?xml version="1.0" encoding="UTF-8"?>
<api context="/test" name="test" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="POST">
<inSequence>
<property name="OUT_ONLY" scope="default" type="STRING" value="true"/>
<property name="FORCE_SC_ACCEPTED" scope="axis2" type="STRING" value="true"/>
<log level="full">
<property name="message" value="********************************************input**********************"/>
</log>
<send>
<endpoint>
<http method="post" uri-template="ws://localhost:8080/websocket/server"/>
</endpoint>
</send>
</inSequence>
<outSequence>
<send/>
</outSequence>
<faultSequence/>
</resource>
</api>
outsequence:
<?xml version="1.0" encoding="UTF-8"?>
<sequence name="outflowDispatchSeq" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
<log level="full">
<property name="message" value="************************************************"/>
</log>
</sequence>
with the above API, I am able to send data to the server as shown in below image.
Http request from postman.
But as shown in below image of the console, the response which i am getting is empty as no body present.
If I use proxy service with content-type mentioned as in esb documentation(link) in websocket server i am getting exception
<?xml version="1.0" encoding="UTF-8"?>
<sequence name="dispatchSeq" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
<property name="OUT_ONLY" value="true"/>
<property name="FORCE_SC_ACCEPTED" scope="axis2" type="STRING" value="true"/>
<property name="websocket.accept.contenType" scope="axis2" value="text/plain"/>
<send>
<endpoint>
<address uri="ws://localhost:8080/websocket/server"/>
</endpoint>
</send>
</sequence>
axis2.xml websocket configuration is:
<transportSender name="ws" class="org.wso2.carbon.websocket.transport.WebsocketTransportSender">
<parameter name="ws.outflow.dispatch.sequence" locked="false">outflowDispatchSeq</parameter>
<parameter name="ws.outflow.dispatch.fault.sequence" locked="false">outflowFaultSeq</parameter>
</transportSender>
So how to send and receive the data from websocket
I'm in an internel network and I want to create a service (ESB) to call an external get service.
for example my ESB service path: uri/esb/path/param1/param2
my external path: external/path/param1/param2
here my entry
<?xml version="1.0" encoding="UTF-8"?>
<api context="/services/KRI-getIndividualVehicleFuelco2" name="KRI-getIndividualVehicleFuelco2" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="GET">
<inSequence>
<property name="renault_error_format" scope="default" type="STRING" value="json"/>
<log level="custom">
<property name="getIndividualVehicleFuelco2" value="********** begin **********"/>
<property expression="get-property('RequestID')" name="RequestID"/>
</log>
<Delegation.DelegationIn>
<Jboss-Endpoint-Key>KRI-customAddressingTransformation.xml</Jboss-Endpoint-Key>
<Custom-Sequence-Header>KRI-commonsequences-processSpecialHeadersIn</Custom-Sequence-Header>
</Delegation.DelegationIn>
<loopback/>
</inSequence>
<outSequence>
<sequence key="KRI-commonsequences-genericErrorHandling"/>
<Delegation.DelegationOut>
<Jboss-Endpoint-Key>KRI-customAddressingTransformation.xml</Jboss-Endpoint-Key>
<Custom-Sequence-Header>KRI-commonsequences-processSpecialHeadersOut</Custom-Sequence-Header>
</Delegation.DelegationOut>
<log level="custom">
<property name="getIndividualVehicleFuelco2" value="********** end **********"/>
<property expression="get-property('RequestID')" name="RequestID"/>
</log>
</outSequence>
<faultSequence>
<loopback/>
</faultSequence>
</resource>
</api>
I created an endpoint with the base uri of the external service.
<?xml version="1.0" encoding="UTF-8"?>
<endpoint name="KIS-fuelco-PPD" xmlns="http://ws.apache.org/ns/synapse">
<address uri="http://kisre701.intra.com/kis/api/v2/individual-vehicle-fuelco2/"/>
</endpoint>
how can I parse parameters and send them to endpoint?
I am new to the WSO2 esb. I want to create a api in which i want to add a dynamic parameter from api Url to endpoint url.
My end point url is like http://example.com/api/sync/{session_id}.json
I tried to create api like
<api name="rest" context="/sync">
<resource methods="GET" uri-template="/{id}">
<inSequence>
<log level="full">
<property xmlns:ns="http://org.apache.synapse/xsd"
name="uri.var.session"
expression="get-property('uri.var.id')"
scope="axis2"/>
</log>
<property name="REST_URL_POSTFIX" scope="axis2" action="remove"/>
<send>
<endpoint name="Mecars">
<http trace="enable"
method="get"
uri-template="http://example.com/sync/{+uri.var.session}.json"/>
</endpoint>
</send>
</inSequence>
</resource>
</api>
In log i get the value of uri.var.session But on the endpoint Uri-template it is not appending.
Please guid me how append the {id} value in the api uri-template to end point uri-template?
Check this sample
I recommend you to do string concatenation at property mediator adn use that directly at uri-template, rather adding "variable +.json" at uri-template.
That is;
<property xmlns:ns="http://org.apache.synapse/xsd"
name="uri.var.session"
expression="get-property('uri.var.id')"
scope="axis2"/>
In the above for expression do string concatenation to construct full variable with ".json" ending.
Please remove the '+' symbol from your http end point.Its working fine to me
sample API
<api xmlns="http://ws.apache.org/ns/synapse" name="Elastic Search Using NPI" context="/api/npi/professional/npi.json">
<resource methods="OPTIONS GET" uri-template="/{npi}">
<inSequence>
<log level="full">
<property name="uri.var.npi" expression="get-property('uri.var.npi')"></property>
</log>
<send>
<endpoint>
<http method="get" uri-template="example.com/{uri.var.npi}"></http>
</endpoint>
</send>
</inSequence>
</resource>
</api>
Change the http endpoint uri template like follows.
<http trace="enable" method="get" uri-template="http://example.com/sync/{uri.var.id}.json"></http>
Following is the modified api configuration.
<api xmlns="http://ws.apache.org/ns/synapse" name="rest" context="/sync">
<resource methods="GET" uri-template="/{id}">
<inSequence>
<log level="full">
<property xmlns:ns="http://org.apache.synapse/xsd" name="uri.var.session" expression="get-property('uri.var.id')"></property>
</log>
<property name="REST_URL_POSTFIX" scope="axis2" action="remove"></property>
<send>
<endpoint name="Mecars">
<http trace="enable" method="get" uri-template="http://example.com/sync/{uri.var.id}.json"></http>
</endpoint>
</send>
</inSequence>
</resource>
</api>
You can do the string concatenation at the property mediator as follows.
<property xmlns:ns="http://org.apache.synapse/xsd"
name="uri.var.session"
expression="fn:concat(get-property('uri.var.id'),'.json')"
scope="axis2"/>
My aim is i have to receive the url's like www.google.com from client in proxy service and send response back to client.
How can i solve this.Here i am sending my proxy service.
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="Geturl"
transports="https http"
startOnLoad="true"
trace="enable"
statistics="enable">
<description/>
<target>
<inSequence onError="fault">
<property name="RESPONSE" value="true" scope="default" type="STRING"/>
<property name="REQUEST_HOST_HEADER" value="www.google.com" scope="axis2"/>
<property name="querystrings"
expression="get-property('axis2', 'REST_URL_POSTFIX')"/>
<property name="REST_URL_POSTFIX"
expression="get-property('REQUEST_HOST_HEADER')"
scope="axis2"
type="STRING"/>
<property name="HTTP_METHOD" value="GET" scope="axis2" type="STRING"/>
<header name="To"
expression="get-property('www.google.com')"/>
<property name="message" value="Response message"/>
<property name="Sender Address" expression="get-property('www.google.com')"/>
<log level="full"/>
<log level="full">
<property name="REQUEST_HOST_HEADER" value="www.wso2.org"/>
</log>
<send/>
</inSequence>
<outSequence onError="fault">
<log level="full"/>
<log level="full">
<property name="REQUEST_HOST_HEADER" value="www.google.com"/>
</log>
<log level="full">
<property name="success" value="success"/>
</log>
<send/>
</outSequence>
</target>
</proxy>
Thanks
In the outSequence of a proxy service, when you call <send/> , the response will be sent back to the client. Try sample proxy service [1], and invoke using Try-It or SOAP UI. You will see that the response comming to the client.
[1]http://docs.wso2.org/wiki/display/ESB460/Sample+150%3A+Introduction+to+Proxy+Services