You can achieve it by using **internal API** that can change in future versions without any comment.
Use a custom StreamingOutput class which does the ivy context setup:
public abstract class IvyStreamingOutput implements StreamingOutput {
private final IProcessModelVersion pmv;
private final ISession session;
public IvyStreamingOutput()
{
this.pmv = MetaData.getProcessModelVersion();
this.session = MetaData.getSession();this(MetaData.getProcessModelVersion(), MetaData.getSession());
}
public IvyStreamingOutput(IProcessModelVersion pmv, ISession session)
{
this.pmv = pmv;
this.session = session;
}
@Override
public final void write(OutputStream stream)
throws IOException, WebApplicationException
{
IProcessModelVersionRequest streamRequest = RequestFactory.createRestRequest(pmv, session);
MetaData.pushRequest(streamRequest);
try
{
writeInIvyContext(stream);
}
finally
{
MetaData.popRequest();
}
}
public abstract void writeInIvyContext(OutputStream stream)
throws IOException, WebApplicationException ;
}
Then you can implement any logic that requires the Ivy.XYZ() methods within the `writeInIvyContext(OutputStream stream)` method.