Replies:

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.
 

Followers:
Marcio has no followers yet.
Following:
Marcio has not followed anybody yet.
Global Masters badges:
Marcio has no Global Masters badges yet.