Technical Articles
Remote Debugging on Cloud Foundry
As we know that everything is moving to Cloud. And it has become a bottleneck for a developer to debug the application/ code on Cloud. In this article I will share how you can debug your applications directly deployed on Cloud Foundry.
Prerequisites:
- IntelliJ IDEA : I would recommend community version if you don’t have a license.
- Application should be deployed on Cloud Foundry.
- You should have the same code base in local, which is deployed on Cloud Foundry.
Steps:
- Add below property in your mta.yaml for your module under property section:
- JBP_CONFIG_JAVA_OPTS: “[from_environment: false, java_opts: ‘-Xms1300M -XX:NewSize=950M -Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=8000,suspend=n’]”
- JBP_CONFIG_JAVA_OPTS: “[from_environment: false, java_opts: ‘-Xms1300M -XX:NewSize=950M -Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=8000,suspend=n’]”
- Open the command prompt (if you are using windows)/ Terminal(in case of Linux/Unix).
- Login to Cloud Foundry.
- cf login -a https://api.cf.sap.hana.ondemand.com (Canary Landscape).
- cf login -a https://api.cf.eu10.hana.ondemand.com (Live Landscape).
- Navigate to your space where your application is deployed.
- You can use this command to navigate: cf target -o <organisation name> -s <space name>
- After successfully navigating to space, you need to enable the ssh-tunnel for the application you want to debug.
- cf enable-ssh <application name>
- Just to be sure, run the below command to see whether ssh is enabled for your application or not.
- cf ssh-enabled <application name>
- Restage your application.
- cf restage <application name>
- After successfully restaging the application run the below command.
- cf ssh -N -T -L 8000:localhost:8000 <application name>
- Open IntelliJ IDEA and import your project.
- Click on the Add Configuration to the top right corner as show in the picture below.
- Now click on the “+” button and choose “Remote”.
- After clicking on Remote you will another window. Set the pot as “8000” and “main” in “Use module classpath”.
- Now click “Ok” and Click on Debug icon on the top right corner.
- After clicking on the debug icon, you will see “Connected ” in the console of IntelliJ.
- Put the debug points in the desired file.
Now you are ready to debug your application. You can open your application and you will get a hit on your breakpoints.
Happy Debugging.
Note: Please let me know if you are facing some issues.
Thanks,
Achal Kansal
If your needs tend toward Python and/or eclipse you might want to check out this post.
The underlying mechanism of a reverse tunnel to a debugging server running local is the same.
https://blogs.sap.com/2018/12/11/setting-up-a-python-development-environment-for-hana-with-remote-debugging/
-Andrew
Hi Kansal,
I have been working on debugging. If i try to connect to SAP, it is succeeding. But if i try with debugger i am seeing the following error:
Error running ‘remote debug’: Unable to open debugger port (localhost:5005): java.net.ConnectException “Connection refused: connect”
Thanks.
Hi satish,
You have to give 8000 as port number in intellj
Thanks,
Hi Achal,
We tried setting up remote debugging in IntelliJ and face the same error as above.
Error running 'remoteDebugg': Unable to open debugger port (localhost:8000): java.net.ConnectException "Connection refused: connect"
We tried with both options of DebuggerMode but still faced errors.
Attach to Remote : Error running 'remoteDebugg': Unable to open debugger port (localhost:8000): java.net.SocketException "Connection reset" if chosen Attach to remote JVM
Listen to Remote JVM: Error running 'remoteDebugg': Unable to open debugger port (localhost:8000): java.net.BindException "Address already in use: NET_Bind" if chosen Listen to remote JVM
P.N: In second case there was nothing running in the port.
IntelliJ_Config
What would be the analogous configuration for a Node application?
In the package json, under npm scripts, give the "start" command as "node --inspect <app.js>"
You can find more details here
https://sap.github.io/cloud-sdk/docs/js/guides/remote-debugging
https://blogs.sap.com/2020/11/23/debugging-nodejs-application-in-vscode-running-on-sap-cloud-foundry/
Basically something like this
Hello,
The Application which I am trying to debug has the user variables maintained as=> JRE11. Currently remote debugging works in case of java8 but I am not able to debug for this configuration. Do I need to follow some additional steps to debug for this app.
Thanks
There is a slight change if you're using standard SAPMachine JDK and standard Java community buildpack
SAPMachine JDK: Has a standard debugger enabled by default. So we can control it whether to enable or disable it.
This link may be helpful to please refer it
https://help.sap.com/docs/btp/sap-business-technology-platform/debug-java-web-application-running-on-sapmachine?locale=en-US