"Conversion to base64Binary failed" Error using MapForce to POST to Web Service - map-force

In Altova MapForce, when sending XML to the Body of an HTTP POST (a Web Service call) through a mime-entity function, it generates an error "Conversion to base64Binary failed for '<?xml...'". How do I send XML from a string into a web service call Body connector without generating that error?

The mime-entity function expects binary data which is Base64-encoded. That encoding can be performed using the charset-encode function with a suitable encoding such as "utf-8".

Related

Azure Service Bus interoperability between Apache Camel based producer and .NET consumer

we're trying to build an event-based integration between an Apache Camel based system with produces messages in an Azure Service Bus topic and an .NET based consumer of these messages.
The producer used the AMQP interface of the Service Bus, while the .NET based consumer uses the current API from Microsoft in namespace Azure.Messaging.ServiceBus.
When we try to access the body in a received message as follows:
private async Task ProcessMessagesAsync(ProcessMessageEventArgs args)
{
try {
message = Encoding.UTF8.GetString(args.Message.Body);
}
catch( Exception e)
{
_logger.LogError(e, "Body not decoded: Message: {#message}", e.Message);
}
_logger.LogInformation("Body Type: {#bodytype}, Content-Type: {#contenttype}, Message: {#message}, Properties: {#properties}", raw.Body.BodyType, args.Message.ContentType, message, args.Message.ApplicationProperties);
await args.CompleteMessageAsync(args.Message);
}
the following exception is raised:
Value cannot be retrieved using the Body property.Use GetRawAmqpMessage to access the underlying Amqp Message object.
System.NotSupportedException: Value cannot be retrieved using the Body property.Use GetRawAmqpMessage to access the underlying Amqp Message object.
at Azure.Messaging.ServiceBus.Amqp.AmqpMessageExtensions.GetBody(AmqpAnnotatedMessage message)
at Azure.Messaging.ServiceBus.ServiceBusReceivedMessage.get_Body()
When peeking the topic with service bus explorer the message looks strange:
#string3http://schemas.microsoft.com/2003/10/Serialization/�_{"metadata":{"version":"1.0.0","message_id":"AGHcNehoD-hK0pPJCSga9v9sXFwC","message_timestamp":"2022-01-10T13:34:32.778Z"},"data":{"source_timestamp":"2022-01-05T17:20:31.000","material":"101052"}}
When messages are sent to another topic with a .NET producer there's a plaintext JSON body in the topic, as expected.
Did anybody successfully build a solution with Azure Service Bus with components based on the two mentioned frameworks, and what did the trick so that interoperability did work? Who can a Camel AMQP producer create messages with a BodyType of Data so that the body can be decoded by the .NET Service Bus client libraries without need to use GetRawAmqpMessage?
I can't speak to what format Camel is using, but that error message indicates that the Body that you're trying to decode is not an AMQP data body, which is what the Service Bus client library uses and expects.
In order to read a body that is encoded as an AMQP value or sequence, you'll need to work with the data in AMQP format rather than by using the ServiceBusReceivedMessage convenience layer. To do so, you'll want to call GetRawAmqpMessage on the ServiceBusReceivedMessage, which will give you back an AmqpAnnotatedMessage.
The annotated message Body property will return an AmqpMessageBody instance which will allow you to query the BodyType and retrieve the data in its native format using one of the TryGetmethods on the AmqpMessageBody.
On our procuder side a SAP Cloud Integration is used, when the Message Type parapeter of the AMQP Adapter is set to Binary, according to:
https://help.sap.com/viewer/368c481cd6954bdfa5d0435479fd4eaf/Cloud/en-US/d5660c146a93483692335e9d79a8c58f.html.
This seem to correspond to Apache Camel jmsMessageType set to Bytes,
see https://camel.apache.org/components/3.14.x/amqp-component.html for details.
The decoding of the body in the ServiceBusReceivedMessage works as expected and the BodyType is set to Data. If using Text on the producer side, the BodyType will be set to Value as described which led to the problems with the decoding of the body.

Sending a POST request using Balkan's requests lib with data and files (Robot Framework)

