Hi @Maslennikov.Dmitry... I get the error on execute the line with "write args(1)" after "use $io..." Not possible execute "write" from process with JDBC connection. I will change all %Zen from my code coming soon. Thanks for warning
IRISforUNIX (Red Hat Enterprise Linux for x86-64) 2021.1 (Build 215U) WedJun9202109:48:12EDT
I think you meant "Inverse proxy Object" Here I changed my code to this: Iris Class
Class Utils.CSW1JavaFunctions Extends %RegisteredObject [ ClassType = "", Not ProcedureBlock ] {
ClassMethod IrisReturn(user, pass) As %Stream.GlobalBinary [ ProcedureBlock = 1 ]
{
;
set cswStream=##class(%Stream.GlobalBinary).%New()
;
set cswReturn=##class(%ZEN.proxyObject).%New()
set cswReturn.user=$get(user)
set cswReturn.pass=$get(pass)
set cswReturn.success=1
;
try {
set cswObj = ##class(%ZEN.Auxiliary.altJSONProvider).%ObjectToAET(cswReturn,,,"d")
do cswObj.%ToJSON(cswStream)
} catch ex {
throw ex
}
quit cswStream
}
}
I am not use Persistence class. In my case, my classes extends from %RegisteredObject Change Java method to this:
public Object execute(String method, Object... args) throws Exception {
ObjectMapper mapper = new ObjectMapper();
JsonNode jsonNode = null;
try {
byte[] data = iris.classMethodBytes(CACHE_CLASS_NAME, method, args[0], args[1]);
InputStream is = new ByteArrayInputStream(data);
/* Just debug */
BufferedReader in = new BufferedReader(new InputStreamReader(is));
String line = null;
while ((line = in.readLine()) != null) {
System.out.println(line);
}
jsonNode = (JsonNode) mapper.readTree(is);
} catch (Exception ex) {
ex.printStackTrace();
}
return jsonNode;
}
With this example, I get "3@%Stream.GlobalBinary" in console... lol :)
I created a very simple example with java classes and Iris methods. I make return a json string to demonstrate. I need to change this Strings to Strems. Ok?
ClassMethod IrisReturn(ByRef cswStream As %String, user, pass) As %Status [ ProcedureBlock = 1 ]
{
;
set cswStream=""
//set cswStream=##class(%Stream.GlobalBinary).%New()
;
set cswReturn=##class(%ZEN.proxyObject).%New()
set cswReturn.user=$get(user)
set cswReturn.pass=$get(pass)
set cswReturn.success=1
;
try {
set cswObj = ##class(%ZEN.Auxiliary.altJSONProvider).%ObjectToAET(cswReturn,,,"d")
set cswStream=cswObj.%ToJSON()
} catch ex {
set ^%MJ("ee")=ex.AsStatus()
}
quit $$$OK
}
I need that parameter cswStream is a Stream. But.. I dont find examples in documentation to use Streams in java. With you need the project, I can upload in my GitHub Account and share to you.
I talked to intersystems support. he asked me to break validation into two steps. one for each Tag. I'm trying to follow the support tips. But without success so far. In this example I'm trying to validate just the first <NFe> tag
;
; set sc=$$ValidateNFe("teste.xml","v400")
;
ValidateNFe(cswFileNameOrStream,cswNFeVersion) ;
new reader,sc,data,nfeStream,protNFeStream,clazzProc,clazzNFe,clazzProtNFe
;
set sc=$$Reader(cswFileNameOrStream,.reader)
quit:$$$ISERR(sc) sc
;
set clazzProc="br.com.sefaz.nfe."_cswNFeVersion_".TNfeProc"
;
set sc=##class(%Dictionary.CompiledClass).%ExistsId(clazzProc)
quit:$$$ISERR(sc) $$$ERROR(10000,"Classe ("_clazzProc_") não existente!")
;
do reader.Correlate("nfeProc",clazzProc)
if 'reader.Next(.data,.sc){
quit $$$ERROR(10000,"Arquivo XML inválido!")
}
;
set sc=$$XmlToStream(data.NFe,.nfeStream)
quit:$$$ISERR(sc) sc
;
set sc=##class(%XML.Document).GetDocumentFromStream(nfeStream,.document)
do document.AddIDs()
quit data.NFe.Signature.ValidateDocument(document)
Reader(cswFileNameOrStream,cswReader) ;
new sc
;
set cswReader=##class(%XML.Reader).%New()
set sc=cswReader.OpenStream(cswFileNameOrStream)
quit sc
XmlToStream(cswObj,xmlStream) ;
new writer,sc
;
set writer=##class(%XML.Writer).%New()
set writer.Charset="UTF-8"
set writer.Indent=1
set writer.NoXMLDeclaration=1
set xmlStream=##class(%GlobalBinaryStream).%New()
;
set sc=writer.OutputToStream(.xmlStream)
quit:$$$ISERR(sc) sc
;
set sc=writer.RootObject(cswObj)
quit sc
I get this error
w sc
FailedCheck
I believe that my "XmlToStream" rule is changing the original XML and therefore the validation was compromised. Does that make any sense?
Thanks for the reply Mr. Cemper.
But my application has much more complex json layouts. This was just a very basic example. From the tests I did with Stream, it is ok. My problem is how to get this stream via Java through a JDBC connection
The problem is a byte[] and java heap space. I have 200Mb into a InputStream and convert this a byte[], cause java.lang.OutOfMemoryError: Java heap space
It's a piece of my code....
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
int nRead;
byte[] data = new byte[1024];
while ((nRead = binaryStream.read(data, 0, data.length)) != -1) {
buffer.write(data, 0, nRead);
}
SerialBlob blob = new SerialBlob(buffer.toByteArray());
go to post
Thank you @John Murray
I create a method using the query SubclassOf that you shared.....
go to post
Hi @Maslennikov.Dmitry...
I get the error on execute the line with "write args(1)" after "use $io..."
Not possible execute "write" from process with JDBC connection.
I will change all %Zen from my code coming soon. Thanks for warning
go to post
Hi Dan.
Thank you so much. The code worked. Now I will work to improve my example. Thanks
go to post
Hi Dan... This is $zv from Iris instance.
IRIS for UNIX (Red Hat Enterprise Linux for x86-64) 2021.1 (Build 215U) Wed Jun 9 2021 09:48:12 EDT
I think you meant "Inverse proxy Object" Here
I changed my code to this:
Iris Class
I am not use Persistence class. In my case, my classes extends from %RegisteredObject
Change Java method to this:
With this example, I get "3@%Stream.GlobalBinary" in console... lol :)
go to post
I created a very simple example with java classes and Iris methods. I make return a json string to demonstrate. I need to change this Strings to Strems. Ok?
I use quarkus and jdk 11 and Iris database
Restasy endpoint
Class BrokerService with @Inject datasource and unwrap to IrisConnection
Iris Method
To test my example, I use curl
Return
I need that parameter cswStream is a Stream. But.. I dont find examples in documentation to use Streams in java.
With you need the project, I can upload in my GitHub Account and share to you.
go to post
I talked to intersystems support. he asked me to break validation into two steps. one for each Tag. I'm trying to follow the support tips. But without success so far. In this example I'm trying to validate just the first <NFe> tag
I get this error
I believe that my "XmlToStream" rule is changing the original XML and therefore the validation was compromised. Does that make any sense?
go to post
go to post
I noticed that ^% G has become unusable due to performance. I will direct my tests to another tool
go to post
Yes... its works to me...
go to post
This is works.... but sound like a workarround:
go to post
I try to set $HOME before to write file, but...
when I run third party software that reads the configuration file, the $ HOME variable goes back to / root
go to post
I need to run third party software that needs a configuration file in $HOME
go to post
Hello Kevin. Thank you for your attention.
I am trying to send an InputStream to the database.
My Stream is coming from a rest service (jax-rs, upload) I have an average file size of 200Mb.
I have a "prepareStatement" with sql query "Insert into <Class with %GlobalBinaryString property>"
go to post
Hello Kevin...
The problem is a byte[] and java heap space. I have 200Mb into a InputStream and convert this a byte[], cause java.lang.OutOfMemoryError: Java heap space
It's a piece of my code....
go to post
I am so sorry about the syntax error. I Edited my post
go to post
Bad news to me.
Iris driver do not connect to cache 2018. And this is my case