IBM Mobile First 7.1: multipart/related Content-Type and XSL transformation - ibm-mobilefirst

I need to invoke from an HTTP adapter a SOAP service that has a multipart/related content type.
If I use this object as WL.Server.invokeHttp parameter
{
method : 'post',
returnedContentType : 'xml',
returnedContentEncoding : 'utf-8',
path : servicePath,
body : {
content : MY_REQUEST,
contentType : "text/xml; charset=utf-8"
},
transformation: {
type: 'xslFile',
xslFile: 'myXsl.xsl'
}
};
I got this error:
"Runtime: Failed to read the HTTP response to: /MyService
\njava.lang.IllegalArgumentException: Http content type 'multipart/related' not supported.
Supported types are: [json, css, csv, javascript, plain, xml, html]"
So I modified the parameter returnedContentType: 'plain' to obtain a result. Now the response looks like this:
{
"isSuccessful": true,
"errors": [],
"warnings": [],
"info": [],
"text": "--uuid:85c87f37-9436-41d1-94d4-0b944c3618b1\nContent-Type: application/xop+xml; charset=UTF-8; type=\"text/xml\";\nContent-Transfer-Encoding: binary\nContent-ID: <root.message#cxf.apache.org>\n\n
MY SOAP RESPONSE
\n--uuid:85c87f37-9436-41d1-94d4-0b944c3618b1--",
"responseHeaders": {
...
"Content-Type": "multipart/related; type=\"application/xop+xml\"; boundary=\"uuid:85c87f37-9436-41d1-94d4-0b944c3618b1\"; start=\"<root.message#cxf.apache.org>\"; start-info=\"text/xml\""
...
}
}
But the xsl transformation is not performed.
With some string manipulation on the text parameter I can obtain the SOAP response as a string but I didn't find a way(some API) to manually invoke the XSL transformation to obtain a json.

XSL transformation is done only on the server-side (there is no manual 'activation' for it). What you could do perhaps, if you still need to do XSL transformation, is run the XSL via JavaScript. See for example: how to run XSL file using JavaScript / HTML file

Related

mail.send is not accepting HTML/ CSS code

I have copied the (HTML) source code from a received email just to have the template/format of that email, and this is the error message that I am receiveing when running the API:
Internal : Unexpected error Error during Web API HTTP Request
HTTP Status Code: 400
HTTP Response Content: {
"error": {
"code": "BadRequest",
"message": "Unable to read JSON request payload. Please ensure Content-Type header is set and payload is of valid JSON format.",
"innerError": {
"date": "2020-12-02T17:01:05",
"request-id": "3ab50fc1-0c13-4536-96db-bf6b9b7a736d",
"client-request-id": "3ab50fc1-0c13-4536-96db-bf6b9b7a736d"
}
}
}
I have tested basic commands using HTML such as making text bold and line breaks which work, but anything more complex and I will receive an error.
Update**
Thank you for your response guys, the call that I'm using looks like this:
{
"message": {
"subject": "[Subject]",
"body": {
"contentType": "HTML",
"content": "[Email Body Content]"
},
"toRecipients": [
{
"emailAddress": {
"address": "[Email Address]"
}
}
],
"internetMessageHeaders":[
{
"name":"x-custom-header-group-name",
"value":"Nevada"
},
{
"name":"x-custom-header-group-id",
"value":"NV001"
}
]
}
}
**Another update ** Upon changing the content type to text/html is recieved this error:
Internal : Unexpected error Error during Web API HTTP Request
HTTP Status Code: 415
HTTP Response Content: {"error":{"code":"RequestBodyRead","message":"A supported MIME type could not be found that matches the content type of the response. None of the supported type(s) 'Microsoft.OData.ODataMediaType, Microsoft.OData.ODataMediaTyp...' matches the content type 'text/plain; charset=utf-8'."}}
note i also have tried text/plain as the content type.
Thank you
Ok, I tried the above payload (just updated the email address) and tested with Microsoft Graph Explorer. It works for me :)
Here's the payload:
{"message":{"subject":"[Subject]","body":{"contentType":"HTML","content":"[Email Body Content]"},"toRecipients":[{"emailAddress":{"address":"test#domain.onmicrosoft.com"}}],"internetMessageHeaders":[{"name":"x-custom-header-group-name","value":"Nevada"},{"name":"x-custom-header-group-id","value":"NV001"}]}}
Here's the snapshot:

