I am trying to figure out how to properly use the XML to JSON conversion in the Azure APIM Policy Editor. I've seen dozens of examples where all that's identified is this:
<xml-to-json kind="direct" apply="always" consider-accept-header="false" />
However, I cannot find the appropriate place within my policy to place the code to make it do what I'm expecting. Here is my Outbound policy, which is where I am looking to use this:
<outbound>
<base />
<choose>
<when condition="#(context.Response.StatusCode < 400)">
<set-body template="liquid">
{% if body.envelope.body.GetProjectsByQueryResponse.GetProjectsByQueryResult %}"{{body.envelope.body.GetProjectsByQueryResponse.GetProjectsByQueryResult | Replace: '\r', '\r' | Replace: '\n', '\n' | Replace: '([^\\](\\\\)*)"', '$1\"'}}"{% else %} null {% endif %}
</set-body>
</when>
<otherwise>
<set-variable name="old-body" value="#(context.Response.Body.As<string>(preserveContent: true))" />
<!-- Error response as per https://github.com/Microsoft/api-guidelines/blob/master/Guidelines.md#7102-error-condition-responses -->
<set-body template="liquid">{
"error": {
"code": "{{body.envelope.body.fault.faultcode}}",
"message": "{{body.envelope.body.fault.faultstring}}"
}
}
</set-body>
<choose>
<when condition="#(string.IsNullOrEmpty(context.Response.Body.As<JObject>(preserveContent: true)["error"]["code"].ToString()) && string.IsNullOrEmpty(context.Response.Body.As<JObject>(preserveContent: true)["error"]["message"].ToString()))">
<set-body>#{
var newResponseBody = new JObject();
newResponseBody["error"] = new JObject();
newResponseBody["error"]["code"] = "InvalidErrorResponseBody";
if (string.IsNullOrEmpty((string)context.Variables["old-body"]))
{
newResponseBody["error"]["message"] = "The error response body was not a valid SOAP error response. The response body was empty.";
}
else
{
newResponseBody["error"]["message"] = "The error response body was not a valid SOAP error response. The response body was: '" + context.Variables["old-body"] + "'.";
}
return newResponseBody.ToString();
}</set-body>
</when>
</choose>
</otherwise>
</choose>
<set-header name="Content-Type" exists-action="override">
<value>application/json</value>
</set-header>
<xml-to-json kind="direct" apply="always" consider-accept-header="false" />
</outbound>
As you can see I've tried placing the conversion line at the very end of the outbound policy, but it's not doing what I expect; I still have an xml document returned.
Any help here in understanding how to revise my policy to work would be wonderful.
Related
I am trying to connect to the emma api using ColdFusion. Using the below code. Trying to get a listing of all members in an account as per api docs doing the below. I keep getting status code of 404 on the below call. Any ideas on what I am missing here?
<cfset account_id= '123'/>
<cfset public_key = 'abc'/>
<cfset private_key = 'xyz' />
<cfset the_url = 'https://app.e2ma.net/#account_id#/members/' />
<cfhttp url="#the_url#" method="get" result="Results" timeout="999">
<cfhttpparam type="header" name="Content-Type" value="application/x-www-form-urlencoded" />
<cfhttpparam type="header" name="Accept" value="application/json" />
<cfhttpparam type="header" name="public_api_key" value="#public_key#" >
<cfhttpparam type="header" name="private_api_key" value="#private_key#" >
</cfhttp>
<cfdump var="#Results#"/>
Here are the results of the cfdump:
It looks like you're using the wrong endpoint. In their documentation they say the following:
The endpoint for all of our API calls is https://api.e2ma.net/
In your code you're using app.e2ma.net, this should be api.e2ma.net instead.
Also the path for the URL you're requesting doesn't include a trailing slash in their documentation (GET /#account_id/members is what they have). You may also want to update that.
I need receiver in message response json the new header field.After the send the new header and body to rest soapUI or client . For Manage response header and body i have modify my route whit the options bindingStyle = SimpleConsumer but now in the soapUI see only header but the body is empty . First this operation ( bindingStyle = Default ) i saw the body response but do not I saw the header .
(I'm using camel 2.12)
Who can help me ?
<route id="mainid">
<from uri="cxfrs:bean:rsServer?resourceClasses=xxxx&bindingStyle=SimpleConsumer"/>
<doTry>
<routingSlip uriDelimiter=",">
<simple>direct:${header.operationName}</simple>
</routingSlip>
<doCatch>
.....
</doCatch>
</doTry>
</route>
...
<route id="routeid">
<from uri="direct:postmethod" />
<removeHeaders pattern="Camel*" />
<to uri="jetty:{{baseUrl}}{{uri}}" />
</route>
...
How can I add tags to a blog post in IBM Connections? The API documentation says I need to update the blog post with a PUT command. If I do so according to the documentation, then I get a 500 Internal Server error as response. Same happens when trying to create a blog post with a POST command.
Question 1: what is wrong with the command?
Question 2: is there a way to only add tags without updating the content of the blog post?
sUrl = "https://my-connect-server/blogs/%BLOGID%/api/entries/%POSTID%"
sBody = "<?xml version=""1.0"" encoding=""UTF-8""?>" & _
"<entry xmlns=""http://www.w3.org/2005/Atom"">" & _
"<id>urn:lsid:ibm.com:blogs:entry-%POSTID%</id>" & _
"<title type=""text"">Test Blog Post</title>" & _
"<summary type=""html"">new summary</summary>" & _
"<content type=""html"">new content </content>" & _
"<category term=""new-tag-1""></category>" & _
"<category term=""new-tag-2""></category>" & _
"<entry>"
Call oHttp.Open("PUT", sUrl, False)
Call oHttp.setRequestHeader("Content-Type", "application/atom+xml")
Call oHttp.send(sBody)
The reason is you are not sending a full payload to the blog api. You should send back the full Blog entry with the additions/subtractions you want to make to the XML payload.
I call the api
https://<SERVER>/blogs/5133e363-7456-4525-afe6-188960888b35/api/entries/b17182a4-7807-4adf-97c7-8ac051a3f115
I had to trim off the XML header, so it's like this:
<entry xml:lang="en" dir="ltr" xmlns="http://www.w3.org/2005/Atom">
<id>urn:lsid:ibm.com:blogs:entry-b17182a4-7807-4adf-97c7-8ac051a3f115</id>
<snx:communityUuid xmlns:snx="http://www.ibm.com/xmlns/prod/sn">5133e363-7456-4525-afe6-188960888b35</snx:communityUuid>
<link href="https://<SERVER>:443/blogs/5133e363-7456-4525-afe6-188960888b35/api/entries/b17182a4-7807-4adf-97c7-8ac051a3f115" rel="edit" type="application/atom+xml">
</link>
<link href="https://<SERVER>/blogs/5133e363-7456-4525-afe6-188960888b35/entry/Test" rel="alternate" type="text/html">
</link>
<link href="https://<SERVER>:443/blogs/5133e363-7456-4525-afe6-188960888b35/feed/entrycomments/Test/atom" rel="replies" type="application/atom+xml" thr:count="0" xmlns:thr="http://purl.org/syndication/thread/1.0">
</link>
<app:collection href="https://<SERVER>:443/blogs/5133e363-7456-4525-afe6-188960888b35/api/recommend/entries/b17182a4-7807-4adf-97c7-8ac051a3f115" xmlns:app="http://www.w3.org/2007/app">
<atom:title xmlns:atom="http://www.w3.org/2005/Atom">Likes</atom:title>
<atom:category term="recommend" scheme="http://www.ibm.com/xmlns/prod/sn/collection" xmlns:atom="http://www.w3.org/2005/Atom">
</atom:category>
<app:categories fixed="yes">
</app:categories>
</app:collection>
<app:collection href="https://<SERVER>:443/blogs/5133e363-7456-4525-afe6-188960888b35/api/entrycomments/b17182a4-7807-4adf-97c7-8ac051a3f115" xmlns:app="http://www.w3.org/2007/app">
<atom:title xmlns:atom="http://www.w3.org/2005/Atom">Comment Entries</atom:title>
<app:accept>application/atom+xml;type=entry</app:accept>
<atom:category term="comments" scheme="http://www.ibm.com/xmlns/prod/sn/collection" xmlns:atom="http://www.w3.org/2005/Atom">
</atom:category>
<app:categories fixed="yes">
</app:categories>
</app:collection>
<snx:moderation status="approved" xmlns:snx="http://www.ibm.com/xmlns/prod/sn">
</snx:moderation>
<title type="text">Test</title>
<updated>2015-08-14T11:58:05.000Z</updated>
<app:edited xmlns:app="http://www.w3.org/2007/app">2015-08-14T11:58:05.000Z</app:edited>
<published>2015-08-14T11:57:44.000Z</published>
<snx:rank scheme="http://www.ibm.com/xmlns/prod/sn/recommendations" xmlns:snx="http://www.ibm.com/xmlns/prod/sn">0</snx:rank>
<snx:rank scheme="http://www.ibm.com/xmlns/prod/sn/comment" xmlns:snx="http://www.ibm.com/xmlns/prod/sn">0</snx:rank>
<snx:rank scheme="http://www.ibm.com/xmlns/prod/sn/hit" xmlns:snx="http://www.ibm.com/xmlns/prod/sn">8</snx:rank>
<author>
<name>John Doe0</name>
<snx:userid xmlns:snx="http://www.ibm.com/xmlns/prod/sn">20000395</snx:userid>
<snx:userState xmlns:snx="http://www.ibm.com/xmlns/prod/sn">active</snx:userState>
<snx:isExternal xmlns:snx="http://www.ibm.com/xmlns/prod/sn">false</snx:isExternal>
</author>
<contributor>
<name>John Doe0</name>
<snx:userid xmlns:snx="http://www.ibm.com/xmlns/prod/sn">20000395</snx:userid>
<snx:userState xmlns:snx="http://www.ibm.com/xmlns/prod/sn">active</snx:userState>
<snx:isExternal xmlns:snx="http://www.ibm.com/xmlns/prod/sn">false</snx:isExternal>
</contributor>
<category term="test">
</category>
<category term="test2">
</category>
<app:control xmlns:app="http://www.w3.org/2007/app">
<app:draft>no</app:draft>
<snx:comments enabled="yes" days="0" xmlns:snx="http://www.ibm.com/xmlns/prod/sn">
</snx:comments>
</app:control>
<summary type="html"><p dir="ltr">Test</p></summary>
<content type="html"><p dir="ltr">Test</p></content>
</entry>
I added to the category tag before
<category term="test2">
</category>
I send a put to the same api as above, with header Content-Type: application/atom+xml and Method: PUT
You should get Status Code: 200 OK
I'm working in ICIMS API. I need to return JSON data and some specific data in header in a cfm page call by ICIMS server.
Here is the response should be:
Response to the Work Flow Status Change PUSH event to the platform:
HTTP/1.1 303 See Other
Location: http://xx.xx.xx.xx:8085/selectpackage?systemHash=101
Content-Type: application/json
{
"userMessage":"Confirm or modify package.",
}
Thanks in advance.
Answer:
> <cfset contentString = '{"userMessage": "Confirm or modify package."}'
> />
>
> <cfheader name="Location"
> value="http://xx.xx.xx.xx:8085/selectpackage?systemHash=101" />
> <cfcontent type="application/json" variable="#toBinary( toBase64( contentString ) )#" />
<cfheader
statusCode = "303"
statusText = "See Other">
<cfheader
name="Location"
value="http://xx.xx.xx.xx:8085/selectpackage?systemHash=101">
<cfheader
name="Content-Type"
value="application/json">
<cfset foo = structNew()>
<cfset foo["userMessage"] = "Confirm or modify package.">
<cfoutput>#serializeJSON(foo)#</cfoutput>
Is there any way to log request from body in camel route?
<camel:log message="RequestType [${request.body.request}]" loggingLevel="INFO" />
Error in logs:
Caused by: org.apache.camel.language.simple.types.SimpleParserException: Unknown function: request.body.request
This is working part, but dunno how to get into field :
<camel:log message="RequestType ${in.body}" loggingLevel="INFO" />
<camel:log message="RequestType2 [${body}]" loggingLevel="INFO" />
Request field for sure it's not empty becaue later I'm checking it:
<camel:ognl>request.body.request instanceof ...
Try with
<camel:log message="RequestType [${body.request}]" loggingLevel="INFO" />
The camel:log is using the simple language which you can read more about here: http://camel.apache.org/simple