UTFDataFormatException when trying to connect jvisualvm to an eclipse local process - java

I am trying to profile a local java application. It is run through Eclipse. I am using the jvisualvm corrsponding to my jdk installation. It sees the process when it is started, it can sample it without problem but when I try to start the profiler, the eclipse console shows this error :
Profiler Agent: Waiting for connection on port 5140 (Protocol version: 15)
Profiler Agent: Established connection with the tool
Profiler Agent Error: Exception when trying to send response or command to client:
java.io.UTFDataFormatException
java.io.UTFDataFormatException
at java.io.ObjectOutputStream$BlockDataOutputStream.writeUTF(ObjectOutputStream.java:2164)
at java.io.ObjectOutputStream$BlockDataOutputStream.writeUTF(ObjectOutputStream.java:2007)
at java.io.ObjectOutputStream.writeUTF(ObjectOutputStream.java:869)
at org.netbeans.lib.profiler.wireprotocol.VMPropertiesResponse.writeObject(VMPropertiesResponse.java:156)
at org.netbeans.lib.profiler.wireprotocol.WireIO.sendComplexResponse(WireIO.java:286)
at org.netbeans.lib.profiler.server.ProfilerServer.sendComplexResponseToClient(ProfilerServer.java:678)
at org.netbeans.lib.profiler.server.ProfilerServer.handleClientCommand(ProfilerServer.java:1559)
at org.netbeans.lib.profiler.server.ProfilerServer.listenToClient(ProfilerServer.java:1698)
at org.netbeans.lib.profiler.server.ProfilerServer.run(ProfilerServer.java:655)
Profiler Agent: Connection with agent closed
Profiler Agent: Connection with agent closed
When looking at the code, the writeUTF function throws this exception when the response is too long...
void writeUTF(String s, long utflen) throws IOException {
if (utflen > 0xFFFFL) {
throw new UTFDataFormatException();
}
...
}
Would someone have an idea about what happens here ?
Thanks.

This was likely caused by a VisualVM bug—now fixed—associated with long classpaths.

Related

Unable to open flight recorder in JMC for Java application and Eclipse IDE

When I try to run flight recorder it takes a very long time in loading and then crashes, and throws an exception after a while:
Connection refused to host: 17.226.xx.yyyy; nested exception is:
java.net.ConnectException: Operation timed out (Connection timed out)
java.lang.RuntimeException: Could not connect to [1.8.0_181] Eclipse
(2092). Make sure the JVM is running and that you are using the
correct protocol in the Service URL
(service:jmx:rmi://127.0.0.1/stub/rO0ABXN9AAAAAQAlamF2YXgubWFuYWdlbWVudC5yZW1vdGUucm1pLlJNSVNlcnZlcnhyABdqYXZhLmxhbmcucmVmbGVjdC5Qcm94eeEn2iDMEEPLAgABTAABaHQAJUxqYXZhL2xhbmcvcmVmbGVjdC9JbnZvY2F0aW9uSGFuZGxlcjt4cHNyAC1qYXZhLnJtaS5zZXJ2ZXIuUmVtb3RlT2JqZWN0SW52b2NhdGlvbkhhbmRsZXIAAAAAAAAAAgIAAHhyABxqYXZhLnJtaS5zZXJ2ZXIuUmVtb3RlT2JqZWN002G0kQxhMx4DAAB4cHc4AAtVbmljYXN0UmVmMgAADTE3LjIyNi4yMC4yMjQAAMF44tzu6CRJNeORCVrBAAABZN4+pbCAAQB4).
I have tried running different version of jdks: from java 7 to java 8:
jdk1.7.0_80.jdk
jdk1.8.0_141.jdk
jdk1.8.0_144.jdk
jdk1.8.0_162.jdk
jdk1.8.0_181.jdk
Also, uninstalled eclipse and installed back STS back. Still the issue is there. Looks like issue is somehwhere in jmc not able to connect to eclipse and/or tomcat jvm.
Anyone who has resolved similar issue please help on that. Thanks.
Update: I am able to record flights using command terminal by using
jcmd $pid JFR.start name=MyRecording settings=default duration=60s
jcmd $pid JFR.dump name=MyRecording filename=/tmp/test_TIMESTAMP.jfr
Still I am clueless why it would not run from gui.
I am able to open flight recorder now with a "hack".
To make it work I had to add -Djava.rmi.server.hostname=localhost vm arg in the server configs of my JEE application.

How to run Java Card Connected Edition Web samples on Eclipse?

I downloaded Java Card Connected Edition 3.0.2 from Oracle official website and installed it. There are some web samples in JCDK. In documentation written:
All samples must be run from within the NetBeans IDE. They cannot be run from
the command line in this release of the development kit.
Samples works with NetBeans IDE correctly. I can import them and run on Java Card Platform.
But I want to use this samples on Eclipse IDE. In Eclipse as Java Card SDK path I showed Java Card Connected home path. Then created new device and tried to start it [CardHolderApp for example]. But Eclipse gives:
ApduTool thread exited
User input thread exited
APDU|ApduTool [v3.0.2]
APDU| Copyright (c) 2009 Sun Microsystems, Inc.
APDU| All rights reserved.
APDU| Use is subject to license terms.
APDU|Opening connection to localhost on port 9025.
APDU|Connected.
APDU|java.net.ConnectException: Connection refused: connect
ApduTool process finished with code: 1
.log file:
!ENTRY org.eclipse.core.jobs 4 2 2015-09-08 01:39:17.142
!MESSAGE An internal error occurred during: "Launching CardHolderApp".
!STACK 0
java.lang.RuntimeException: Cannot start device. Please see the log.
at com.oracle.javacard.jcdk.launch.runconfiguration.AppletRunConfigurationDelegate.launch(AppletRunConfigurationDelegate.java:79)
at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:885)
at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:739)
at org.eclipse.debug.internal.ui.DebugUIPlugin.buildAndLaunch(DebugUIPlugin.java:1039)
at org.eclipse.debug.internal.ui.DebugUIPlugin$8.run(DebugUIPlugin.java:1256)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)
Is it possible to run Java Card Connected Web project in Eclipse IDE?
UPDATE:
Device started successfully. But project not deployed. It gives "unsupported String type constant" on every String usage.
Code example:
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
response.setContentType("text/html"); // unsupported String type constant
PrintWriter out = response.getWriter();
RequestDispatcher dispatcher = null;
dispatcher = request.getRequestDispatcher("/WEB-INF/header.i");//unsupported String type constant
response.sendRedirect(response.encodeRedirectURL("http://www.sun.com"));//unsupported String type constant
dispatcher.include(request, response);
dispatcher.include(request, response);
}
Classic Edition did not support Strings. But it must work on Connected Edition.
Forgetting about all the complicated software in between. Just looking at the error messages, it looks like port 9025 is not open or available on your localhost :
APDU|Opening connection to localhost on port 9025.
APDU|Connected.
APDU|java.net.ConnectException: Connection refused: connect
ApduTool process finished with code: 1
The text [java.net.ConnectException: Connection refused: connect], everytime I see "Connection refused" it means java tried to create a socket on the port (9025 in this case) and it could not get the port number either because of a blockage (like a firewall) or not available (something else is using port 9025).
On windows or *nix, you can usually use the netstat command to see what ports are being used.
hth, adym