Trying to Upload .dat.gz file as as a base64 string using Jmeter http

I have to send a https rest API request through jmeter
body of the request :
{"auth":{"token":"${SessionID}"},"clientGUID":"B0DC2BE4-D744-45c6-AEF6-EBEF319A336B","taskID":"${TaskID}","chunkID":"1","chunkSize":3375134,"fileName":"${curFileTime}downloadLogsBig.dat.gz","bytes":"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"}
where XXXX is the byte array of file. Need help achieve this with the best method do this
byte[] fileContent = Files.readAllBytes(uploadFile.toPath());
uploadReq.setBytes(fileContent); --> Java to set XXXX
You can try amending your request payload as:
{
"auth": {
"token": "${SessionID}"
},
"clientGUID": "B0DC2BE4-D744-45c6-AEF6-EBEF319A336B",
"taskID": "${TaskID}",
"chunkID": "1",
"chunkSize": 3375134,
"fileName": "${curFileTime}downloadLogsBig.dat.gz",
"bytes": "${bytes}"
}
and populate the "bytes" using JSR223 PreProcessor and the following Groovy code:
vars.put('bytes', new File('jmeter.sh').bytes as String)

How to make POST request with __RequestVerificationToken header in Postman

I want to send a POST request with Postman to receive back information from a database with a list of elements.
Case:
On a Home page, I have a search engine when I'm choosing parameters. URL://example.com
I'm clicking button: Display on a list URL://example.com
I'm receiving list with searched elements URL://example.com/Search/Result
Fist Test
Method: Post
URL: example.com
Headers: Content-Type - application/json
Temporary Headers: which include : __RequestVerificationToken
Body:
{
"options": "1",
"IsMember": "false",
"ID": "2",
"btnShowList" : "true"
}
Result:
Status: 200,
But in a body I have HTML of whole home page, so probably post was not executed
Second Test
Method: Post
URL: example.com/Search/Result
Headers: Content-Type - application/json
Temporary Headers: which include : __RequestVerificationToken
Body:
{
"options": "1",
"IsMember": "false",
"ID": "2",
"btnShowList" : "true"
}
Result:
Status: 404, Not Found
Questions:
Is it possible to do the post if in URL is no query parameres?
Any idea how can I write such a test case?
Have anyone writes post method with dynamic parameters such as eg. __RequestVerificationToken
Receiving an HTML in response is totally normal, especially if the technology used is ASP.net WebForms for instance.
To answer some of your questions: It is possible to make a post with no query params. All you need to do is hit the correct url with the expected body

How to pass a file to an API from Azure Logic App