I'm trying to send a request (post) using Balkan's requests library from test case written in Robot Framework http://bulkan.github.io/robotframework-requests/#Post with two parameters as a data and a file. Unfortunatelly, all the time I have the same error like described below.
My Test Case:
X_T_Should Upload File Correctly And Get HTTP 200
Send Default File To SUT And Return Response
*** Keywords ***
Send Default File To SUT And Return Response
[Arguments] ${user_login}=${USER_LOGIN} ${user_password}=${USER_PASSWORD}
${url}= Get URL
${auth}= Create List ${user_login} ${user_password}
Create Session rm ${url} auth=${auth}
&{headers}= Create Dictionary Content-Type=application/x-www-form-urlencoded
&{data}= Create Dictionary name=file filename=${DEFAULT_FILE_NAME}
${file_data}= Get Binary File ${CURDIR}${/}Resources${/}${DEFAULT_FILE_NAME}
&{files}= Create Dictionary file=${file_data}
${resp}= Post Request rm ${UPLOAD_URI} files=${files} data=${data} headers=${headers}
Delete All Sessions
Error (from Robot Framework):
20160525 09:47:10.645 : FAIL : ValueError: Data must not be a string.
The problem is with the keyword Post Request. When I do not set an argument files or data that everything is well but if I set both args. that I see these strange error.
It is a bug in library?
According to the documentation, the files parameter is a list of file names. You are passing the actual file contents into the keyword. This might explain why you are getting "Data must not be a string".
We've encountered this exception also. The exception seems to be raised in Requests Python library.
At line 119 of requests/models.py,
elif isinstance(data, basestring)
checks whether data is a string. And robotframework-requests seems to be casting data into a string almost always. There is an issue for robotframework-requests regarding the exception.

DocumentDB web API access with R

I have the following issue when trying to connect to the documentDB web API with R and PostMan.
In the DocumentDB documentation the way to ask something to the web API is to compose an Authorization header with base64 hash.
In R I'm trying to compute the signature and test the header directly with postman.
But I get every time a http 401.
Here is my R code:
toHash <- enc2utf8("get\ncolls\ndbs/toto/colls/testtoto\nsun, 08 may 2016 06:43:05 gmt\n\n")
hash <- hmac(key, toHash, "sha256")
base64(hash)
the "key" is the primary key got from the portal.
And then, following the Azure documentation, my header is:
type=master&ver=1.0&sig=< thebase64(hash) >
I'm pasting that into PostMan with the headers x-ms-version, date and x-ms-date.
But it'is not working..
I'm stuck now, does anyone have an idea? Am I using a wrong R function? A wrong key, is there a way to get more information about the mismatch?
The web api response is :
{
"code": "Unauthorized",
"message": "The input authorization token can't serve the request. Please check that the expected payload is built as per the protocol, and check the key being used. Server used the following payload to sign: 'get\ncolls\ndbs/toto/colls/testtoto\nsun, 08 may 2016 06:43:05 gmt\n\n'\r\nActivityId: fadbfc0b-e298-418a-b56c-8114699fff91"
}
I found what was wrong by myself.
The token given in the Azure portal is base64 encoded. So It is mandatory to decode it:
RCurl::base64Decode(key, mode="raw")
in order to use it with the digest::hmac function. It is also mandatory to specify raw = TRUE within this hmac function.

Error while Uploading file for API in apigee

I have an existing API proxy in Apigee edge. When I am trying to edit and save any policy I am getting below error.
Error while Uploading file for API <api name>.
org.apache.xerces.dom.ElementNSImpl cannot be cast to com.apigee.messaging.config.beans.TargetConnection
I am not able to figureout how to resolve this.
Thanks in advance.
When you get an error message like 'cannot be cast to...' that suggests that the field is expecting a certain type (message type in your case, like a request object or response object).
Try ensuring that the variable you enter into that particular field is a message type. It may be that the variable you are using is only a subset of a whole message.

IBM Worklight Http Adapters

I am using IBM worklight and would like to consume a .NET web service using http adapters. getting the error: "errors": ["Runtime:Runtime: Http request failed: java.net.UnknownHostException:
domain inside the xml typed it in full as [http://localhost/Service/Service1.asmx]
function HelloWorld() {
var input = {
method : 'get',
returnedContentType : 'xml',
path : "HelloWorld",
transformation : {
type : 'xslFile',
xslFile : 'filtered.xsl'
}
};
return WL.Server.invokeHttp(input);
}
In adapter's XML
<protocol>http</protocol>
<host>localhost</host>
<port>80</port>
In adapters JS use path:"Service/Service1.asmx"
Also, make sure that your service returns XML and your filtered.xsl contains a valid transformation for returned XML (otherwise just remote transformation property).
I think you are doing the same mistake I was doing few minutes ago. Your HelloWorld function is incomplete. I suggest if you refer to the way the client is constructing the message as per this question: IBM Worklight HTTP Adapter SOAP response: XSL transformation failed

Resources