How do we decode $content?
My content:
When I simply do this:
I get this:
I've also tried this:
body('Get_blob_content')['$content']
that didn't work either:
another attempt:
base64ToString(body('Get_blob_content')['$content']):
How do we decode $content?
I agree with George Chen, the solution is decodeBase64(body('Get_blob_content')), but you check if the content is a valid json in String format, if not, try to add string function:
decodeBase64(string(body('Get_blob_content'))).
Regards.
Related
I am passing a JSON array object in the HTTP POST as
[{"level":"INFO","data": "Test 1"},{"level":"INFO","data": "Test 2"}]
This message is seen as 1 object/log message in SumoLogic. How can I tell SumoLogic to consider each JSON object as an independent object and show 2 log messages instead of one?
I believe this can't be done with the json operator. But, have a look at the docs for the "parse regex" operator. There's an option called "multi" which creates a new message for each match of the regex. In your case, something like this might do the trick:
parse regex "\{?<fieldname>.*?\}" multi
I didn't try this in the product itself, but here is Regex101 link to play with the regex.
I believe the actual answer to this is to not send your logs as an array. Instead include each json object in your body with a '\n' at the end for Sumo to consider these as individual log messages.
{"level":"INFO","data": "Test 1"}\n
{"level":"INFO","data": "Test 2"}\n
How to find the file type whether it is an image or ppt or pdf from Base64 string.
How can i decode that string and also get the file extension of Base64 String.
It should be in AngularJs.
If the string was obtained by FileReader.readAsDataURL() (see https://developer.mozilla.org/en-US/docs/Web/API/FileReader/readAsDataURL) it should be similar to this one:
"data:image/jpeg;base64,/9j/4AAQSkZJRgABAgAAAQABAAD/2wBDAAgGBgcGBQg ... "
So the first part is the MIME_TYPE (data:image/jpeg;), then there's a delimitator (base64,) and finally the base64 string which can be decoded using a library like this one:
https://github.com/ninjatronic/angular-base64
I would like to achieve something like below:
from("direct:dataload")
.beanRef("headerUpdater")
.log("Log: " + simple("${in.header.contentType}").getText())
//.unmarshal().beanio(simple("${in.header.contentType}").getText(), "content")
.unmarshal(new BeanIODataFormat(
"file://C://Users//admr229//Documents//mappings.xml", "clients"))
.to("bean:headerFooterValidator")
.split(body())
.process(dataValidator).choice()
.when(header("error").isNotNull())
.to("seda:saveErrorsForReport").otherwise()
.to("seda:updateLive")
.end();
I have commented out the line which I cannot make. I wanted to pass dynamic values from previous endpoint's output to initialize beanio.
Only thing I can think of is using recipient list which will dynamically choose a predefined endpoint. Because, for my case, that endpoint will have unmarshall with beanio, unlike something like "activemq:queue:test", which is purely text.
I hope I have made my question clear. Please let me know if you need any further details.
I am using camel 2.15.2
You can use the data format component [1] where you can specify beanio as the data format, and build the uri dynamic [2]
[1] - http://camel.apache.org/dataformat-component.html
[2] - http://camel.apache.org/how-to-use-a-dynamic-uri-in-to.html
you can use do something like this but, again this not dynamic I guess as it need to have properties set before brining up the context.
.unmarshal().beanio(mapping, streamName)
I am a new guy for JSON, I don't know to send JSON object and Array...
But, I pass the JSON values like the below format,
object.put("code", "1");
object.put("message", "Success");
object.put("Name", "xxx");
object.put("F_Name","yyy");
object.put("Address", "zzz");
object.put("Phone_No","123");
out.println(object);
But it display like
{"Phone_No":"123","message":"Success","Address":"zzz","Name":"xxx","F_Name":"yyy","code":"1"}
I don't know, why it's display like this. How to order this? Please help me.
And this is what format, Array format or object format...
And tell how to send array values in JSON..
Thanks in advance..
You didn't write what is the class of the object. However, if you care about the order, use GSON and its JsonObject class:
import com.google.gson.Gson;
import com.google.gson.JsonObject;
JsonObject object = new JsonObject();
object.addProperty("code", "1");
object.addProperty("message", "success");
object.addProperty("Name", "xxx");
// ...
Gson gson = new Gson();
out.println(gson.toJson(object));
As my understanding of question and the code above, The "object" you already using might be json object. Usually JSON object can maintain data in the form of key, value pairs. So you are putting content into json object and displaying. That's why its getting displayed like that. The displayed format is json format. If you want to put array into json object you can put as you already did for normal strings.
object.put("array1", arrayvariable1[]);
object.put("array2", arrayvariable2[]);
I guess it might have helped you.
I'm having content which encoded in base 64 format already. I want to set content in Mimemessage in object as if the content is in base64 format. Is there any method available for this? Please provide solution.
http://javamail.kenai.com/nonav/javadocs/javax/mail/internet/PreencodedMimeBodyPart.html