I have a simple Logic App. The trigger is on New file (ex: Dropbox, OneNote, etc.)
I want to pass the filename and the fileContent to a API APP (web Api).
But I got error, or worse the content is null once in the API!
The API is in C#.
How do you pass a file (ex: pdf, png) to and API from Logic App
UPDATE:
In Logic App here my action code:
"UploadNewFile": {
"inputs": {
"method": "post",
"queries": {
"filedata": {
"fileName":"#triggerOutputs()['headers']['x-ms-file-name']",
"fileContent":"#base64(triggerBody())"
}
},
"uri": "https://smartuseconnapiapp.azurewebsites.net/api/UploadNewFile"
},
"metadata": {
"apiDefinitionUrl": "https://smartuseconnapiapp.azurewebsites.net/swagger/docs/v1",
"swaggerSource": "website"
},
"runAfter": {},
"type": "Http"
}
In my API App, If the function is declared like this filedata is null
[Route("api/UploadNewFile")]
[HttpPost]
public HttpStatusCode UploadNewFile([FromBody] string filedata)
And if I don't add the [FromBody] like that I got an error.
[Route("api/UploadNewFile")]
[HttpPost]
public HttpStatusCode UploadNewFile(string filedata)
Yes you can send binary content to your own API in a few different methods. Our out-of-the-box actions use this as well.
If you want to send the binary contents as the request body
For example, an outgoing request from the Logic App could have binary content and a content-type header of image/png
In this case the swagger for the body of your request should be binary - or:
{ "name": "body",
"In": "body",
"Schema": {
"Type":"string",
"Format": "binary"
} ... }
That should tell the designer that the request body is binary content. If a previous action or the trigger had binary data (e.g. "When a file is added to FTP") and you used that output in the body, it would show up in your custom API inputs as:
"Body": "#triggerBody()"
Notice there are no { and } on the expression (string interpolations) which would convert the binary content to a string. This would send an outgoing request to the connector with the binary content - so your controller just needs to accept binary content and honor the content-type header as needed.
If you want to send binary content in a JSON request
Sometimes you don't want to send binary as the full request, but as a property of another object. For instance a person object may have a name, address, and profile pic all in the request body. In this case we recommend sending the binary content as base64 encdoded. You can use "format": "base64" in swagger to describe a property as this. In code-view would look something like:
"Body": {
"Name": "#triggerBody()['Name']",
"ProfilePic": "#base64(body('Dropbox'))"
}
Hope that helps. Let me know if you have any questions - here is an article on how logic apps preserves content-types as well.
I found how to to it.
I needed to pass the filename in the querystring and the file in the body of the HTTP Request. Today, it's not possible to do it using the design view so you need to go in code view.
In the Logic App code
"queries": {
"fileName": "#{triggerOutputs()['headers']['x-ms-file-name']}"
},
"body": "#triggerBody()"
In the API App code
public HttpResponseMessage UploadNewFile([FromUri] string fileName)
{
var filebytes = Request.Content.ReadAsByteArrayAsync();
[...]
}
A more detailed explanation can be found in this blog post:
http://www.frankysnotes.com/2017/03/passing-file-from-azure-logic-app-to.html

HTTP Adapter Error "Runtime: Failed to parse JSON string"

I am using IBM Worklight Studio, and trying to create HTTP Adapter which retrieve JSON object from external http server.
When I just access target http server with HTTP Get access(with browser, for example), I know their response is like following array style JSON format:
[
{ "xxx":"aaa", "yyy":"bbb", ... },
{ "xxx":"ccc", "yyy":"ddd", ... },
:
{ "xxx":"eee", "yyy":"fff", ... }
]
And I had created HTTP Adapter which would retrieve above information
var input = {
method : 'get',
returnedContentType : 'json',
path : path
};
return WL.Server.invokeHttp(input);
Now I tried to invoke this adapter with "Run As -> Invoke Worklight Procedure", then I got this error message:
{
"errors": [
"Runtime: Failed to parse JSON string\n\n[\n {\n
(raw JSON data) } ],
"info": [],
"isSuccessful": false,
"warnings": []
}
And in my log console, worklight says following error messages:
FWLSE0101E: Caused by: java.io.IOException: Expecting '{' on line 2, column 2 instead, obtained token: 'Token: ['
From above information, it seems that worklight would expect that returned JSON object need to start with "{", not "[".
Is this my guess right? Are there any workaround for this?
Thanks for advance.
Worklight knows how to handle JSON objects that start with [ (JSON arrays). In such case Worklight will return the response as:
{ "array" : [*the json array*]}
Looking at the code of the HTTP Adapter, I see that there is a bug with parsing JSON arrays that do not start with [.
I do not see a workaround for this problem, except changing the response returned from the http server.
I opened an internal bug about this, thank you for helping us find this bug.
You can change returnedContentType to "plain", this will make WL server return content as a big string and not attempt to parse it.
Then in your adapter you can use var obj = JSON.parse(response.text)