Browser can't connect to Jetty server

I saw another question like this on StackOverflow, but the answers he got were pretty, rediculous. "Connect to the localhost." -- Like, okay.
Anyway, the problem is I finally got my embedded Jetty server to compile and run, the problem was since I'm using it in an API i needed the sources, instead of just the dependency.
I'm running the most basic hello-world code right now, and the server is starting, but none of my browsers can form a connection.
Here's the code:
try {
httpServer = new Server(8080);
httpServer.setHandler(new JettyPage());
httpServer.start();
} catch(Exception e) {
e.printStackTrace();
}
Naturally, here's JettyPage.java:
public class JettyPage extends AbstractHandler {
#Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException {
response.setContentType("text/html;charset=utf-8");
response.setStatus(HttpServletResponse.SC_OK);
baseRequest.setHandled(true);
response.getWriter().println("<h1>Hello world.</h1>");
}
}
The output in the console:
2014-11-07 07:01:05.155:INFO::main: Logging initialized #599ms
2014-11-07 07:01:05.190:INFO:oejs.Server:main: jetty-9.3.0.M1
2014-11-07 07:01:05.215:INFO:oejs.ServerConnector:main: Started ServerConnector#6e5e91e4{HTTP/1.1,[http/1.1]}{0.0.0.0:8080}
2014-11-07 07:01:05.215:INFO:oejs.Server:main: Started #660ms
Firefox:
The connection was reset
Opera:
No data received
Chrome:
No data received
--- Yes, I am connecting to localhost:8080
I've also tried: 0.0.0.0:8080 and 127.0.0.1:8080
Note: If I disable my apache server that's running on port 80, and bind Jetty to port 80, I still can't connect.
I had exactly the same problem...very simple code, couldn't get browser to connect to Jetty even though it compiled and ran from both command-line and IDE. Finally traced it down to mismatched servlet and Jetty jars (at least I think that caused the problem). The ones that worked for me were javax-servlet-api-3.1.0.jar and jetty-all-9.2.8.v20150217.jar. Once I started using those I could connect if the code was compiled at command-line or from NetBeans IDE.
For raw noobs like me, most of the online examples for command-line compile use Linux/Unix path separators (":"). It took me several minutes to figure out on a Windows machine I needed a different one (";"):
javac -cp .;javax.servlet-api-3.1.0.jar;jetty-all-9.2.8.v20150217.jar HelloWorld.java
Hope that helps.
If you followed the HelloWorld example exactly, you would have a response.
There is still something wrong with your runtime environment.
Is this windows you are running on? If so, try setting the port to something other than 8080 (try 38080), as you might have something already on that port, and Windows will not throw an error or warning in this situation. (on other OS's this would result in a bind exception)
Do you have any logging output that indicates an error or warning?
There should be plenty of logging output to the console, even when there is an error in starting up the server, or serving some content.
If you want to enable VERY verbose logging, you can add -Dorg.eclipse.jetty.LEVEL=DEBUG to your java execution.
Windows Version
> java -Dorg.eclipse.jetty.LEVEL=DEBUG -cp .;servlet-api.jar;jetty-all.jar HelloWorld
Linux / OSX / Unix Version
$ java -Dorg.eclipse.jetty.LEVEL=DEBUG -cp .:servlet-api.jar:jetty-all.jar HelloWorld

Selenium webdriver error when trying to lunch tests on a remote machine

I'm trying to run my web app tests using selenium on iE on a remorte machine. My tests run successfully locally but when I try to run them on a remorte XP OS using IE8, I get this log error : org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
Help please ! Thanks !
Possible causes are
Selenium Server Standalone is NOT started on the remote machine
Selenium Server Standalone is started BUT inside code wrong IP address is written
Follow the steps written below in order to get things work:
1) Download Selenium Server Standalone JAR file : http://selenium-release.storage.googleapis.com/2.40/selenium-server-standalone-2.40.0.jar in the remote machine (IP address of remote machine let say: 192.168.10.100)
2) From remote machine, run the following command to start Server Standalone:
java -jar selenium-server-standalone-2.40.0.jar
3) Ensure IEDriverServer path is also set in that machine. Information is avialble here: https://code.google.com/p/selenium/wiki/InternetExplorerDriver
4) After all the above setting done write following sample code to open IE in remote machine:
public class IERemoteWebDriver {
public static void main(String[] args) throws IOException {
// Assuming Remote machine IP address '192.168.10.100'
String remote_address = "http://192.168.10.100:4444/wd/hub";
URL remote_url = new URL(remote_address);
DesiredCapabilities dc = DesiredCapabilities.internetExplorer();
WebDriver wbdv = new RemoteWebDriver(remote_url, dc);
wbdv.navigate().to("https://www.google.com/");
}
}
This should work!
One possibly issue could be that your IE8 browser does not have Protected Enabled.
Open a new browser and then go to Tools->Internet Options->Security,
make sure all the zones have Enable Protected Mode selected.

