Dealing with JavaGateway output
Hi everyone,
I have just started to use JavaGateway and I didn''t encountered so much difficulties since I've got the output of the Java class I have called.
This is the class I have implemented:
Method OnRequest(pRequest As EnsLib.HL7.Message, Output pResponse As EnsLib.HL7.Message) As %Status { set MDMarchiv=pRequest.OutputToString() $$$TRACE(MDMarchiv) #dim RPConverter = ##class(training.hl7.HL7toRP).%New() set output=RPConverter.hl7toRp(MDMarchiv) $$$LOGINFO("after transformation: "_output) set RPStream = ##class(%FileCharacterStream).%New(output) #dim finalResponse As %FileCharacterStream=##class(%FileCharacterStream).%New() set sc = ..Transform(output, "xdata://" _ $classname() _ ":" _ "addSOAP", .finalResponse) #dim RPArchiv As HS.Message.XMLMessage = ##class(HS.Message.XMLMessage).%New() set RPArchiv.ContentStream=RPStream set sc=..SendRequestAsync("lombardia.bus.DCEProcess",RPArchiv) if $$$ISERR(sc) {quit sc} quit $$$OK }
Basically, I want want to translate an HL7 message into an XML message through the java class called by the JavaGateway in this way:
Parameter JAVAGATEWAYPORT = 55555; Method hl7toRp(hl7 As %String) As %String { #dim jgw As %Net.Remote.Gateway = "" //#dim ret As %String="" try { $$$LOGINFO("START: JAVAGTW "_..#JAVAGATEWAYPORT) //w "START: JAVAGTW"_..#JAVAGATEWAYPORT_"\n" set jgw = ##class(%Net.Remote.Java.JavaGateway).%New() set sc = jgw.%Connect("localhost", ..#JAVAGATEWAYPORT) $$$LOGINFO("Status after connect: "_sc) if $$$ISERR(sc) quit w "HL7 "_ hl7,! $$$TRACE(hl7) #dim ret As %String = ##class(com.santer.siss.mapping.v25.fse.tester.HL7toXML).hl7ToRP(.jgw, .hl7) $$$LOGINFO($$$CLASSNAME(ret)) if $isObject(jgw) try { do jgw.%Disconnect() } catch ignore { $$$LOGSTATUS(ignore.AsStatus()) } } catch ex { w "Exception"_ex ,! set sc = $get(%objlasterror) if (sc = "") set sc = ex.AsStatus() set ret = sc } w ret,! return ret }
Everithing seems to work fine, indeed, when I log the output with the $$$LOGINFO i get the xml message that I was expecting. The quite strange thing is that when I try to log the class type I have obtained as output of the java class, I didn't get %String or some other ObjectScript class but, instead, I get the xml message itself. It seem to be that the result don't have a proper class type.
The final issue arise when I try to put the result into a stream; the xml message results empty and, moreover, If I try to send just the RPStream, I get this error: OID is null.
How can I cast the output as a string or better as a stream in order to deal with it normally?
Thanks in advance for your collaboration.
Please consider posting com.santer.siss.mapping.v25.fse.tester.HL7toXML:hl7ToRP method.
And also $$$CLASSNAME definition.
That is correct, the ret variable seems to be a string, so it's not a class, therefore it cannot have a class name.
In Object Script there are objects and primitives (strings). Only objects have classes.
How are you doing it?
Ok this make sense, thank you. This if what I get from the $CLASSNAME log:
This, instead, is the java class:
I have tried to put it into a stream in two ways:
1. set RPStream = ##class(%FileCharacterStream).%New(output)
2. With an XSLT in order to add the SOAP envelope: #dim finalResponse As %FileCharacterStream=##class(%FileCharacterStream).%New()
set sc = ..Transform(output, "xdata://" _ $classname() _ ":" _ "addSOAP", .finalResponse)
Thanks to trace operation, I was seeing the the tranform was working but I was getting an error before the asysnc request. I'm posing everithig below:
Transform
Trasform Output:
In this case I get this Error:
but it seems to be truncated.
Thanks a lot for your answer and collaboration
Streams work like this:
set stream = ##class(<stream class>).%New() do stream.Write(string) set sc = stream.Save()
In your case I'd recommend using %Stream.GlobalCharacter as stream class. FileStream also works better if you supply a filename. Check this doc.
Thank you so much. I solved the problem.
Not sure what are you trying to do. SOAP Operation should add all relevant headers and additional ones can be passed as objects. Docs.
UPD.