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

Hi Dan.
Thank you so much. The code worked. Now I will work to improve my example. Thanks

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

 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?

I use quarkus and jdk 11 and Iris database

Restasy endpoint

@Path("/session")
@RequestScoped
public class SessionEndPoint {

	@Inject
	BrokerService brokerService;
	
	private ObjectMapper mapper = new ObjectMapper();

	@POST
	@Path("IrisReturn")
	@Produces(MediaType.APPLICATION_JSON)
	public Response systemBoot(@HeaderParam("user") String user, @HeaderParam("pass") String pass) {
		ResponseBuilder response = Response.ok();
		try {
			JsonNode serverReturn = (JsonNode) brokerService.execute("IrisReturn", user, pass);
			response = Response.ok(mapper.writeValueAsString(serverReturn));
		} catch (Exception ex) {
			response = Response.status(Status.INTERNAL_SERVER_ERROR);
		}

		return response.build();
	}

	
}

Class BrokerService with @Inject datasource and unwrap to IrisConnection

@RequestScoped
public class BrokerService {

    @Inject
    DataSource dataSource;

    private Connection conn;
    private IRIS iris;
    private static String CACHE_CLASS_NAME = "Utils.CSW1JavaFunctions";

    @PostConstruct
    public void linit() {

        try {
            conn = dataSource.getConnection();
            IRISConnection iconn = (IRISConnection) conn.unwrap(IRISConnection.class);
            iris = IRIS.createIRIS(iconn);
        } catch (Exception e) {
            System.err.println("Connection erro!");
            e.printStackTrace();
        }
    }

    public Object execute(String method, Object... args) throws Exception {
        ObjectMapper mapper = new ObjectMapper();
        JsonNode jsonNode = null;
        IRISReference cacheReturn = new IRISReference("");
        try {
            iris.classMethodStatusCode(CACHE_CLASS_NAME, method, cacheReturn, args[0], args[1]);
            String xxxxxx = mapper.writeValueAsString(cacheReturn.getValue());
            jsonNode = (JsonNode) mapper.readTree(xxxxxx);
        } catch (Exception ex) {
            ex.printStackTrace();
		}
        return jsonNode;
    }

}

Iris Method 
 

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
}


To test my example, I use curl
 

curl -i -X POST -H "user: marcio.coelho" -H "pass: 123" -H "Content-Type: application/json" http://localhost:8090/session/IrisReturn

Return
 

"{\"pass\":123,\"success\":1,\"user\":\"marcio.coelho\"}"

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

I noticed that ^% G has become unusable due to performance. I will direct my tests to another tool
 

This is works.... but sound like a workarround:

set sc='$zf(-1,"export USER=`whoami` && export HOME=$( getent passwd ""$USER"" | cut -d: -f6 ) && touch $HOME/file.txt")