Question Krishnamuthu Venkatachalam · Feb 4, 2019

How to set Content-Type header in http outbound adapter. It always sends the content-type as plain text/html.

How to set Content-Type header in http outbound adapter. It always sends the content-type as plain text/html. I am uploading a image / Pdf.

Class TEST.BusinessOperation.SaveFile Extends Ens.BusinessOperation
{
Parameter ADAPTER = "EnsLib.HTTP.OutboundAdapter";
Property Adapter As EnsLib.HTTP.OutboundAdapter;
Parameter INVOCATION = "Queue";
Method SaveFile(pRequest As Messages.File, Output pResponse As Messages.SaveFileResponse) As %Status
{
     set fileName = pRequest.fileName
    set Content = pRequest.fileContent
    set tSC = ..Adapter.PutURL(URL,.HttpResponse,"",Content.Read())

}

}

Comments

Gilberto Junior · Feb 4, 2019

Hi

Here is the code I use:

Set tHttpRequest = ## class (% Net.HttpRequest). New ()
From tHttpRequest.ContentTypeSet ("application / json")
From tHttpRequest.SetHeader ("Authorization", "Basic [Base64String]")
From tHttpRequest.ContentCharsetSet ("utf-8")
From tHttpRequest.EntityBody.Write (tJsonTxt)

0
Krishnamuthu Venkatachalam  Feb 4, 2019 to Gilberto Junior

The above  example would work but how can I do it with Ensemble Outbound adapter. Since we have no reference of HttpRequest object.

(I did not find a field like ContentType in Adapter class.)

0
Rajib Quayum  Feb 4, 2019 to Gilberto Junior

Have you tried this instead of ContentTypeSet?

SetHeader ("Content-Type", "application/json")

This seems to work for us.

0
Everardo Cunha  Jun 25, 2019 to Gilberto Junior

Ola Gilberto,

Tudo bem? Por acaso ja usou Server-Sent Events com Emsemble/Cache?

Obrigado,

Everardo

0
Gilberto Junior  Feb 5, 2019 to Krishnamuthu Venkatachalam

Hi, Krishna muthu.

This is the only ESB adapter that I do not use, because debugging esb ends up taking many steps to create a
% Net.HttpRequest. With this we adopt the strategy of making the requisitions manually.

Sorry for the mistakes this message has been translated by google translate.

0
Krishnamuthu Venkatachalam  Feb 4, 2019 to Rajib Quayum

No, we have no object reference of HttpRequest (SetHeader is a method of HttpRequest object)

0
Gilberto Junior  Jun 25, 2019 to Everardo Cunha

Everardo, bom dia.

Desculpa mas pra te falar a vdd nem sei o que é Server-Sent Events 

Consegue mandar um exemplo do que isso faria

0
Eduard Lebedyuk · Feb 4, 2019

Redefine HTTP adapter like this:

Class Production.Adapter.HTTPOutboundAdapter Extends EnsLib.HTTP.OutboundAdapter
{

Method PostURL(pURL As%String, Output pHttpResponse As%Net.HttpResponse, pFormVarNames As%String, pData...) As%Status [ CodeMode = expression ]
{
..SendFormDataArray(.pHttpResponse, "POST", ..GetRequest(), .pFormVarNames, .pData, pURL)
}

ClassMethod GetRequest() As%Net.HttpRequest
{
    set request = ##class(%Net.HttpRequest).%New()
    set request.ContentType  =  "application/pdf"quit request
}

}

And use it instead of default adapter.

For better performance it would be better to reuse the request.

Alternatively, you can call SendFormDataArray adapter method directly and it accepts request object.

0
Robert Cemper · Feb 4, 2019

 #1)

You need to get %Net.HttpRequest in hands to set your property Content Type.

#2)

instead of PutURL(...) you have to use method SendFormDataURL(....)  of EnsLib.HTTP.OutboundAdapter

more details in docs here:

Creating Custom HTTP Requests

If you use the more common methods of the HTTP outbound adapter (such as Get), the adapter automatically creates and sends an HTTP request, which can include either form data or a request body. In special cases, you may want to create a custom HTTP request so that you can specify details such as proxy authorization or a different character encoding.
0