i have this java web application running on 4 servers.
The newest server ( just setting up ) is failing with the error
"java.lang.NoSuchMethodError: org.htmlparser.lexer.Lexer.parseCDATA()Lorg/htmlparser/Node"
when running the code below.
I have 1 server is running locally on my mac.
2 servers are running Centos 6.10 / java 1.8.0_242 / tomcat-8.5.54
The newest server (the one that is failing ) is running Centos 6.10 / java 1.8.0_242 / tomcat-8.5.54
i have copied all the jars from the working Centos server to the broke one
I am at a loss. Would love to hear some ideas on how to debug/resolve this....
The Code running is pretty simple
Another part that also confuses me, is if the jar was not found wouldnt Parser.createParser blow up and i have added debug code to make sure parser_c is not null
import org.htmlparser.Node;
import org.htmlparser.Parser;
import org.htmlparser.tags.ImageTag;
import org.htmlparser.tags.LinkTag;
import org.htmlparser.util.ParserException;
public class SignatureTools {
public static String getURLFromSignature(String signature) throws ParserException {
System.out.println("[getURLFromSignature]");
if ( signature == null ){ return null;}
Parser parser_c = Parser.createParser(signature, null);
Node nodes_c[] = parser_c.extractAllNodesThatAre(LinkTag.class);
String mkURL = null;
for (Node node : nodes_c) {
if (node != null && node instanceof LinkTag && ((LinkTag) node).getAttribute("href") != null) {
String href = ((LinkTag) node).getAttribute("href");
if ( href.contains("https://www.thedomain.com") ){
mkURL = href;
}
}
}
return URL;
}
}
found the problem..
i used this bit of code and found that Lexer was being loaded from a different jar instead of htmllexer.jar
Lexer lexer = new Lexer();
try {
System.out.println( "Lexer---->" + new File(Lexer.class.getProtectionDomain().getCodeSource().getLocation().toURI()).getPath());
} catch (URISyntaxException e) {
e.printStackTrace();
}
Related
My Java program (see below) sometimes crashes with a java.nio.file.AccessDeniedException in a java.nio.File.move() method execution.
I could not understand why this exception is thrown and I have no bypass for now.
Here is an example of the exception :
java.nio.file.AccessDeniedException: C:\PROJECTS\PROJECT0\CHANGES -> C:\PROJECTS\PROJECT0\GEN70\CHANGES
at sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:95)
at sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:109)
at sun.nio.fs.WindowsFileCopy.move(WindowsFileCopy.java:399)
at sun.nio.fs.WindowsFileSystemProvider.move(WindowsFileSystemProvider.java:299)
at java.nio.file.Files.move(Files.java:1406)
at com.ibm.cldt.engine.tool.TestMove.generate(TestMove.java:75)
at com.ibm.cldt.engine.tool.TestMove.createAndUseProject(TestMove.java:42)
at com.ibm.cldt.engine.tool.TestMove.main(TestMove.java:25)
Here the problem is detected on "GEN70" of "PROJECT0", but, it varies. For example, here is another run :
java.nio.file.AccessDeniedException: C:\PROJECTS\PROJECT2\CHANGES -> C:\PROJECTS\PROJECT2\GEN33\CHANGES
Note : before running the program, you have to delete the directory C:/PROJECTS if you have one.
What can I do to prevent my program from throwing this exception ?
I run this code on Windows 10 Enterprise, and an IBM JRE 1.8.
java version "1.8.0"
Java(TM) SE Runtime Environment (build pwa6480sr4fp5-20170421_01(SR4 FP5))
IBM J9 VM (build 2.8, JRE 1.8.0 Windows 10 amd64-64 Compressed References 20170419_344392 (JIT enabled, AOT enabled)
J9VM - R28_20170419_1004_B344392
JIT - tr.r14.java_20170419_344392
GC - R28_20170419_1004_B344392_CMPRSS
J9CL - 20170419_344392)
JCL - 20170420_01 based on Oracle jdk8u131-b11
Here is the code. You can run it as Java standalone application. Before launching, check that you do not have a C:/PROJECTS directory.
I will be surprised if the program execution ends without exception on your machine. If that is the case, please retry ...
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
public class TestMove
{
private static final String PROJECTS_ROOT = "C:/PROJECTS";
private static final int NUMBER_OF_PROJECTS = 10;
private static final int NUMBER_OF_GENERATIONS = 100;
private static final int NUMBER_OF_CHANGES = 10;
public static void main( String[] args )
{
try
{
for ( int project = 0; project < NUMBER_OF_PROJECTS; ++project )
{
createAndUseProject( "PROJECT"+project );
}
}
catch ( IOException ioe )
{
ioe.printStackTrace();
}
}
private static void createAndUseProject( String projectName ) throws IOException
{
Path projectRoot = Paths.get( PROJECTS_ROOT, projectName );
Files.createDirectories( projectRoot );
for ( int generation = 0; generation < NUMBER_OF_GENERATIONS; ++generation )
{
addNewChanges( projectRoot );
generate( projectRoot, generation );
}
}
private static final StandardOpenOption[] CREATE_APPEND =
new StandardOpenOption[] { StandardOpenOption.CREATE, StandardOpenOption.APPEND };
private static void addNewChanges( Path projectRoot ) throws IOException
{
Path changesDir = projectRoot.resolve( "CHANGES" );
Files.createDirectory( changesDir );
String newLine = System.lineSeparator();
Path changesLogFile = changesDir.resolve( "changes.log" );
try ( BufferedWriter changesWriter = Files.newBufferedWriter( changesLogFile, CREATE_APPEND ) )
{
for ( int change = 0; change < NUMBER_OF_CHANGES; ++change )
{
changesWriter.append( "This is my change number "+ change ).append( newLine );
}
}
}
private static void generate( Path projectRoot, int generation ) throws IOException
{
Path generationDir = projectRoot.resolve( "GEN"+generation );
Files.createDirectory( generationDir );
Path projectChangesDir = projectRoot.resolve( "CHANGES" );
Path generationChangesDir = generationDir.resolve( "CHANGES" );
// Here is the problem : AccessDeniedException is thrown ... sometimes.
Files.move( projectChangesDir, generationChangesDir );
Path changesLogFile = generationChangesDir.resolve( "changes.log" );
try ( BufferedReader changesReader = Files.newBufferedReader( changesLogFile ) )
{
for ( String change = changesReader.readLine(); change != null; change = changesReader.readLine() )
computeChange( change );
}
}
private static void computeChange( String change )
{
// Do whatever needed ...
}
}
What can I do to prevent my program from throwing this exception ?
COMPLEMENTS
From the first answers, I downloaded the Oracle JDK 1.8.0_221 from Oracle website. Then, I used javac and java commands to compile and run my program from a CMD window.
Here is the transcript:
Microsoft Windows [Version 10.0.18362.356]
(c) 2019 Microsoft Corporation. All rights reserved.
C:\tmp\Java>dir
Volume in drive C is Windows
Volume Serial Number is 8A56-3036
Directory of C:\tmp\Java
09/24/2019 06:57 PM <DIR> .
09/24/2019 06:57 PM <DIR> ..
09/24/2019 06:54 PM 2,678 TestMove.java
1 File(s) 2,678 bytes
2 Dir(s) 353,415,393,280 bytes free
C:\tmp\Java>"C:\Program Files\Java\jdk1.8.0_221\bin\javac" TestMove.java
C:\tmp\Java>"C:\Program Files\Java\jdk1.8.0_221\bin\java" TestMove
java.nio.file.AccessDeniedException: C:\PROJECTS\PROJECT0\CHANGES -> C:\PROJECTS\PROJECT0\GEN97\CHANGES
at sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:83)
at sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:97)
at sun.nio.fs.WindowsFileCopy.move(WindowsFileCopy.java:387)
at sun.nio.fs.WindowsFileSystemProvider.move(WindowsFileSystemProvider.java:287)
at java.nio.file.Files.move(Files.java:1395)
at TestMove.generate(TestMove.java:73)
at TestMove.createAndUseProject(TestMove.java:40)
at TestMove.main(TestMove.java:23)
C:\tmp\Java>
Same problem with a standard up-to-date JVM, an no eclipse. I feel bad ;-) ...
UPDATE :
I have found this bypass. It works well, but I do not feel good with it in my app in production.
I have replaced those two lines :
// Here is the problem : AccessDeniedException is thrown ... sometimes.
Files.move( projectChangesDir, generationChangesDir );
With this code:
while ( true )
{
try
{
Files.move( projectChangesDir, generationChangesDir );
break;
}
catch ( IOException ioe ) { ++failures; }
}
It works suprisingly well and makes it possible for my program to run until its normal end. But ... well ... not so satisfactory. At the end failures counter is around 10, sometimes less, sometimes more, for a total of 1000 attempts (10 projects x 100 generations).
I know this question is rather old, and I don't have a clear answer, but a suspicion.
I'm having they same problem sometimes, but only when trying to move executable files (or folders containing such), and it happens more often when my computer is busy doing other stuff.
My suspicion is that an (corporate level) antivirus software is the culprit. Sometimes it isn't fast enough to scan the file and still has a lock on it when your program tries to move it.
I also didn't find a nice solution, and use a practically identical workaround to the one you are using. Disabling the antivirus isn't an option here, because even if I get an exception from my company, we also have to ensure the software works for our costumers without the need disable antivirus.
AccessDeniedException suggests there is a permissions problem. How are you executing your program, and does the user have permissions to create the c:/projects directory, and write to it?
One option would be to try running your code as an admin user. This post should help with that: https://superuser.com/questions/42537/is-there-any-sudo-command-for-windows
For now, as far as I know, only Aaron (https://stackoverflow.com/users/1678362/aaron) did try the sample Java code I provided in my question (thank you Aaron). He did not reproduce the issue.
I wonder what could be the difference between our two setups. Maybe the fact that my Windows 10 is a Professional one ?
Also, I would be happy if others can try the small code sample on their machine ... especially with various setups, including Windows 10 Professional.
I'm trying to develop a simple SNMP GET/SET program in java using SNMP4j. I've followed the following tutorials
http://www.developer-tricks.com/2012/11/how-to-get-started-with-snmp4j.html
https://blog.jayway.com/2010/05/21/introduction-to-snmp4j/
I have also read through the 'Getting started with SNMP4J' stackoverflow thread.
Every tutorial and program I've tried to replicate so far to get me started has resulted in "Error:java: java.lang.UnsupportedOperationException" when I compile. I can't figure out why. I used the exact code in both the tutorials I listed above, and both resulted in the same error as soon as I compile. I've read up on other threads involving the exception, but haven't found anything relevant to SNMP4j, a lot of what I read involved something with lists using the AsList method, which isn't used at all.
The code im trying to run is directly copied from the 'developer-tricks' link I posted earlier. The only difference is I changed the OID and IP address to ones for my own machine.
If anyone else has some experience in how to solve this exception, I would realy appreciate any advice.
Here is the console output when I try to compile.
Information:javac 10 was used to compile java sources
Information:3/29/2018 4:19 PM - Compilation completed with 1 error and
0 warnings in 716ms Error:java:
java.lang.UnsupportedOperationException
Here is my code, nearly identical to the 'how-to-get-started-with-snmp4j' tutorial i linked to.
public static void main(String[] args) throws IOException {
try {
Snmp snmp4j = new Snmp(new DefaultUdpTransportMapping());
snmp4j.listen();
Address add = new UdpAddress("192.168.1.10" + "/" + "161");
CommunityTarget target = new CommunityTarget();
target.setAddress(add);
target.setTimeout(500);
target.setRetries(3);
target.setCommunity(new OctetString("public"));
target.setVersion(SnmpConstants.version2c);
PDU request = new PDU();
request.setType(PDU.GET);
OID oid = new OID(".1.3.6.1.4.1.34832.512.1.1.1.2");
request.add(new VariableBinding(oid));
PDU responsePDU = null;
ResponseEvent responseEvent;
responseEvent = snmp4j.send(request, target);
if (responseEvent != null) {
responsePDU = responseEvent.getResponse();
if (responsePDU != null) {
Vector tmpv = responsePDU.getVariableBindings();
if (tmpv != null) {
for (int k = 0; k < tmpv.size(); k++) {
VariableBinding vb = (VariableBinding) tmpv.get(k);
String output = null;
if (vb.isException()) {
String errorstring = vb.getVariable().getSyntaxString();
System.out.println("Error:" + errorstring);
} else {
String sOid = vb.getOid().toString();
Variable var = vb.getVariable();
OctetString oct = new OctetString((OctetString) var);
String sVar = oct.toString();
System.out.println("success:" + sVar);
}
}
}
}
}
} catch (IOException e) {
e.printStackTrace();
}
Turns out the error had nothing to do with SNMP4j. It happened with any program I compiled.
In order to fix this, I uninstalled JDK 10 and installed JDK 9 instead. I was using Intellij. Not sure exactly what caused this, but uninstalling and reinstalling was the solution.
I have build an application connecting R and java using the Rserve package.
In that, i am getting the error as "evaluation successful but object is too big to transport". i have tried increasing the send buffer size value in Rconnection class also. but that doesn't seem to work.
The object size which is being transported is 4 MB
here is the code from the R connection file
public void setSendBufferSize(long sbs) throws RserveException {
if (!connected || rt == null) {
throw new RserveException(this, "Not connected");
}
try {
RPacket rp = rt.request(RTalk.CMD_setBufferSize, (int) sbs);
System.out.println("rp is send buffer "+rp);
if (rp != null && rp.isOk()) {
System.out.println("in if " + rp);
return;
}
} catch (Exception e) {
e.printStackTrace();
LogOut.log.error("Exception caught" + e);
}
//throw new RserveException(this,"setSendBufferSize failed",rp);
}
The full java class is available here :Rconnection.java
Instead of RServe, you can use JRI, that is shipped with rJava package.
In my opinion JRI is better than RServe, because instead of creating a separate process it uses native calls to integrate Java and R.
With JRI you don't have to worry about ports, connections, watchdogs, etc... The calls to R are done using an operating system library (libjri).
The methods are pretty similar to RServe, and you can still use REXP objects.
Here is an example:
public void testMeanFunction() {
// just making sure we have the right version of everything
if (!Rengine.versionCheck()) {
System.err.println("** Version mismatch - Java files don't match library version.");
fail(String.format("Invalid versions. Rengine must have the same version of native library. Rengine version: %d. RNI library version: %d", Rengine.getVersion(), Rengine.rniGetVersion()));
}
// Enables debug traces
Rengine.DEBUG = 1;
System.out.println("Creating Rengine (with arguments)");
// 1) we pass the arguments from the command line
// 2) we won't use the main loop at first, we'll start it later
// (that's the "false" as second argument)
// 3) no callback class will be used
engine = REngine.engineForClass("org.rosuda.REngine.JRI.JRIEngine", new String[] { "--no-save" }, null, false);
System.out.println("Rengine created...");
engine.parseAndEval("rVector=c(1,2,3,4,5)");
REXP result = engine.parseAndEval("meanVal=mean(rVector)");
// generic vectors are RVector to accomodate names
assertThat(result.asDouble()).isEqualTo(3.0);
}
I have a demo project that exposes a REST API and calls R functions using this package.
Take a look at: https://github.com/jfcorugedo/RJavaServer
I'm using grph library for a university project (www.i3s.unice.fr/~hogie/grph/)
but i have a problem only on Linux with that library, when i create a new Graph object, i receive the following exception:
Exception in thread "main" java.lang.ExceptionInInitializerError
at org.elendev.wesproject.graph.GraphFactory.main(GraphFactory.java:19)
Caused by: java.lang.NullPointerException
at toools.os.OperatingSystem.getLocalOS(OperatingSystem.java:47)
at grph.Grph.setCompilationDirectory(Grph.java:353)
at grph.Grph.<clinit>(Grph.java:246)
... 1 more
I tried to call directly getLocalOS function, with:
System.out.println(toools.os.OperatingSystem.getLocalOS());
and i receive the same exception. I cannot find information about that library, and the project launched on a macbook works perfectly.
The operating system i'm currently using is gentoo linux 32bit.
And the jdk version is: 1.7.0_65
Any idea of what could be the problem?
Not sure whether this can count as an answer, but it could at least help to solve the issue:
The exception comes from the toools.os.OperatingSystem.getLocalOS method. Although the .JAR file from the website that you mentioned has a whopping 39 megabytes, the source code of this class is not contained in it.
There seems to be no information available about this class at all. Neither Google nor Maven finds anything related to the toools package. One has to assume that it is an abandoned utility class that passed away a long time ago.
However, the method in question can be disassembled to the following code:
public static OperatingSystem getLocalOS()
{
if (localOS == null)
{
if (new RegularFile("/etc/passwd").exists())
{
if (new Directory("/proc").exists())
{
if (new RegularFile("/etc/fedora-release").exists()) {
localOS = new FedoraLinux();
} else if (ExternalProgram.commandIsAvailable("ubuntu-bug")) {
localOS = new UbuntuLinux();
} else {
localOS = new Linux();
}
}
else if (new Directory("/Applications").exists()) {
localOS = new MacOSX();
} else {
localOS = new Unix();
}
}
else if (System.getProperty("os.name").startsWith("Windows")) {
localOS = new Windows();
} else {
localOS = new OperatingSystem();
}
localOS.name = System.getProperty("os.name");
localOS.version = System.getProperty("os.version");
}
return localOS;
}
From this, you can possibly derive the conditions that must be met in order to properly detect your OS as a linux OS. Particularly, when there is a file named /etc/passwd, and a directory /proc, this should be sufficient to identify the OS as a Linux. You may want to give it a try...
Iam not able to upload files in FireFox and safari but iam able to do it successfully in explorer.
When i tried to debug i found out that in case of IE the upload browser is giving the entire file as eg C:\Documents and Settings\jjayashree\My Documents\price.csv
but where as in FF and safari the upload widget is just giving the file name with no extension.
previously code was like this
if (fileName.contains("\")) {
index = fileName.lastIndexOf("\");
}
if (this.fileName != null && this.fileName.trim().length() > 0 && index >= 0) {
this.fileName = this.fileName.substring(index + 1, this.fileName.length());
int dotPosition = fileName.lastIndexOf('.');
String extension = fileName.substring(dotPosition + 1, fileName.length());
try {
if (profileType.equalsIgnoreCase("sampleProfile")) {
if (extension.equalsIgnoreCase("csv")) {
//fileNameTextBox.setText(this.fileName);
this.form.submit();
} else {
new CustomDialogBox(Nexus.INFO_MESSAGE, MessageConstants.SPECIFY_FILE_NAME_MSG).show();
}
}
} catch (Exception e) {
Window.alert("SPECIFY_VALID_FILE_NAME_MSG");
}
} else {
Window.alert("SPECIFY_A_FILE_MSG");
}
i changed it as
if (this.fileName != null && this.fileName.trim().length() > 0) {
this.fileName = this.fileName.substring(this.fileName.lastIndexOf("\") + 1, this.fileName.length());
}
i found it working but when the same is deployed in linux iam getting an error
I also hav a doubt becos in the doPost of servlet iam using fileName.replace("\", "/");
is this the problem. . How wil mozilla encounter this fileName.replace() wil it just see and find nothing can be replced and go or wil it throw any kind of Exception
Maybe try gwtupload? It simplifies file loading to one function call, and handles all the backend for you. It's a little complicated to get working but there's a tutorial on the site on how to do it.
http://code.google.com/p/gwtupload/