5

I want to attach the Debugger to my deployed WARs in my dockerized WebLogic 12c. I use this official image of WebLogic (which is a Linux container) https://hub.docker.com/_/oracle-weblogic-server-12c and I start the container using docker command:

docker run -d -p 4002:4002 -p 9002:9002 
-v c:/my-path-to-shared-volume:/u01/oracle/properties 
-e ADMINISTRATION_PORT_ENABLED=true -e DOMAIN_NAME=docker_domain 
-e JAVA_TOOL_OPTIONS=\"-agentlib:jdwp=transport=dt_socket,address=4002,server=y,suspend=n\" 
--name weblogic store/oracle/weblogic:12.2.1.3-dev-200109

The weblogic console comes alive at https://localhost:9002/console/ but when trying to run the debugger, my IDE says:

Unable to open debugger port (localhost:4002): java.io.IOException "handshake failed - connection prematurally closed"

My OS is Windows10. I tried with Visual Studio Code and IntelliJ, and got the same output. The WARs run just fine and they respond when I use portman to hit some service endpoints.

What seems to happen is that weblogic start scripts inside the container tries to apply the Java Options param twice! Please see the relative parts of container output below:

Domain Home is: /u01/oracle/user_projects/domains/docker_domain Picked up JAVA_TOOL_OPTIONS: "-agentlib:jdwp=transport=dt_socket,address=localhost:4002,server=y,suspend=n" Listening for transport dt_socket at address: 4002 Initializing WebLogic Scripting Tool (WLST) ... Welcome to WebLogic Server Administration Scripting Shell

[...](and further down in the logs I get: )

Starting WLS with line: /usr/java/jdk-8/bin/java -server -Djava.security.egd=file:/dev/./urandom -cp /u01/oracle/wlserver/server/lib/weblogic-launcher.jar -Dlaunch.use.env.classpath=true -Dweblogic.Name=AdminServer -Djava.security.policy=/u01/oracle/wlserver/server/lib/weblogic.policy -Djava.system.class.loader=com.oracle.classloader.weblogic.LaunchClassLoader -javaagent:/u01/oracle/wlserver/server/lib/debugpatch-agent.jar -da -Dwls.home=/u01/oracle/wlserver/server -Dweblogic.home=/u01/oracle/wlserver/server weblogic.Server Picked up JAVA_TOOL_OPTIONS: "-agentlib:jdwp=transport=dt_socket,address=localhost:4002,server=y,suspend=n" ERROR: transport error 202: bind failed: Address already in use ERROR: JDWP Transport dt_socket failed to initialize, TRANSPORT_INIT(510) JDWP exit error AGENT_ERROR_TRANSPORT_INIT(197): No transports initialized [debugInit.c:750] Stopping Derby server... Derby server stopped.

I then tried to work with docker-compose, creating a .yaml file to add my environmental props there, trying to prevent these from running twice. I got the exact same behavior. Whichever port I use, it is found Already in use.

This is my .yaml file

version: '2'
services:
  weblogic:
    container_name: weblogic_yamled
    image: store/oracle/weblogic:12.2.1.3-dev-200109
    ports:
        - "7001:7001"
        - "7002:7002"
        - "4002:4002"
        - "4003:4003"
        - "9002:9002" 
    volumes:
        - c:/my-path-to-shared-volume:/u01/oracle/properties
    environment:
        - ADMINISTRATION_PORT_ENABLED=true
        - DOMAIN_NAME=docker_domain
        - JAVA_TOOL_OPTIONS="-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=localhost:4002"

Finally, I tried transport=dt_shmem but then I got a different error:

ERROR: transport library not found: dt_shmem

Do not know what else I should try!

JohnPan
  • 1,185
  • 11
  • 21

6 Answers6

1

Try adding address=*:4002 instead of address=4002

Akshay Shah
  • 704
  • 4
  • 11
  • Thx for answer. Same behavior: java.io.IOException "handshake failed - connection prematurally closed" – JohnPan Apr 30 '20 at 07:53
1

JAVA_OPTS is a Tomcat specific environment variable

In Java 8 the JDK supports a JAVA_TOOL_OPTIONS environment variable so to enable the debugger. Try replace JAVA_OPTS with JAVA_TOOL_OPTIONS

You also have to setup the address like this: address=*:8000, address=localhost:4002 or address=0.0.0.0:4002

Vargan
  • 1,277
  • 1
  • 11
  • 35
  • Yes, I tried all address=localhost:4002, address=*:4002 and address=4002 – JohnPan May 05 '20 at 14:39
  • I've edited my answer, that might solve your problem @JohnPan – Vargan May 05 '20 at 15:24
  • Thanks for the update. It still won't connect but I will update me question with new findings – JohnPan May 06 '20 at 08:14
  • I did the update. Pls note that none of the multipitch address syntax is accepted. So I stick with `address=4002` – JohnPan May 06 '20 at 08:26
  • @JohnPan, have you tried run docker with `docker run -d -p 9002:9002` – Vargan May 06 '20 at 09:11
  • If you mean without exposing the 4002 via the -p param, yes I did. Same error: `bind failed: Address already in use`. If you read the logs you can tell that it is the JavaOpts that runs two times – JohnPan May 06 '20 at 09:31
  • Haven't used weblogic in ages. If memory serves right, there should be a catalina.sh, maybe you can have a look inside it and see how it starts the call? Also, have you tried changing port? – Vargan May 06 '20 at 11:02
1

I had a similar issue with attaching a memory monitoring tool (JVisualVM). I could telnet to the server but that was not the whole story.

From what I have understood what was blocking me was the RMI connection used under the hoods. What was missing was a "tunnel" between client (where your debugger runs) and host (where your application runs) machine.

In windows you would open a cmd and give:

putty.exe -ssh <username>@<remote-host> -L <port>:<remote-host>:<same_port_again>

This will open a putty window which should remain open after logging in for the tunnel to remain open.

For more information on this, you can check here on the 2nd step of the solution provided by @freedev.

I am not sure if it works for you but I suspect it may be the same case as mine.

Lucky Luke
  • 147
  • 2
  • 2
  • 9
1

The problem is that the WebLogic server in the container is configured to run in production mode (the value of the PRODUCTION_MODE variable in the script setDomainEnv.sh is set to "true").

To disable this You need open the file setDomainEnv.sh, find PRODUCTION_MODE="true" and change it to PRODUCTION_MODE="false".

You also don't need to set JAVA_TOOL_OPTIONS variable, setDomainEnv.sh script already has the possibility to start in debug mode. To enable the debug mode, the environment variable “debugFlag” needs to be set to true before executing the script.

Docker command:

docker run -d --name weblogic -p 7001:7001 -p 9002:9002 -p 55195:55195 
-v c:/my-path:/u01/oracle/properties 
-e ADMINISTRATION_PORT_ENABLED=true -e DOMAIN_NAME=base_domain 
-e debugFlag=true -e DEBUG_PORT=55195 
store/oracle/weblogic:12.2.1.3

Note, I also change the debug port to 55195.

bravo1
  • 51
  • 6
0

Have you tried using the port number + 3 (4005) instead? That's a common practice to have a separate debug port for containerized applications

0

use -Xrunjdwp:transport instead of -agentlib:jdwp=transport

-Xdebug -Xrunjdwp:transport=dt_socket,address=*:8787,server=y,suspend=n
Egon
  • 36
  • 2