Iris vs Java
Hello. I'm having problems migrating a java application that is running with cache 2018 to Iris
The application uses json generated by the cache to receive it as a string in java.
Basically an instance of the "%ZEN.proxyObject" class
On Iris I've been trying to convert this '%ZEN.proxyObject Object to an instance of the %GlobalBinaryStream class and I need to get it via reference.
But I haven't had success yet. I Just found example with primitive dataTypes via reference and I need a Streams.
Has anyone done something like that?
This is my cache class example:
ClassMethod Login(ByRef streamReturn As %GlobalBinaryStream, user As %String, pass As %String) As %Status [ ProcedureBlock = 1 ] { set streamReturn=##class(%GlobalBinaryStream).%New() set cswReturn=##class(%ZEN.proxyObject).%New() set cswReturn.success=1 ; set sc=##class(%ZEN.Auxiliary.jsonProvider).%WriteJSONStreamFromObject(.streamReturn,cswReturn,,,,"aelo") ; quit sc }
I need to get streamReturn with java native api...
Thanks
suggestion
or simply
If you have a complex object, then add %JSON.Adaptor to the class,
and do an %JSONExportToStream as you did with %XML.Adapter
The %GlobalBinaryStream class is deprecated and newly written code should instead use %Stream.GlobalBinary. Of course, existing code that is not needing modification can continue using %Library.GlobalBinaryStream.
.
Hi Marcio,
I am a developer at InterSystems and I work with Java, JSON, and SQL every day. Perhaps I can help. Can you provide an example of the Java code where you receive the JSON output from IRIS? I think I have a couple of interesting options for you.
-Dan
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.
Interesting! I didn't see which version of InterSystems IRIS you are using but you might try a couple of things:
First, don't return a status value from your method. Instead return a %Stream.GlobalBinary instance. If you still want a status, get it some other way. I recommend just throwing an exception - IRIS Native should handle that okay. The object value you get back will be a proxy object that should allow you to read the stream. In our documentation you might search for "reverse proxy objects".
If get some time, I will try to build a sample of doing this.
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 :)
Yes, of course "inverse" - sorry.
Persistent vs RegisteredObject - not a problem but you are calling a simple class method so we don't need any super class. I used this implementation for the IRIS Class:
And this is a crude hack at the Java code - the anonymous InputStream class could use more work but it does run for this simple example. I'll leave the rest of the InputStream coding to you.
Running this produces this output:
/usr/lib/jvm/adoptopenjdk-11-hotspot-amd64/bin/java -javaagent:/home/...
{"user":"java","pass":"jpass"}
Process finished with exit code 0
Hi Dan.
Thank you so much. The code worked. Now I will work to improve my example. Thanks