maven jetty does not shutdown properly in eclipse

I am currently running jetty from eclipse as an external java program. The problem is when I terminate jetty and I try to relaunch it again, it cannot due to the port still being in use.
What I have to do is open up Windows Task Manager and kill the java process manually. How do you get jetty to shutdown/terminate/end nicely?
The following are my maven jetty application settings
Arguments: jetty:run-war
MAVEN_OPTS: -Xdebug -Xnoagent
-Djava.compiler=NONE -Xrunjdwp:transport=dt_socket, address=8080,server=y, suspend=y
Setting suspend=n doesn't seem to solve the problem either.
If a java application does not shutdown it is because of an alive non-daemon thread. Try getting a thread dump of the running maven process, e.g. using VisualVM and see what keeps the application alive.
You could run the application via the 'Run Jetty Run' Eclipse plugin, rather than the Maven jetty plugin. Eclipse has more direct control over the new JVM then.
I'm not familiar with the maven plug-in, but when starting jetty with start.jar, you can use stop.jar to have it shutdown gracefully (since version 4.something).
Stopping Jetty
Programs started with the start.jar mechanism may be stopped with the
stop.jar:
java -jar stop.jar
This connects via a local port to stop the server. The default port can be set
with the STOP.PORT system property
Source
Alternatively, and maybe more to your liking, you can do it within eclipse by writing a class like this, and running the main method:
package mypackage;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.Socket;
public class Stop {
public static final int PORT = 8079; //Change to whatever your port is, 8079 is default
public static void main(String[] args) throws Exception {
Socket s = new Socket(InetAddress.getByName("127.0.0.1"), PORT);
OutputStream out = s.getOutputStream();
System.out.println("*** sending jetty stop request");
out.write(("\r\n").getBytes());
out.flush();
s.close();
}
}
Source
It seems that I forgot to tick "Allow termination of remote VM". Strange that it didn't seem to work before.

Categories