xml object to stream
I receive request xml object as
pRequest =
<getURL>
<Url1><![CDATA[https://test/cs/icdfg?&RevisionSelectionMethod=LatestReleased&allowInter...
</getURL>
I need to send this to a stream
Set XmlStream = ##class(%Stream.GlobalCharacter).%New()
// how do I send my pRequest into XmlStream ??
Do httpRequest.EntityBody.CopyFrom(XmlStream)
What class is pRequest? If it's a custom class, can you post the class definition?
Class TEST.pRequest Extends (%Persistent, %XML.Adaptor)
{
Property getURL As %String(MAXLEN = 10000000);
}
==================================
Class TEST.Operation.UrlOP Extends Ens.BusinessOperation
{
Parameter ADAPTER = "EnsLib.HTTP.OutboundAdapter";
Parameter INVOCATION = "Queue";
Method UrlApi(pRequest As TEST.pRequest, Output pResponse As TEST.pResponse) As %Status
{
Set httpRequest= ##class(%Net.HttpRequest).%New()
Set httpRequest.Server = ..Adapter.HTTPServer
Set httpRequest.Location = ..Adapter.URL
Set httpRequest.SSLConfiguration = ..Adapter.SSLConfig
Set httpRequest.SSLCheckServerIdentity = 0
Set httpRequest.Https = $$$YES
Set httpRequest.ContentType = "application/xml"
Set XmlStream = ##class(%Stream.GlobalCharacter).%New()
Do XmlStream.Write("<?xml version=""1.0"" encoding=""UTF-8""?><getURL><Url1>"_pRequest.getURL_"</Url1></getURL>")
//instead of above lines of code I would like to send pRequest into a stream
Do httpRequest.EntityBody.CopyFrom(XmlStream)
Set sc = httpRequest.Post("", 2)
}
QUIT $$$OK
XData MessageMap
{
<MapItems>
<MapItem MessageType="TEST.pRequest">
<Method>UrlApi</Method>
</MapItem>
</MapItems>
}
}
=====================================
Why define and reference an outbound adaptor when you don't use it in your code?
I'd suggest to have a look to the documentation Using the HTTP Outbound Adapter.
Anyway, given your code, you don't need a stream, it's just waste of resources and make your code more complicated for no reason, you can simply:
....
Set httpRequest.ContentType = "application/xml"
Do httpRequest.EntityBody.Write("<?xml version=""1.0"" encoding=""UTF-8""?><getURL>"_pRequest.getURL_"</getURL>")
Set sc = httpRequest.Post("", 2)
....
Note that I assume that <Url1></Url1> is contained in the getURL string property content, as your first post suggest.
Do XmlStream.Write("<?xml version=""1.0"" encoding=""UTF-8""?><getURL><Url1>"_pRequest.getURL_"</Url1></getURL>")
This is removing CDATA from the xml.
It worked :
set status = pRequest.XMLExportToStream(.XmlStream)
Do httpRequest.EntityBody.CopyFrom(XmlStream)