custom java action render html to image

0
Hi everybody, upfront I am quite new to coding in java. (But I tried hard sovling this on my own….. Did not succeed) Please note my mendix studio version is 7.23.19  Ok here is what I want to do:  I want to render a string of html into a image and “save” that to  a image object. So here is what i have done. I create a new entity (just a copy of the image in System) in the domain model of the module    I also set the access rules   Next I have set up my microflow where a create a new object of the entity Testimage and hand it to my costum java call. I also hand in a string of html Here now my java code:   package siedoc_2.actions; import com.mendix.systemwideinterfaces.core.IContext; import com.mendix.webui.CustomJavaAction; import com.mendix.systemwideinterfaces.core.IMendixObject; import gui.ava.html.image.generator.HtmlImageGenerator; import java.awt.image.RenderedImage; import java.io.*; import javax.imageio.ImageIO; public class Test_Java_call3 extends CustomJavaAction<java.lang.Boolean> { private java.lang.String Html_String; private IMendixObject __PictureParameter1; private siedoc_2.proxies.TestImage PictureParameter1; public Test_Java_call3(IContext context, java.lang.String Html_String, IMendixObject PictureParameter1) { super(context); this.Html_String = Html_String; this.__PictureParameter1 = PictureParameter1; } @java.lang.Override public java.lang.Boolean executeAction() throws Exception { this.PictureParameter1 = __PictureParameter1 == null ? null : siedoc_2.proxies.TestImage.initialize(getContext(), __PictureParameter1); // BEGIN USER CODE HtmlImageGenerator hig = new HtmlImageGenerator(); hig.loadHtml(Html_String); hig.saveAsImage("hello-world.png"); File imageFile = new File("hello-world.png"); InputStream targetStream = new FileInputStream(imageFile); PictureParameter1.setContents( getContext(), targetStream, imageFile.length()); return true; // END USER CODE } /** * Returns a string representation of this action */ @java.lang.Override public java.lang.String toString() { return "Test_Java_call3"; } // BEGIN EXTRA CODE // END EXTRA CODE } However the workflow return an error when execuded in the  app. (I will add the error message at the end because it is quite long)   First question: Do I use the getContext() here corretly in  PictureParameter1.setContents( getContext(), targetStream, imageFile.length()); Second question: If the upper code is correct, then I guess the problem lies with  hig.saveAsImage("hello-world.png"); File imageFile = new File("hello-world.png"); as I am not allowed to just save to the “server”. Is there a way make this save possible or use some kind of temporary file or buffer?   Third question: Am I complety wrong and the problem is somewhere else? Or is there a better way to this? Thanks a lot!!!!!   Here the complet error message:   An error has occurred while handling the request. [User 'MxAdmin' with session id '0176e5a1-XXXX-XXXX-XXXX-XXXXXXXX557e' and roles 'TechnicalAdministrator'] -------- com.mendix.core.CoreException: com.mendix.modules.microflowengine.MicroflowException: com.mendix.core.CoreRuntimeException: com.mendix.systemwideinterfaces.MendixRuntimeException: com.mendix.connectionbus.ConnectionBusRuntimeException: com.mendix.basis.connectionbus.ConnectionBusException: Exception occurred while updating data. (SQL State: 42501, Error Code: -5501) Detail Message: org.hsqldb.HsqlException: user lacks privilege or object not found: contents at SieDoc_2.Test_HTML (JavaAction : 'Test_Java_call3') Advanced stacktrace: at com.mendix.basis.component.InternalCoreBase.execute(InternalCoreBase.java:389) Caused by: com.mendix.modules.microflowengine.MicroflowException: com.mendix.core.CoreRuntimeException: com.mendix.systemwideinterfaces.MendixRuntimeException: com.mendix.connectionbus.ConnectionBusRuntimeException: com.mendix.basis.connectionbus.ConnectionBusException: Exception occurred while updating data. (SQL State: 42501, Error Code: -5501) Detail Message: org.hsqldb.HsqlException: user lacks privilege or object not found: contents at SieDoc_2.Test_HTML (JavaAction : 'Test_Java_call3') Advanced stacktrace: at com.mendix.modules.microflowengine.MicroflowUtil.processException(MicroflowUtil.java:146) Caused by: com.mendix.core.CoreException: com.mendix.core.CoreRuntimeException: com.mendix.systemwideinterfaces.MendixRuntimeException: com.mendix.connectionbus.ConnectionBusRuntimeException: com.mendix.basis.connectionbus.ConnectionBusException: Exception occurred while updating data. (SQL State: 42501, Error Code: -5501) Detail Message: org.hsqldb.HsqlException: user lacks privilege or object not found: contents at com.mendix.basis.component.InternalCoreBase.execute(InternalCoreBase.java:418) Caused by: com.mendix.core.CoreRuntimeException: com.mendix.systemwideinterfaces.MendixRuntimeException: com.mendix.connectionbus.ConnectionBusRuntimeException: com.mendix.basis.connectionbus.ConnectionBusException: Exception occurred while updating data. (SQL State: 42501, Error Code: -5501) Detail Message: org.hsqldb.HsqlException: user lacks privilege or object not found: contents at com.mendix.basis.actionmanagement.ActionManagerBase.executeSync(ActionManagerBase.java:159) Caused by: com.mendix.systemwideinterfaces.MendixRuntimeException: com.mendix.connectionbus.ConnectionBusRuntimeException: com.mendix.basis.connectionbus.ConnectionBusException: Exception occurred while updating data. (SQL State: 42501, Error Code: -5501) Detail Message: org.hsqldb.HsqlException: user lacks privilege or object not found: contents at com.mendix.util.classloading.Runner.doRunUsingClassLoaderOf(Runner.java:36) Caused by: com.mendix.connectionbus.ConnectionBusRuntimeException: com.mendix.basis.connectionbus.ConnectionBusException: Exception occurred while updating data. (SQL State: 42501, Error Code: -5501) Detail Message: org.hsqldb.HsqlException: user lacks privilege or object not found: contents at com.mendix.connectionbus.ConnectionBusImpl.commitBinaryField(ConnectionBusImpl.java:700) Caused by: com.mendix.basis.connectionbus.ConnectionBusException: Exception occurred while updating data. (SQL State: 42501, Error Code: -5501) Detail Message: org.hsqldb.HsqlException: user lacks privilege or object not found: contents at com.mendix.connectionbus.connections.jdbc.JdbcDataStore.getCorrectException(JdbcDataStore.java:736) Caused by: java.sql.SQLSyntaxErrorException: user lacks privilege or object not found: contents in statement [UPDATE "siedoc_2$testimage" SET "contents" = ? WHERE "id" = ?] at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source) at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source) at org.hsqldb.jdbc.JDBCPreparedStatement.<init>(Unknown Source) at org.hsqldb.jdbc.JDBCConnection.prepareStatement(Unknown Source) at org.apache.commons.dbcp2.DelegatingConnection.prepareStatement(DelegatingConnection.java:288) at org.apache.commons.dbcp2.DelegatingConnection.prepareStatement(DelegatingConnection.java:288) at com.mendix.connectionbus.connections.jdbc.JdbcDataStoreBase.withPreparedStatement(JdbcDataStoreBase.scala:565) at com.mendix.connectionbus.connections.jdbc.JdbcDataStoreBase.$anonfun$execModificationQueries$1(JdbcDataStoreBase.scala:341) at com.mendix.connectionbus.connections.jdbc.JdbcDataStoreBase.$anonfun$execModificationQueries$1$adapted(JdbcDataStoreBase.scala:341) at com.mendix.connectionbus.connections.jdbc.JdbcDataStoreBase.$anonfun$executeWithUcViolationHandling$1(JdbcDataStoreBase.scala:510) at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23) at scala.util.Try$.apply(Try.scala:213) at com.mendix.connectionbus.connections.jdbc.JdbcDataStoreBase.executeWithUcViolationHandling(JdbcDataStoreBase.scala:510) at com.mendix.connectionbus.connections.jdbc.JdbcDataStoreBase.doModificationQueries$1(JdbcDataStoreBase.scala:344) at com.mendix.connectionbus.connections.jdbc.JdbcDataStoreBase.execModificationQueries(JdbcDataStoreBase.scala:354) at com.mendix.connectionbus.connections.jdbc.JdbcDataStoreBase.execUpdateQueries(JdbcDataStoreBase.scala:271) at com.mendix.connectionbus.connections.jdbc.JdbcDataStore.store(JdbcDataStore.java:494) at com.mendix.connectionbus.store.EntityStorer.handleRequest(EntityStorer.java:132) at com.mendix.connectionbus.store.EntityStorer.store(EntityStorer.java:72) at com.mendix.connectionbus.RequestAnalyzer.doRequest(RequestAnalyzer.java:78) at com.mendix.connectionbus.ConnectionBusImpl.doRequest(ConnectionBusImpl.java:488) at com.mendix.connectionbus.ConnectionBusImpl.commitBinaryField(ConnectionBusImpl.java:698) at com.mendix.basis.objectmanagement.member.MendixBinaryImpl.storeValue(MendixBinaryImpl.java:137) at system.proxies.FileDocument.setContents(FileDocument.java:364) at siedoc_2.actions.Test_Java_call3.executeAction(Test_Java_call3.java:45) at siedoc_2.actions.Test_Java_call3.executeAction(Test_Java_call3.java:20) at com.mendix.systemwideinterfaces.core.UserAction.execute(UserAction.java:46) at com.mendix.basis.actionmanagement.CoreActionHandlerImpl.doCall(CoreActionHandlerImpl.scala:79) at com.mendix.basis.actionmanagement.CoreActionHandlerImpl.call(CoreActionHandlerImpl.scala:57) at com.mendix.core.actionmanagement.CoreAction.call(CoreAction.java:55) at com.mendix.basis.actionmanagement.ActionManagerBase$1.execute(ActionManagerBase.java:150) at com.mendix.util.classloading.Runner.doRunUsingClassLoaderOf(Runner.java:32) at com.mendix.basis.actionmanagement.ActionManagerBase.executeSync(ActionManagerBase.java:155) at com.mendix.basis.component.InternalCoreBase.execute(InternalCoreBase.java:414) at com.mendix.modules.microflowengine.actions.actioncall.JavaAction.execute(JavaAction.scala:56) at com.mendix.modules.microflowengine.microflow.impl.MicroflowObject.execute(MicroflowObject.java:47) at com.mendix.modules.microflowengine.microflow.impl.MicroflowImpl.executeAfterBreakingIfNecessary(MicroflowImpl.java:201) at com.mendix.modules.microflowengine.microflow.impl.MicroflowImpl.executeAction(MicroflowImpl.java:157) at com.mendix.systemwideinterfaces.core.UserAction.execute(UserAction.java:46) at com.mendix.basis.actionmanagement.CoreActionHandlerImpl.doCall(CoreActionHandlerImpl.scala:79) at com.mendix.basis.actionmanagement.CoreActionHandlerImpl.call(CoreActionHandlerImpl.scala:57) at com.mendix.core.actionmanagement.CoreAction.call(CoreAction.java:55) at com.mendix.basis.actionmanagement.ActionManagerBase$1.execute(ActionManagerBase.java:150) at com.mendix.util.classloading.Runner.doRunUsingClassLoaderOf(Runner.java:32) at com.mendix.basis.actionmanagement.ActionManagerBase.executeSync(ActionManagerBase.java:155) at com.mendix.basis.component.InternalCoreBase.execute(InternalCoreBase.java:383) at com.mendix.basis.component.InternalCoreBase.execute(InternalCoreBase.java:398) at com.mendix.webui.actions.client.ExecuteMicroflowAction.runMicroflow(ExecuteMicroflowAction.scala:46) at com.mendix.webui.actions.client.ExecuteMicroflowAction.apply(ExecuteMicroflowAction.scala:32) at com.mendix.webui.actions.client.ExecuteMicroflowAction.apply(ExecuteMicroflowAction.scala:15) at com.mendix.webui.actions.client.RegularClientAction.$anonfun$execute$4(RegularClientAction.scala:46) at com.mendix.webui.requesthandling.helpers.StateHandling.withState(StateHandling.scala:35) at com.mendix.webui.requesthandling.helpers.StateHandling.withState$(StateHandling.scala:23) at com.mendix.webui.actions.client.RegularClientAction.withState(RegularClientAction.scala:21) at com.mendix.webui.actions.client.RegularClientAction.$anonfun$execute$3(RegularClientAction.scala:44) at scala.util.Try$.apply(Try.scala:213) at com.mendix.webui.actions.client.RegularClientAction.$anonfun$execute$2(RegularClientAction.scala:44) at com.mendix.webui.actions.client.RegularClientAction.$anonfun$execute$2$adapted(RegularClientAction.scala:42) at com.mendix.webui.requesthandling.helpers.ContextHandling.$anonfun$inContext$6(ContextHandling.scala:47) at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23) at com.mendix.basis.actionmanagement.IMonitoredAction$$anon$1.execute(IMonitoredAction.scala:47) at com.mendix.util.classloading.Runner.doRunUsingClassLoaderOf(Runner.java:32) at com.mendix.basis.actionmanagement.IMonitoredAction.monitor(IMonitoredAction.scala:49) at com.mendix.basis.actionmanagement.IMonitoredAction.monitor$(IMonitoredAction.scala:25) at com.mendix.webui.requesthandling.helpers.ContextHandling$ClientMonitoredAction.monitor(ContextHandling.scala:59) at com.mendix.webui.requesthandling.helpers.ContextHandling.inContext(ContextHandling.scala:47) at com.mendix.webui.requesthandling.helpers.ContextHandling.inContext$(ContextHandling.scala:27) at com.mendix.webui.actions.client.RegularClientAction.inContext(RegularClientAction.scala:21) at com.mendix.webui.requesthandling.helpers.ContextHandling.inContext(ContextHandling.scala:24) at com.mendix.webui.requesthandling.helpers.ContextHandling.inContext$(ContextHandling.scala:19) at com.mendix.webui.actions.client.RegularClientAction.inContext(RegularClientAction.scala:21) at com.mendix.webui.actions.client.RegularClientAction.$anonfun$execute$1(RegularClientAction.scala:42) at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23) at com.mendix.webui.requesthandling.helpers.ProfileHandling.profileRequest(ProfileHandling.scala:14) at com.mendix.webui.requesthandling.helpers.ProfileHandling.profileRequest$(ProfileHandling.scala:10) at com.mendix.webui.actions.client.RegularClientAction.profileRequest(RegularClientAction.scala:21) at com.mendix.webui.actions.client.RegularClientAction.execute(RegularClientAction.scala:39) at com.mendix.webui.requesthandling.ClientRequestHandler.handleAction(ClientRequestHandler.scala:124) at com.mendix.webui.requesthandling.ClientRequestHandler.processRequest(ClientRequestHandler.scala:101) at com.mendix.externalinterface.connector.RequestHandler.doProcessRequest(RequestHandler.java:40) at com.mendix.external.connector.MxRuntimeConnector$1.execute(MxRuntimeConnector.java:72) at com.mendix.external.connector.MxRuntimeConnector$1.execute(MxRuntimeConnector.java:69) at com.mendix.util.classloading.Runner.doRunUsingClassLoaderOf(Runner.java:32) at com.mendix.external.connector.MxRuntimeConnector.processRequest(MxRuntimeConnector.java:75) at com.mendix.basis.impl.MxRuntimeImpl.processRequest(MxRuntimeImpl.java:953) at com.mendix.m2ee.appcontainer.server.handler.RuntimeHandler.service(RuntimeHandler.java:42) at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:763) at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:551) at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:233) at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1610) at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:233) at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1369) at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:188) at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:489) at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1580) at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:186) at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1284) at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141) at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127) at org.eclipse.jetty.server.Server.handle(Server.java:501) at org.eclipse.jetty.server.HttpChannel.lambda$handle$1(HttpChannel.java:383) at org.eclipse.jetty.server.HttpChannel.dispatch(HttpChannel.java:556) at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:375) at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:272) at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:311) at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:103) at org.eclipse.jetty.io.ChannelEndPoint$1.run(ChannelEndPoint.java:104) at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.runTask(EatWhatYouKill.java:336) at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:313) at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.tryProduce(EatWhatYouKill.java:171) at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:129) at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:375) at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:806) at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:938) at java.lang.Thread.run(Thread.java:748) Caused by: org.hsqldb.HsqlException: user lacks privilege or object not found: contents at org.hsqldb.error.Error.error(Unknown Source) at org.hsqldb.error.Error.error(Unknown Source) at org.hsqldb.ParserDQL.XreadTargetSpecification(Unknown Source) at org.hsqldb.ParserDML.readSetClauseList(Unknown Source) at org.hsqldb.ParserDML.compileUpdateStatement(Unknown Source) at org.hsqldb.ParserCommand.compilePart(Unknown Source) at org.hsqldb.ParserCommand.compileStatement(Unknown Source) at org.hsqldb.Session.compileStatement(Unknown Source) at org.hsqldb.StatementManager.compile(Unknown Source) at org.hsqldb.Session.execute(Unknown Source) at org.hsqldb.jdbc.JDBCPreparedStatement.<init>(Unknown Source) at org.hsqldb.jdbc.JDBCConnection.prepareStatement(Unknown Source) at org.apache.commons.dbcp2.DelegatingConnection.prepareStatement(DelegatingConnection.java:288) at org.apache.commons.dbcp2.DelegatingConnection.prepareStatement(DelegatingConnection.java:288) at com.mendix.connectionbus.connections.jdbc.JdbcDataStoreBase.withPreparedStatement(JdbcDataStoreBase.scala:565) at com.mendix.connectionbus.connections.jdbc.JdbcDataStoreBase.$anonfun$execModificationQueries$1(JdbcDataStoreBase.scala:341) at com.mendix.connectionbus.connections.jdbc.JdbcDataStoreBase.$anonfun$execModificationQueries$1$adapted(JdbcDataStoreBase.scala:341) at com.mendix.connectionbus.connections.jdbc.JdbcDataStoreBase.$anonfun$executeWithUcViolationHandling$1(JdbcDataStoreBase.scala:510) at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23) at scala.util.Try$.apply(Try.scala:213) at com.mendix.connectionbus.connections.jdbc.JdbcDataStoreBase.executeWithUcViolationHandling(JdbcDataStoreBase.scala:510) at com.mendix.connectionbus.connections.jdbc.JdbcDataStoreBase.doModificationQueries$1(JdbcDataStoreBase.scala:344) at com.mendix.connectionbus.connections.jdbc.JdbcDataStoreBase.execModificationQueries(JdbcDataStoreBase.scala:354) at com.mendix.connectionbus.connections.jdbc.JdbcDataStoreBase.execUpdateQueries(JdbcDataStoreBase.scala:271) at com.mendix.connectionbus.connections.jdbc.JdbcDataStore.store(JdbcDataStore.java:494) at com.mendix.connectionbus.store.EntityStorer.handleRequest(EntityStorer.java:132) at com.mendix.connectionbus.store.EntityStorer.store(EntityStorer.java:72) at com.mendix.connectionbus.RequestAnalyzer.doRequest(RequestAnalyzer.java:78) at com.mendix.connectionbus.ConnectionBusImpl.doRequest(ConnectionBusImpl.java:488) at com.mendix.connectionbus.ConnectionBusImpl.commitBinaryField(ConnectionBusImpl.java:698) at com.mendix.basis.objectmanagement.member.MendixBinaryImpl.storeValue(MendixBinaryImpl.java:137) at system.proxies.FileDocument.setContents(FileDocument.java:364) at siedoc_2.actions.Test_Java_call3.executeAction(Test_Java_call3.java:45) at siedoc_2.actions.Test_Java_call3.executeAction(Test_Java_call3.java:20) at com.mendix.systemwideinterfaces.core.UserAction.execute(UserAction.java:46) at com.mendix.basis.actionmanagement.CoreActionHandlerImpl.doCall(CoreActionHandlerImpl.scala:79) at com.mendix.basis.actionmanagement.CoreActionHandlerImpl.call(CoreActionHandlerImpl.scala:57) at com.mendix.core.actionmanagement.CoreAction.call(CoreAction.java:55) at com.mendix.basis.actionmanagement.ActionManagerBase$1.execute(ActionManagerBase.java:150) at com.mendix.util.classloading.Runner.doRunUsingClassLoaderOf(Runner.java:32) at com.mendix.basis.actionmanagement.ActionManagerBase.executeSync(ActionManagerBase.java:155) at com.mendix.basis.component.InternalCoreBase.execute(InternalCoreBase.java:414) at com.mendix.modules.microflowengine.actions.actioncall.JavaAction.execute(JavaAction.scala:56) at com.mendix.modules.microflowengine.microflow.impl.MicroflowObject.execute(MicroflowObject.java:47) at com.mendix.modules.microflowengine.microflow.impl.MicroflowImpl.executeAfterBreakingIfNecessary(MicroflowImpl.java:201) at com.mendix.modules.microflowengine.microflow.impl.MicroflowImpl.executeAction(MicroflowImpl.java:157) at com.mendix.systemwideinterfaces.core.UserAction.execute(UserAction.java:46) at com.mendix.basis.actionmanagement.CoreActionHandlerImpl.doCall(CoreActionHandlerImpl.scala:79) at com.mendix.basis.actionmanagement.CoreActionHandlerImpl.call(CoreActionHandlerImpl.scala:57) at com.mendix.core.actionmanagement.CoreAction.call(CoreAction.java:55) at com.mendix.basis.actionmanagement.ActionManagerBase$1.execute(ActionManagerBase.java:150) at com.mendix.util.classloading.Runner.doRunUsingClassLoaderOf(Runner.java:32) at com.mendix.basis.actionmanagement.ActionManagerBase.executeSync(ActionManagerBase.java:155) at com.mendix.basis.component.InternalCoreBase.execute(InternalCoreBase.java:383) at com.mendix.basis.component.InternalCoreBase.execute(InternalCoreBase.java:398) at com.mendix.webui.actions.client.ExecuteMicroflowAction.runMicroflow(ExecuteMicroflowAction.scala:46) at com.mendix.webui.actions.client.ExecuteMicroflowAction.apply(ExecuteMicroflowAction.scala:32) at com.mendix.webui.actions.client.ExecuteMicroflowAction.apply(ExecuteMicroflowAction.scala:15) at com.mendix.webui.actions.client.RegularClientAction.$anonfun$execute$4(RegularClientAction.scala:46) at com.mendix.webui.requesthandling.helpers.StateHandling.withState(StateHandling.scala:35) at com.mendix.webui.requesthandling.helpers.StateHandling.withState$(StateHandling.scala:23) at com.mendix.webui.actions.client.RegularClientAction.withState(RegularClientAction.scala:21) at com.mendix.webui.actions.client.RegularClientAction.$anonfun$execute$3(RegularClientAction.scala:44) at scala.util.Try$.apply(Try.scala:213) at com.mendix.webui.actions.client.RegularClientAction.$anonfun$execute$2(RegularClientAction.scala:44) at com.mendix.webui.actions.client.RegularClientAction.$anonfun$execute$2$adapted(RegularClientAction.scala:42) at com.mendix.webui.requesthandling.helpers.ContextHandling.$anonfun$inContext$6(ContextHandling.scala:47) at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23) at com.mendix.basis.actionmanagement.IMonitoredAction$$anon$1.execute(IMonitoredAction.scala:47) at com.mendix.util.classloading.Runner.doRunUsingClassLoaderOf(Runner.java:32) at com.mendix.basis.actionmanagement.IMonitoredAction.monitor(IMonitoredAction.scala:49) at com.mendix.basis.actionmanagement.IMonitoredAction.monitor$(IMonitoredAction.scala:25) at com.mendix.webui.requesthandling.helpers.ContextHandling$ClientMonitoredAction.monitor(ContextHandling.scala:59) at com.mendix.webui.requesthandling.helpers.ContextHandling.inContext(ContextHandling.scala:47) at com.mendix.webui.requesthandling.helpers.ContextHandling.inContext$(ContextHandling.scala:27) at com.mendix.webui.actions.client.RegularClientAction.inContext(RegularClientAction.scala:21) at com.mendix.webui.requesthandling.helpers.ContextHandling.inContext(ContextHandling.scala:24) at com.mendix.webui.requesthandling.helpers.ContextHandling.inContext$(ContextHandling.scala:19) at com.mendix.webui.actions.client.RegularClientAction.inContext(RegularClientAction.scala:21) at com.mendix.webui.actions.client.RegularClientAction.$anonfun$execute$1(RegularClientAction.scala:42) at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23) at com.mendix.webui.requesthandling.helpers.ProfileHandling.profileRequest(ProfileHandling.scala:14) at com.mendix.webui.requesthandling.helpers.ProfileHandling.profileRequest$(ProfileHandling.scala:10) at com.mendix.webui.actions.client.RegularClientAction.profileRequest(RegularClientAction.scala:21) at com.mendix.webui.actions.client.RegularClientAction.execute(RegularClientAction.scala:39) at com.mendix.webui.requesthandling.ClientRequestHandler.handleAction(ClientRequestHandler.scala:124) at com.mendix.webui.requesthandling.ClientRequestHandler.processRequest(ClientRequestHandler.scala:101) at com.mendix.externalinterface.connector.RequestHandler.doProcessRequest(RequestHandler.java:40) at com.mendix.external.connector.MxRuntimeConnector$1.execute(MxRuntimeConnector.java:72) at com.mendix.external.connector.MxRuntimeConnector$1.execute(MxRuntimeConnector.java:69) at com.mendix.util.classloading.Runner.doRunUsingClassLoaderOf(Runner.java:32) at com.mendix.external.connector.MxRuntimeConnector.processRequest(MxRuntimeConnector.java:75) at com.mendix.basis.impl.MxRuntimeImpl.processRequest(MxRuntimeImpl.java:953) at com.mendix.m2ee.appcontainer.server.handler.RuntimeHandler.service(RuntimeHandler.java:42) at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:763) at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:551) at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:233) at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1610) at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:233) at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1369) at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:188) at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:489) at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1580) at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:186) at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1284) at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141) at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127) at org.eclipse.jetty.server.Server.handle(Server.java:501) at org.eclipse.jetty.server.HttpChannel.lambda$handle$1(HttpChannel.java:383) at org.eclipse.jetty.server.HttpChannel.dispatch(HttpChannel.java:556) at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:375) at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:272) at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:311) at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:103) at org.eclipse.jetty.io.ChannelEndPoint$1.run(ChannelEndPoint.java:104) at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.runTask(EatWhatYouKill.java:336) at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:313) at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.tryProduce(EatWhatYouKill.java:171) at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:129) at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:375) at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:806) at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:938) at java.lang.Thread.run(Thread.java:748)  
asked
3 answers
0

Instead of calling PictureParameter1.setContents(), try using the storeFileDocumentContent() method in the Core API. 

https://apidocs.rnd.mendix.com/8/runtime/com/mendix/core/Core.html#storeFileDocumentContent(com.mendix.systemwideinterfaces.core.IContext,com.mendix.systemwideinterfaces.core.IMendixObject,java.lang.String,java.io.InputStream)

Hope this helps

answered
0

Hi Matthias,

 

Were you ever able to complete the Java-action? This is exactly what I need for a client of mine.

answered
0

Hi Yordee,

 

the answer is yes and no. So I was able to handover a string and generate the picture. (actually a empty picture which is handed into the java action is filled with data). However, we never used the solution because we also wanted to hand over some picture as base64. But none of the java html renderer libaries I found was able to do the base64 rendering. 

 

But here is the coded we used (i think we played around wiht different html java liberaies but I have forgoten wich the others were….)

 

// This file was generated by Mendix Studio Pro.
//
// WARNING: Only the following code will be retained when actions are regenerated:
// - the import list
// - the code between BEGIN USER CODE and END USER CODE
// - the code between BEGIN EXTRA CODE and END EXTRA CODE
// Other code you write will be lost the next time you deploy the project.
// Special characters, e.g., é, ö, à, etc. are supported in comments.

package siedoc_2.actions;

import com.mendix.systemwideinterfaces.core.IContext;
import com.mendix.webui.CustomJavaAction;
import com.mendix.systemwideinterfaces.core.IMendixObject;
import gui.ava.html.image.generator.HtmlImageGenerator;
import java.awt.*;
import java.awt.image.RenderedImage;
import java.io.*;
import javax.imageio.ImageIO;
import com.mendix.core.*;
import java.awt.image.BufferedImage;
import javax.imageio.stream.*;

public class Test_Java_call3 extends CustomJavaAction<java.lang.Boolean>
{
	private java.lang.String Html_String;
	private IMendixObject __PictureParameter1;
	private siedoc_2.proxies.TestImage PictureParameter1;

	public Test_Java_call3(IContext context, java.lang.String Html_String, IMendixObject PictureParameter1)
	{
		super(context);
		this.Html_String = Html_String;
		this.__PictureParameter1 = PictureParameter1;
	}

	@java.lang.Override
	public java.lang.Boolean executeAction() throws Exception
	{
		this.PictureParameter1 = this.__PictureParameter1 == null ? null : siedoc_2.proxies.TestImage.initialize(getContext(), __PictureParameter1);

		// BEGIN USER CODE
		
		HtmlImageGenerator hig = new HtmlImageGenerator();
		
		hig.loadHtml(Html_String);	
		BufferedImage image = hig.getBufferedImage();
        BufferedImage bufferedImageToWrite = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_RGB);
        bufferedImageToWrite.createGraphics().drawImage(image, 0, 0, Color.WHITE, null);
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		ImageIO.write(bufferedImageToWrite, "png", baos);
		byte[] bytes = baos.toByteArray();
		
		
		
		//ImageInputStream targetStream = ImageIO.createImageInputStream(bufferedImageToWrite);
		//long l = targetStream.length();
		//int laenge = (int)l;		
		//byte[] temp = new byte[laenge];
		//targetStream.read(temp);
		InputStream targetStream1 = new ByteArrayInputStream(bytes);
			
		
		//hig.saveAsImage("hello-world.png");			
		//File imageFile = new File("hello-world.png");
		//InputStream targetStream = new FileInputStream(imageFile);		
		Core.storeFileDocumentContent( getContext(), PictureParameter1.getMendixObject(), targetStream1 );
		
		//PictureParameter1.setContents( getContext(), targetStream, imageFile.length());
		
		
		return true;
		// END USER CODE
	}

	/**
	 * Returns a string representation of this action
	 * @return a string representation of this action
	 */
	@java.lang.Override
	public java.lang.String toString()
	{
		return "Test_Java_call3";
	}

	// BEGIN EXTRA CODE
	// END EXTRA CODE
}

 

answered