I have defined an API Resource in WSO2 ESB like this with GET method:
/sms/{username}/{password}/{src}/{destination}/{body}
Now if I invoke my API through a standard browser like chrome or firefox it works fine and I get response code ok 200
127.x.x.x:8280/sms/username/password/123123123/456456456/سلام
But I can not invoke this API through Postman and it returns Not-Found 404. If I replace 'سلام' with a standard ascii string like 'hello' it works fine and it returns code ok 200:
127.x.x.x:8280/sms/username/password/123123123/456456456/hello
I tried numerous Content-Types in Headers tab of postman including this but it didn't work:
text/html; charset=UTF-8
I also monitored network requests with fiddler. Standard browser send request with this parameters:
Connection: keep-alive Upgrade-Insecure-Requests: 1 User-Agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML,
like Gecko) Chrome/70.0.3538.77 Safari/537.36 Accept:
text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,/;q=0.8
Accept-Encoding: gzip, deflate Accept-Language: en-US,en;q=0.9
And Postman send request with this parameters:
Content-Type: text/html; charset=UTF-8 cache-control: no-cache
Postman-Token: 5ccc574f-54d2-4c5b-ac72-b0f5f5a8e0be User-Agent:
PostmanRuntime/7.3.0 Accept: /
accept-encoding: gzip, deflate Connection: keep-alive
I use postman v6.4.4
You need to manually encode parts of the URL.
Try this https://stackoverflow.com/a/49964318/9624430
I tried this issue with WSO2 ESB 5.0.0. It works for me as you expected through postman.
<api xmlns="http://ws.apache.org/ns/synapse" name="test-api" context="/test">
<resource methods="GET" uri-template="/value/{val1}">
<inSequence>
<log level="full">
<property name="test" expression="get-property('uri.var.val1')"/>
</log>
<payloadFactory media-type="json">
<format>{ "test": "$1"}</format>
<args>
<arg evaluator="xml" expression="get-property('uri.var.val1')"/>
</args>
</payloadFactory>
<respond/>
</inSequence>
<outSequence>
<send/>
</outSequence>
</resource>
</api>
Request: http://localhost:8280/test/value/سلام
Response:
{
"test": "سلام"
}
Try with WSO2 ESB 5.0.0.
Related
I have an issue which I do not have an idea how to resolve it. I am on WSB2 ESB 4.9.0.
I am trying to call a topic through a proxy using an event. However this never call the proxy subscribed to it.
<?xml version="1.0" encoding="UTF-8"?>
<proxy name="publishSubscribeTest" startOnLoad="true" trace="disable"
transports="http https" xmlns="http://ws.apache.org/ns/synapse">
<target>
<inSequence>
<log level="custom">
<property value="********************* START METHOD *********************" name="publishSubscribeTest"/>
</log>
<event topic="TestTopic"/>
<log level="custom">
<property value="********************* END METHOD *********************" name="publishSubscribeTest"/>
</log>
</inSequence>
<outSequence>
<drop/>
</outSequence>
<faultSequence/>
</target>
</proxy>
The topic has the following details:
Topic Name: TestTopic
Permissions Details: (Everyone has permission to subscribe and publish)
WS Subscription Details: Another custom proxy in WSO2 has been configured as WS Subscription Details.
So when first proxy calls the topic, it should call the proxy subscribed to that topic. However it is never called.
This is the proxy called by topic:
<?xml version="1.0" encoding="UTF-8"?>
<proxy name="proxyCalledByTopic" startOnLoad="true" trace="disable"
transports="https http" xmlns="http://ws.apache.org/ns/synapse">
<target>
<inSequence>
<log level="custom">
<property value="********************* START METHOD *********************" name="proxyCalledByTopic"/>
</log>
</inSequence>
<outSequence>
<send/>
</outSequence>
<faultSequence/>
</target>
</proxy>
So the log should be something like:
publishSubscribeTest = ********************* END METHOD
********************* proxyCalledByTopic = ********************* START METHOD ********************* publishSubscribeTest =
********************* START METHOD *********************
However it is like:
publishSubscribeTest = ********************* END METHOD
********************* publishSubscribeTest = ********************* START METHOD *********************
So I understand that the proxy called by the topic in the subscription is not called.
Any suggestion? Any help?
After some try outs, the issue why the pub sub was not triggering the event was due to the fact that content-type header needs was not populated appropriately from the incoming request to the proxy service. The same can be achieved from setting up an POST api.
Once the content-type header is populated with either of the below values, the pub/sub events started working.
Content-Type: application/json
Content-Type: application/xml
Sample Posts:
XML
POST /TriggerTopic HTTP/1.1
Host: 10.224.234.34:8280
Content-Type: application/xml
Cache-Control: no-cache
Postman-Token: f60c206c-a38e-ed2d-46a0-b051304247be
<?xml version="1.0" encoding="UTF-8"?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Dont forget me this weekend from postman via API</body>
</note>
Sample Post JSON
POST /TriggerTopic HTTP/1.1
Host: 10.224.234.34:8280
Content-Type: application/json
Cache-Control: no-cache
Postman-Token: 3453ddc5-a279-203a-fecf-38e81bd3ba8b
{"value":"some value"}
I want to invoke a BPS process from CEP through SOAP method, but got an exception in BPS side.
the event output formatter such as:
<?xml version="1.0" encoding="UTF-8"?>
<eventFormatter name="output_formatter" statistics="disable"
trace="enable" xmlns="http://wso2.org/carbon/eventformatter">
<from streamName="output" version="1.0.0"/>
<mapping customMapping="enable" type="xml">
<inline>
<TestEchoRequest>
<input>{{meta_output}}</input>
</TestEchoRequest>
</inline>
</mapping>
<to eventAdaptorName="outputadapter" eventAdaptorType="soap">
<property name="headers">SOAPAction:"http://wso2.org/bps/sample/process" </property>
<property name="username">admin#carbon.super</property>
<property name="password">admin</property>
<property name="url">http://192.168.20.213:9767/services/TestEcho/</property>
</to>
</eventFormatter>
but from the view of Enter Event Formatter Details, the headers property was mismatch to the XML version, lost the bottom half of "SOAPAction".
if fire the event from Event Stream Simulator, the BPS got an exception:
TID[-1234] [BPS] [2015-08-27 09:51:08,064] ERROR {org.apache.axis2.engine.AxisEngine} - The endpoint reference (EPR) for the Operation not found is http://192.168.11.250:9767/services/TestEcho/ and the WSA Action = . If this EPR was previously reachable, please contact the server administrator.
the message sent by CEP is just like this, it seems that the SOAPAction header is lost:
POST / HTTP/1.1
Content-Type: text/xml; charset=UTF-8
SOAPAction: ""
User-Agent: Axis2
Host: 192.168.20.213:9767
Transfer-Encoding: chunked
400
<?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Header><wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" soapenv:mustUnderstand="1"><wsu:Timestamp xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="Timestamp-71"><wsu:Created>2015-08-28T05:14:09.554Z</wsu:Created><wsu:Expires>2015-08-28T05:19:09.554Z</wsu:Expires></wsu:Timestamp><wsse:UsernameToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="UsernameToken-72"><wsse:Username>admin</wsse:Username><wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">admin</wsse:Password></wsse:UsernameToken></wsse:Security></soapenv:Header><soapenv:Body><event xmlns="http://wso2.org/carbon/event"><metaData><im>AAAAAAA</im></metaData></event></soapenv:Body></soapenv:Envelope>
0
Is it a bug or any suggestion ?
Above is a known issue in WSO2 CEP 3.1.0, see [1].. As a workaround can you call the soap12 endpoint of TestEcho service because SOAPAction property is optional in soap12 (Add complete url with soap12 endpoint for url property)..
example,
http://192.168.20.213:9767/services/TestEcho.TestEchoHttpsSoap12Endpoint/
[1] https://wso2.org/jira/browse/CEP-1108
What does Envelope refer to in this soap request?
OST /InStock HTTP/1.1 Host: www.example.org Content-Type: application/soap+xml; charset=utf-8 Content-Length: nnn
<?xml version="1.0"?> <soap:Envelope xmlns:soap="http://www.w3.org/2001/12/soap-envelope" soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">
<soap:Body xmlns:m="http://www.example.org/stock"> <m:GetStockPrice>
<m:StockName>IBM</m:StockName> </m:GetStockPrice> </soap:Body>
</soap:Envelope>
I have this SOAP response:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<ConversionRateResponse xmlns="http://www.webserviceX.NET/">
<ConversionRateResult>0.1492</ConversionRateResult>
</ConversionRateResponse>
</soap:Body>
and I want to get the value:
0.1492
How do I state this using xpath?
My SoapUI response as 'raw' is:
HTTP/1.1 200 OK
Cache-Control: private, max-age=0
Content-Type: text/xml; charset=utf-8
Content-Encoding: gzip
Vary: Accept-Encoding
Server: Microsoft-IIS/7.0
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Fri, 31 Oct 2014 19:43:54 GMT
Content-Length: 316
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><ConversionRateResponse xmlns="http://www.webserviceX.NET/"><ConversionRateResult>0.1482</ConversionRateResult></ConversionRateResponse></soap:Body></soap:Envelope>
In pure XPath, trivially:
//ConversionRateResult/text()
But since XPath is usually embedded into a higher-level language like Java or XSLT, you might as well need (an XSLT example):
<xsl:template match="ConversionRateResult">
<xsl:value-of select="."/>
</xsl:template>
I am using Coldfusion9 to interact with a 3rd party SOAP service with which I need to both send and receive SOAP with attachments. I am having no issue in receiving the SOAP which may or may not have binary attachments by using ToString() around the HTTP content to convert the SOAP Body into a usable string, however the service requires that I send my response back using attachments as well which is where I am coming undone. I've just never done this in ColdFusion and i'm not exactly sure how I should be presenting this to the originating service so that the SOAP body is referenced via an ID.
Below is the parsing of the incoming SOAP data with attachments:
<cfset soapData = GetHttpRequestData()>
<!--- Loop over the HTTP headers and dump the SOAP content into a variable --->
<cfsavecontent variable="soapContent">
<cfoutput>
<cfloop collection = #soapData.headers# item = "http_item">
#http_item#: #StructFind(soapData.headers, http_item)# #chr(10)##chr(13)#
</cfloop>
request_method: #soapData.method# #chr(10)##chr(13)#
server_protocol: #soapData.protocol# #chr(10)##chr(13)#
http_content --- #chr(10)##chr(13)#
#toString(soapData.content)#
</cfoutput>
</cfsavecontent>
<!--- Save file to flat file --->
<cffile action = "write"
file = "#expandPath('../')#logs/#dateFormat(now(),'dd-mm-yyyy')#_#timeFormat(now(),'HHmmss')#.txt"
output = "#soapContent#">
Now I am currently presenting the response as a full SOAP XML response containing the body as inline XML with the required STATUSCODE (see below).
<cfsavecontent variable="strResponse">
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAPENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/1999/XMLSchema" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance">
<SOAPENV:Body>
<ns1:processResponse xmlns:ns1="urn:TripFlow" SOAPENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<STATUSLVL>00</STATUSLVL>
</ns1:processResponse>
</SOAP-ENV:Body>
</SOAPENV:Envelope>
</cfsavecontent>
<!--- Strip all whitespace between tags --->
<cfset strResponse = trim(ReReplaceNoCase(strResponse,'(>[\s]*<)','><','ALL'))>
<!--- Output the XML response to the soap service --->
<cfoutput>#strResponse#</cfoutput>
The above response is throwing an error because the SOAP service requires the response to be sent referencing the body message as an attachment exactly like follows from the documentation:
HTTP/1.1 200 OK
Date: Thu, 01 Apr 2010 09:30:25 GMT
Server: Jetty/5.1.4 (Windows XP/5.1 x86 java/1.5.0_15
Content-Type: multipart/related; boundary=soaptestserver; type="text/xml"; start="<theenvelope>"
SOAPAction: ""
Content-Length: 796
Connection: close
--soaptestserver
Content-ID: <theenvelope>
Content-Transfer-Encoding: 8bit
Content-Type: text/xml; charset=utf-8
Content-Length: 442
<?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope xmlns:SOAPENV="
http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/1999/XMLSchema"
xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"><SOAPENV:
Body><ns1:processResponse xmlns:ns1="urn:TripFlow" SOAPENV:
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><message
href="cid:thecontentmessage"/></ns1:processResponse></SOAP-ENV:Body></SOAPENV:
Envelope>
--soaptestserver
SOAP Interface
www.travelsolutions.com 123
travel solutions online V14.0 External System Integration
Content-ID: <thecontentmessage>
Content-Transfer-Encoding: 8bit
Content-Type: text/xml; charset=utf-8
Content-Length: 65
<?xml version="1.0" encoding="UTF-8"?><STATUSLVL>00</STATUSLVL>
--soaptestserver--
Any help would be greatly appreciate as i'm really hitting my head up against a wall on this one. Thanks!
It has been a while since I worked with ColdFusion. The last I remember, it did not provide a harness to send a SOAP attachment. I solved this issue by writing a custom CFX tag with Java that did it for me. The entire SOAP call will need to go through the tag.
The Java library you want to look at if you choose to do this is javax-ws. You also need to find out if the service call has to use MTOM.
Sorry that is not a direct solution, but it is what I had to do with CF a few versions back.
Whenever I interact with SOAP services I usually end up using something similar to this. It generally works. Notice that I have some place-holder text in there that you would need to replace with the appropriate values for your 3rd party provider.
<cfsavecontent variable="soap">
<?xml version="1.0" encoding="UTF-8" ?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/1999/XMLSchema" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance">
<soapenv:Header/>
<soapenv:Body>
<ns1:processResponse xmlns:ns1="urn:TripFlow" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<statuslvl>00</statuslvl>
</ns1:processResponse>
</soapenv:Body>
</soapenv:Envelope>
</cfsavecontent>
<!--- Invoke web service to send message--->
<cfhttp url="http://3rd-party-url-here" method="post" timeout="10">
<cfhttpparam type="header" name="content-type" value="text/xml" />
<cfhttpparam type="header" name="SOAPAction" value="""3rd-party-method-name-here""" />
<!---<cfhttpparam type="header" name="accept-encoding" value="no-compression" /> sometimes this is needed --->
<cfhttpparam type="header" name="content-length" value="#len(soap)#" />
<cfhttpparam type="header" name="charset" value="utf-8" />
<cfhttpparam type="xml" name="message" value="#trim(soap)#" />
</cfhttp>