With Java actions, you can extend the functionality of your application in situations where it would be hard to implement this functionality in microflows.
For information about Java actions in Studio Pro, see Java Actions.
2 Writing Code in the .java Files of Your Java Actions
In the java files of your Java actions, you can write your Java code between the markers:
// BEGIN USER CODEand
// END USER CODE
// BEGIN EXTRA CODEand
// END EXTRA CODE
This is explained in more detail below.
The other code in these files is regenerated each time when you deploy your model, thus any modifications that you make in them will be overwritten. However, your imports will be preserved.
A Java action generated by Mendix Studio Pro. This Java action has no input parameters and simply returns a Boolean with value
The method executeAction is called by the Runtime when the Java action is being executed. Between the lines
// BEGIN USER CODE and
// END USER CODE, you can write your custom code that will always be called when executing the action. In this method, you can call other methods in the section between
// BEGIN EXTRA CODE and
// END EXTRA CODE.
The executeAction method throws all exceptions that occur. This means you can do error handling in the microflow calling this Java action. If you would like to do your own error handling within the action, use try/catch statements.
3 Using the Mendix Java library
In the Java code that you write for your Java actions, you can use the Mendix Java library.
You can find the Javadoc at apidocs.rnd.mendix.com or in the directory you in which installed Mendix (for example, C:\Program Files\Mendix\8.0.0\runtime\javadoc).
This library is automatically added to your libraries when you imported your project into Eclipse, and it is called mxruntime.jar.
For details on usage and example, see How to Use the Java API.
4 Opening HTTP Connections
Most cloud infrastructure services (including those used by the Mendix Cloud) will close HTTP connections automatically if there is no traffic for a few minutes, even if your activity is still waiting for a response. This means that, if your activity calls a web service which takes a long time to respond, the connection may be closed without the activity being aware of this and your activity will not receive a response, but instead get stuck waiting indefinitely for data to arrive.
You should therefore ensure that you always set a timeout for any connections you make in your custom Java code.
5 Using Eclipse as an Environment to Write Your Mendix Java Actions
For details on this topic, see Using Eclipse.
6 Java Actions in the Cloud
For details on this topic, see V3: Java in Mendix Cloud.