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

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

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.

UTFDataFormatException when trying to connect jvisualvm to an eclipse local process

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.

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

Unable to start Neo4j on Windows, no error messages

I'm using the following on Windows 7:
neo4j-community-1.9.2
Java 7 Update 25
I have Windows Firewall disabled.
When I start Neo4j.bat, both as Administrator and normally, I get the following message:
c:\Tools\neo4j\bin>Neo4j.bat
28/07/13 9:34:27 PM org.neo4j.server.AbstractNeoServer INFO: Setting startup tim
eout to: 120000ms based on -1
A blank Java console window pops up, no messages, then the window disappears after a minute or so.
When I go to http://localhost:7474/, I just get a server not found error.
If I try to install it as a service, the service wouldn't start.
Any ideas what I need to do to start Neo4j? I see here that Neo4j 1.9 does support Java 7:
http://blog.neo4j.org/2013/03/neo4j-19m05-released-wrapping-up.html
base.bat correctly points to windows-service-wrapper-5.jar, so not the windows-service-wrapper-*.jar problem that some people have had in the past. It would be helpful if it outputted an error message.
I just tried it with neo4j 2.0 milestone, and it didn't make any difference. The Java window pops up with no messages, http://localhost:7474/ gets a server not found error, then the Java window closes after a minute or two.
I added JAVA_HOME and JRE_HOME system variables, made no difference. I think I would get an error if Neo4j was not able to locate Java anyway.
I've fixed it.
With help from Neo4j's Google Group, I looked at the logs in data/logs/*.log and data/graph.db/messages.log, and found the following exception:
Caused by: java.rmi.server.ExportException: Port already in use: 1337; nested exception is:
java.net.BindException: Address already in use: JVM_Bind
Once I disabled my other service that uses that port, Neo4j's web admin at http://localhost:7474 worked. I then found out port 1337 is used by Neo4j's remote shell, I disabled it by adding enable_remote_shell = false to neo4j.properties, then I was able to have both Neo4j and my other service running.
I'm using the version 2.2.1 community edition of Neo4j on Windows 7, Java 1.8 update 45
In my case the log file messages.log was under default.graphdb directory. In there, you'll see the root cause of the problem.

Eclipse : Failed to connect to remote VM. Connection refused. [duplicate]

This question already has answers here:
Eclipse Error: "Failed to connect to remote VM"
(26 answers)
Closed 9 years ago.
When ever i tried to launch my eclipse debug(for server side code) i'm getting the following error Failed to connect to remote VM. Connection refused.
What's the problem may be? I already tried with most of the solutions out in the web but none of that solved my issue. Could any one can assist me to fix this? Advance thanks..
when you have Failed to connect to remote VM Connection refused error, restart your eclipse
Which server are you using?
Like already said:
In your debug configuration you'll have to define the right port of your server (GF:9009 / Tomcat:8000)
You'll have to set the JVM property of the server to debug
For Glassfish:
Log in to admin-console > Configurations > server-config > JVM-Settings > check DEBUG checkbox > restart server
For Tomcat:
create file debug.bat/.sh (depending on your OS) in %TOMCAT_HOME%/bin directory and write
set JPDA_ADDRESS=8000
set JPDA_TRANSPORT=dt_socket
catalina.bat jpda start
in it.
After you've created this file start server by executing debug.bat/.sh.
Now you should be able to debug remotely in Eclipse after you set the necessary properties in your debug configuration.
Hope this helped! Have Fun!
EDIT
If you're running tomcat in a Win environment as a service you don't have a catalina.bat file in the bin-directory of your tomcat installation.
To set your server into debug-mode please try the following:
Run the Configuration option in Windows Menu or run %catalina_home%/bin/tomcat6w.exe
In Java tab, add this line to Java:
options:-Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n
Sometimes the port which you are trying to access, gets occupied and won't be released.
Try some tools to find whether the port is in use or not.
I also faced the same issue. I tried giving different port numbers but unfortunately it didn't work. I tried restarting the system (not the application server), and it worked :)
I faced the same issue. But i resolved it by changing my port numbers to different one.
The port number in the Eclipse configuration and the port number of
your application might not be the same.
You might not have been started your application with the right
parameters.
Those are the simple problems when I have faced "Connection refused" error.
As suat said, most of the time the connection refused is due to the fact that the port you set up is in use or there is a difference between the port number in your remote application debugging configuration in Eclipse and the port number used in the address attribute in
-Xrunjdwp:transport=dt_socket,address=1044,server=y,suspend=n.
Check those things. Thanks!
If you need to debug an application working on Tomcat, make sure that your Tomcat-folder/bin/startup.bat (if using windows) contains the following lines:
set JPDA_TRANSPORT="dt_socket"
set JPDA_ADDRESS=8000
call "%EXECUTABLE%" jpda start %CMD_LINE_ARGS%
I ran into this problem debugging play framework version 2.x, turned out the server hadn't been started even though the play debug run command was issued. After a first request to the webserver which caused the play framework to really start the application at port 9000, I was able to connect properly to the debug port 9999 from eclipse.
[info] play - Application started (Dev)
The text above was shown in the console when the message above appeared, indicating why eclipse couldn't connect before first http request.

Categories