I'm currently using a Java library via jni4net in a C# application running on IIS Express, and the Java library is throwing an exception. Is it possible to attach a debugger to debug the Java code?
Attempt:
I tried to add the following to the JVM options as per the instructions provided by IntelliJ:
setup.AddJVMOption("-agentlib", "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005");
but get an exception:
Unable to open debugger port : java.net.ConnectException "Connection refused: connect"
By setting the AddJVMOption-String to:
setup.AddJVMOption("-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=1044");
I am able to connect to the jni4net part via Eclipse, maybe you should just omit the first argument ("-agentlib", ...)
When I use setup.AddJVMOption("-agentlib", "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005");
I get an Exception in CreateJVM
Related
I have a remote MongoDB that I need to connect to. I have all the credentials, but when trying to connect from gradle with this.mongoClient = MongoClients.create(dbConnectionString);, I get following error:
java.io.UncheckedIOException: java.net.SocketException: Network is unreachable
at java.base/sun.nio.ch.DatagramSocketAdaptor.disconnect(DatagramSocketAdaptor.java:136)
at java.base/java.net.DatagramSocket.disconnect(DatagramSocket.java:393)
at jdk.naming.dns/com.sun.jndi.dns.DnsClient.doUdpQuery(DnsClient.java:437)
at jdk.naming.dns/com.sun.jndi.dns.DnsClient.query(DnsClient.java:214)
at jdk.naming.dns/com.sun.jndi.dns.Resolver.query(Resolver.java:81)
at jdk.naming.dns/com.sun.jndi.dns.DnsContext.c_getAttributes(DnsContext.java:434)
at java.naming/com.sun.jndi.toolkit.ctx.ComponentDirContext.p_getAttributes(ComponentDirContext.java:235)
at java.naming/com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.getAttributes(PartialCompositeDirContext.java:141)
at java.naming/com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.getAttributes(PartialCompositeDirContext.java:129)
at java.naming/javax.naming.directory.InitialDirContext.getAttributes(InitialDirContext.java:171)
at com.mongodb.internal.dns.DefaultDnsResolver.resolveAdditionalQueryParametersFromTxtRecords(DefaultDnsResolver.java:114)
at com.mongodb.ConnectionString.<init>(ConnectionString.java:381)
at com.mongodb.client.MongoClients.create(MongoClients.java:61)
at io.my.package.dbsetup.DatabaseService.<init>(DatabaseService.java:28)
When I print the connectionString and run mongo $connectionString in terminal, I can connect with no problems. Even MongoDB Compass works. It's just Gradle that doesn't.
My colleague with Ubuntu (I have a Mac) can connect with no issues when running the same code. What could be causing this? Firewall is off.
Turns out I needed to use different Java version - 16 didn't work, but I had luck with 8
I'm running a Java server (Jetty, to be specific) on an AWS EC2 instance using WebSocket to connect to a client's browser. When I do this locally (hosting the server on my computer, not AWS), it runs fine. However, when I move the code to an EC2 instance, I get the following error message on the client-side:
WebSocket connection to 'ws://Elastic_IP:8080/?username=name_of_user' failed: Error during WebSocket handshake: Unexpected response code: 500
I made sure that the EC2 instance will accept traffic on port 8080.
On the server-side, I'm getting many java.lang.NoClassDefFoundError when the connection is attempted. I do not get these error when I run it locally. Perhaps there's an issue when I'm compiling on the EC2 instance, however it does compile without error. I'm compiling and running the code using Eclipse locally, but I'm compiling and running the code on EC2 by hand (javac with lots of classpaths). It's likely that I made an error when compiling by hand, but I'm not sure what the error could be.
Any help would be greatly appreciated.
EDIT
After a little trouble-shooting on my own, I realized that JSON.ParseException was the source of issue. After I removed all calls to this class from the server code, the handshake completed and I was able to establish a connection between the server and the client.
However, I am now running into the following error when I receive a message from the client:
WARN:MyWebSocketHandler:qtp990368553-16: Unhandled Error (closing connection)
java.lang.RuntimeException: Cannot call method public void
MyWebSocketHandler#onMessage(org.eclipse.jetty.websocket.api.Session, java.lang.String) with args:
[org.eclipse.jetty.websocket.common.WebSocketSession, java.lang.String]
It seems that I defined the argument to be org.eclipse.jetty.websocket.api.Session, but during runtime the argument is actually org.eclipse.jetty.websocket.common.WebSocketSession. Any ideas on how this is happening or which one (Session vs WebSocketSession) I should use? The only capability I need is to send strings between the server and the client.
I figured out a possible solution to my problem. Through Eclipse, I can Export the Java project to a runnable jar ("packing" the libraries into the jar). Then running it with java -jar <jar_filename> will work on the server and function the same as on the local machine. However, I've notice some performance issues (slow start), so I do not think this is the best solution, however it is a solution.
So i was going to debug my Solr filter plugins on Intellij Community Edition. After i ran the program from comand prompt with this command
java -jar start.jar -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=8983
I started my Intellij debugger with this config:
Transport : socket
Debugger mode : attach
Host : localhost
Port : 8983
But when I ran the debugger I got this error:
Error running Debugger: Unable to open debugger port (localhost:8983):
java.io.IOException "handshake failed - connection prematurally closed"
Any idea how to fix this?
I got that error when trying to access to debug port on a Docker container.
If you are trying to access the debug port inside a Docker container make sure you are specifying the port as *:5005
E.g.
-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005
This has been changes since Java 9.
See: REGRESSION: Remote debugging does not work on JDK 9
It's not a bug. It's a security.
Before the JDK-8041435
If you have a server with EXT and INT interfaces and start Java process with address=5900 it binds to both interfaces and allow anybody from entire world to connect to your java process unless you block it on firewall.
After JDK-8041435 socket transport try to guess localhost and bind to localhost only. I.e. socket transport by default works only if both client and server are located on the same machine. It's not an easy task to guess proper localhost. so ever same-machine configuration might not work in some situation because of network setup.
You can restore old, insecure behavior using * (asteric)
i.e.
-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5900
should work exactly as it was before JDK-8041435
But it's recommended to explicitly specify ip address to bind when it possible.
And JDWP socket connector accept only local connections by default
The JDWP socket connector has been changed to bind to localhost only if no ip address or hostname is specified on the agent command line. A hostname of asterisk (*) may be used to achieve the old behavior which is to bind the JDWP socket connector to all available interfaces; this is not secure and not recommended.
It should be something like this,
java "-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=8983" -jar start.jar
it's working now
I had this error with OpenJDK 11 inside Docker container and setting environment variable JAVA_DEBUG_PORT to "*:5005" worked for me.
You forgot to specify -Xdebug on the java command line.
Edit: As in
java -jar start.jar -Xdebug -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=8983
It has helped me, at least in Intellij IDEA:
java -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=0.0.0.0:5005
try to add ip 0.0.0.0.
I have a Java application which I am in the process of converting to work with WebStart. It is supposed to connect to a server to do some authentication using Naming.lookup and this works fine when running as a standalone app. Unfortunately when running the same code as a WebStart app the call fails and throws:
java.rmi.ConnectIOException: error during JRMP connection establishment; nested exception is:
java.io.EOFException
This indicates an error at the Registry, possibly a security problem. You need to run the Registry with some debugging parameters to see what, such as -Djava.rmi.server.logCalls etc. See the properties pages linked from the RMI Home Page.
I'm trying to get my Java code in Eclipse to access the internet, through an authenticated proxy. My code is simply reading a website source using http://docs.oracle.com/javase/tutorial/networking/urls/readingURL.html
I get this error:
Exception in thread "main" java.net.ConnectException: Connection timed out: connect
Here are the things I already tried:
- In Preferences, setting the HTTP and HTTPS proxy, clearing SOCKS, and going to Manual
- In Eclipse.ini, adding
-Dorg.eclipse.ecf.provider.filetransfer.excludeContributors=org.eclipse.ecf.provider.filetransfer.httpclient
-Dhttp.proxyPort=8080
-Dhttp.proxyHost=XXX
-Dhttp.proxyUser=XXX
-Dhttp.proxyPassword=XXX
-Dhttp.nonProxyHosts=localhost|127.0.0.1
You need to be aware that what you are setting, is the settings for the JVM in which Eclipse runs. Your programs are started in another JVM where these settings do not apply.
Running your application creates a launch configuration, which you can open and add the system properties you need. They will then apply when that launch configuration is launched.
(also, Eclipse has a very elaborate network settings panel in the preferences window where you can configure this for Eclipse itself).