XML Request from strong-soap - node.js

I am using strong-soap, and it is working well.
How do I locate the request and response XML that strong-soap has generated?
I would like to review and possibly log the XML, so that I can use the converted XML while testing the WSDL directly.

It may be late, but for people that may have the same problem in the future, here is how you can log your inbound and outbound requests in XML format:
server = soap.listen(...)
server.log = function(type, data) {
// type is 'received' or 'replied'
// data is the xml sent or received
};
References: strong-soap Github repo

Related

INVALID_CONTENT_HASH error using Bittex API v3

I'm using Bittrex API v3. My header setup as below:
body = {
"marketSymbol":"BTC-USD",
"direction":"SELL",
"type":"LIMIT",
"quantity":"0.6",
"limit":"6000",
"timeInForce":"IMMEDIATE_OR_CANCEL"
}
var contentHash = CryptoJS.SHA512(JSON.stringify(body)).toString(CryptoJS.enc.Hex)
But I get INVALID_CONTENT_HASH.
If anyone can solve this problem, please let me know as soon as possible.
The v3 API is expecting the content to be hashed as json (which you're doing) but the payload must also be POSTed as json with the Content-Type accordingly set to application/json.
I ran into the same problem with the json being converted to a querystring on POST.

How to represent this xml syntax as an object for node soap

I am trying to consume a soap web service, it works with soap ui but when I use node soap, it does not. I believe the problem is coming from sending a wrong body. This is the body that is to be sent to the web service and this works on soap ui.
<arg0><![CDATA[<C24TRANREQ><PROCESSING_CODE>07</PROCESSING_CODE>
<DR_ACCT_NUM>0711201711</DR_ACCT_NUM><TRAN_CRNCY_CODE>KSD</TRAN_CRNCY_CODE>
</C24TRANREQ> ]]></arg0>
In the object for node-soap, I simply send this below as the args object
const args = {
PROCESSING_CODE: 07,
TRAN_CRNCY_CODE: "KSD",
DR_ACCT_NUM: 0711201711
}
I want to believe my empty response is coming from not including arg0 and C24TRANREQ in my node-soap object. How do I include this?
Also are the numbers to be javascript strings or just numbers?

AWS Lambda fails to return PDF file

I have created a lambda function using serverless. This function is fired via API Gateway on a GET request and should return a pdf file from a buffer. I'm using html-pdf to create the buffer and trying to return the pdf file with the following command
let response = {
statusCode: 200,
headers: {'Content-type' : 'application/pdf'},
body: buffer.toString('base64'),
isBase64Encoded : true,
};
return callback(null, response);
but the browser is just failing to load the pdf, so I don't know exactly how to return the pdf file directly to the browser. Could'nt find a solution for that.
well, I found the answer.
The settings in my response object are fine, I just had to manually change the settings in API Gateway for this to work in the browser. I have added "*/*" to binary media types under the binary settings in API Gateway console
API GATEWAY
just log into your console
choose your api
click on binary support in the dropdown
edit binary media type and add "*/*"
FRONTEND
opening the api url in new tab (target="_blank"). Probably the browser is handling the encoded base 64 response, In my case with chrome, the browser just opens the pdf in a new tab exactly like I want it to do.
After spending several hours on this I found out that if you set Content handling to Convert to binary (CONVERT_TO_BINARY) the entire response has to be base64, I would otherwise get an error: Unable to base64 decode the body.
Therefore my response now looks like:
callback(null, buffer.toString('base64'));
The Integration response:
The Method response:
And Binary Media Types:
If you have a gigantic PDF, then it will take a long time for Lambda to return it and in Lambda you are billed per 100ms.
I would save it to S3 first then let the Lambda return the S3 url to the client for downloading.
I was having a similar issue where pdf where downloaded as base64 and started happening when changed the serverles.yml file from:
binaryMediaTypes:
- '*/*'
to
binaryMediaTypes:
- 'application/pdf'
- '....other media types'
The issue is because the way AWS implemented this feature. From aws documentation here:
When a request contains multiple media types in its Accept header, API
Gateway honors only the first Accept media type. If you can't control
the order of the Accept media types and the media type of your binary
content isn't the first in the list, add the first Accept media type
in the binaryMediaTypes list of your API. API Gateway handles all
content types in this list as binary.
Basically if the first media type contained in the accept request header is not in your list in binaryMediaTypes then you will get base64 back.
I checked the request in the browser and the first media type in the accept header was text/html so I got it working after changing my settings to:
binaryMediaTypes:
- 'application/pdf'
- '....other media types'
- 'text/html'
Hope this helps anyone with the same issue.
Above solution is only for particular content-type. You can't more content type.
Follow only below two-step to resolve multiple content type issue.
Click on the checkbox of Use Lambda Proxy integration
API gateway --> API --> method --> integration request
Create your response as
let response = {
statusCode: 200,
headers: {
'Content-type': 'application/pdf',//you can change any content type
'content-disposition': 'attachment; filename=test.pdf' // key of success
},
body: buffer.toString('base64'),
isBase64Encoded: true
};
return response;
Note* - It is not secure
Instead of doing all this. It's better to use serverless-apigw-binary plugin in your serverless.yaml file.
Add
plugins:
- serverless-apigw-binary
custom:
apigwBinary:
types:
- "application/pdf"
Hope that will help someone.

How to Convert MS SharePoint $metadata XML Response into Standard Odata JSON in NodeJS?

I am working on MS SharePoint 2013 integration and in my use case I want to work on JSON data only.
I am able to convert all the API XML responses like File, Folder, List, ListItem, etc into OData JSON using Node Module - datajs_vanilla, but I am not able to convert https://mysite/_api/$metadata into OData JSON.
I am getting below error while executing datajs for $metadata endpoint:
error:{"message":"no handler for data"}
Below is my code snippet:
OData.read({
requestUri: 'https://example.com/_api/$metadata',
headers: {
'Authorization': 'Bearer token_value',
'Accept':'application/xml;charset=utf-8'
}
}, function (data, response) {
console.log("Operation succeeded."+JSON.stringify(data));
}, function (err) {
console.log("Error occurred " + JSON.stringify(err));
});
I am missing something here to convert into JSON?
or
Could you please suggest me possible solution to convert edmx sharepoint $metadata XML response into OData JSON using node module?
Thanks.
See answer for similar question Get OData $metadata in JSON format .
Metadata document is not defined using OData atom/xml format that's why datajs vanilla is failing to parse it.
Metadata format is CSDL format. Example of metadata doc - http://services.odata.org/V4/TripPinServiceRW/$metadata.
Usually metadata used for discovery and client generation since it has type info and all entity relations. Having service responses being serialized to json and service documentation in json should be sufficient for you to work with service.

Sharepoint soap request MTOM

So we have a requirement to upload file to sharepoint server using iOS client . We are able to upload file size till 40kb but the problem is the file data we are passing is in Base64 encoding,and it fails for file size more than 40kb because we cannot pass large data in soap message,so we tried different approaches possible and mentioned on web . These are the ways we tried out
and we are left with only sending data using MTOM .
After lots of experiments and search I think MTOM is a way to upload data using soap . We are using CopyIntoItems sharepoint service for upload .
Soap request looks like
<"xmlns:soap12=\"http://schemas.xmlsoap.org/soap/envelope/\">\n"
"<soap12:Body>\n"
"<CopyIntoItems xmlns=\"http://schemas.microsoft.com/sharepoint/soap/\">\n"
"<SourceUrl>%#</SourceUrl>\n"
"<DestinationUrls>\n"
"<string>%#</string>\n"
"</DestinationUrls>\n"
"<Fields>\n"
"%#"
"</Fields>\n"
"<Stream>MY_FILE_DATA</Stream>\n"
"</CopyIntoItems>\n"
"</soap12:Body>\n"
"</soap12:Envelope>\n"
Now the problem is how do we format this soap request in the way MTOM accepts,because CopyIntoItems may not work in some other format.
Few samples of MTOM which i looked into
http://pic.dhe.ibm.com/infocenter/wasinfo/v6r1/index.jsp?topic=/com.ibm.websphere.wsfep.multiplatform.doc/info/ae/ae/cwbs_soapmtom.html
http://cxf.apache.org/docs/mtom.html
Any help would be much appreciated..Thanks..!!
What about using HTTP post and developing an Http handler to store posted data?
It is quite easy to setup an http handler in Sharepoint (MSDN) and in the Process request method you can use query string to get the information you need.
Say you create an Upload.ashx handler.
public void ProcessRequest(HttpContext context)
{
var targetList = context.Request["targetList"];
var targetFileName = context.Request["targetFn"];
// Get the stream to content
var stream = context.Request.GetBufferedInputStream();
// Save the file somewhere
}
From the client you do an HTTP post to http://server/_layouts/15/Upload.ashx?targetList=myFiles&...

Resources