Incompatible magic value 21877456 in class file - java

Im trying to use java applet on my web page. I try/search lots of thing but no chance. So here is the case.
My applet code is simple in app.html :
<applet codebase="." archive="applet.jar" code="de.escape.quincunx.dxf.apViewer" width="640" height="480" name="TEST">
<param name="file" value="40.dxf">
<param name="framed" value="false">
<param name="frameWidth" value="800">
<param name="frameHeight" value="600">
</applet>
This html file is working when i directly open in browser. Its working when i serve it with apache but its not working and give error "Incompatible magic value 21877456 in class file" when i try to serve with IIS. In apache i try php and html, both is working.
Is there any special configuration need on IIS when i try to serve applet?
Thank you for your answers.

I think IIS is not serving the right file for a .class, probably it is returning a 404 error or something similar, since it cannot find the file.
That error means that Java was expecting a .class file, all class files start with 0xCAFEBABE, which is a magic number with which Java can check that the file it is receiving is in fact a class file. In your case, however, the file returned by IIS is not a class file, it does not start with 0xCAFEBABE, and Java is unable to parse it.
The most common reason for it is that the web server is not able to serve the file, often because of a 404 error.
You should check what happens under the hood, search in IIS logs for requests of .class files, or use a tool (maybe even firebug) to see what is returned to the browser.

Finally i found a solution. Actually its not the exact solution but thank you for your answer Simone Gianni. His answer lead me to deeply search in IIS access logs and compare them with APACHE access logs. And yes, both was same and looks like couple of classes are not in place in the JAR file. So apVPORT.class is not in the jar file and developer who wrote this applet leave the calls for those classes in the other part of applet even he is not using them.
If someone can answer the reason why apache don't send any information or "its okey" information to java and continue loading rest of the applet even it see the 404 for apVPORT.class but IIS send 404 to java, this will be the final answer for this question.

Incompatible magic value 21877456 in class file : I found that this error comes when page is not able to reach /read the jar file.
in aspx page -
<applet code="FileAccess.class"
archive="../applet/SignFileAccessApplet.jar" width="325" height="325">
</applet>
in archive check whether url is proper or not by using "pickurl" option provided by intellisense of Visual Studio.
class file path in jar file need to be given in code attribute.

Related

Need help to download a pdf file from a url. The file access is restricted

I am trying to validate the contents of a pdf letter for my test automation. For that, first I am trying to download the pdf file to my local machine and validate. But I am not able to download the file properly with Java.
The pdf is present as an embedded document in a page which requires me to log in first. The html looks like below
<td colspan="2" style="vertical-align:top;" id="frameCell_24743998"><iframe id="viewFrame_24743998" src="https://wewewe.net/ewr/ww/desk/ViewQCWalzPDFAction.do?recordId=24743998&we=we&partitionId=16515&Id=1561024580039s79n0a" height="550" width="800" style="width: 1254px;"></iframe><br></td>
So I have got the url and tried to download the file using
FileUtils.copyURLToFile(new URL("https://wewewe.net/ewr/ww/desk/ViewQCWalzPDFAction.do?recordId=24743998&we=we&partitionId=16515&Id=1561024580039s79n0a"), new File("C:\\workspace\\dfdf\\dfdffddf\\dd.pdf"));
But it is showing
java.net.ConnectException: Connection timed out:
Exception.
So is this because I haven't logged in to the application and trying to download. Is there any other way to download it?
Is there any other way to download it?
That very much depends on how exactly that web page is built.
It might for example be possible to use cookies with your Java code, see here for some instructions how to do that. Meaning: you can enable your java code to appear "authorised".
If all of that doesn't work (and adapting the server to be allow "programmatic" access to such files isn't an option), then you could use automation tools such as selenium to do a "browser like" connection+download. See there for guidance.

blueimp jQuery-File-Upload redirect

I am using the blueimp jQuery-File-Upload on SpringSource Tool Suite 2.9.1.
I am trying to redirect from my UploadServlet , but because the option redirect is already
defined (on main.js) it create an error.
how can I redirect from my UploadServlet.java , after the files are uploaded .
In the example code they redirect to results.html , When I try this it upload the files but
after doPost function finish (in my UploadServlet.java) nothing happens & It doesn't
redirect .
please help me and give me an example how to do those thing .
Thanks
Tami
I've been through a similar issue when using the plugin on Google App Engine. Here is the complete working code. May be you'll have slight differences, but I guess you'll find how a Java server have to be done for this plugin to work.

SecurityException on my java applet

I am getting the java.lang.SecurityException: Permission denied: file:////Videos/public/scripts/screenshot.jar when I try to use an applet.
Here is the applet code:
<applet code="Screenshot" archive="file:////Videos/public/scripts/screenshot.jar" width="100px" height="100px">
</applet>
I've signed the applet using this 3-step guide, but it doesn't seem it worked for me, as I am still getting the error.
http://www.narendranaidu.com/2007/11/3-easy-steps-to-self-sign-applet-jar.html
Your jar URL looks strange. Personally I have never seen that somebody tries to download applet from URL other than HTTP. Actually it means that your applet will work only for users that are into your LAN where they have access to shared computer named "Videos". Are you sure this is what you want?
The second thing is: try to just copy and paste the JAR URL to your web browser and see what will happen. If you are able to download the jar file directly without entering password this should work when URL is placed into the applet tag. Otherwise it will not. So, first check your URL and fix its problem.

getFilePath API of FilePart not working as expected

I am working on a webbased application with servlets and JSPs in it. My requirement is to get the path of a file which is uploaded in my application.
The legacy code used to get the name of the file by using the code -
//FilePart class of the com.oreilly.servlet.multipart package.//
FilePart filePart = (FilePart) part;
screenosInputFileName = filePart.getFileName();
The getFileName returns the name of the file correctly as a string like "a.txt". Since I want the path also, I am using getFilePath as in--
String path = filePart.getFilePath();
However, I find that getFilePath is only returning the file name and not the file path. That is, getFileName and getFilePath are returning the same value "a.txt". What I was expecting from getFilePath was something like c:\myfiles.
Also, I am running my application in an Ubuntu enviroment (a linux flavour).
Any ideas why getFilePath is retuning only the filename and not the file path ? And how to overcome the problem. Any pointers higly appreciated.
Note: I am not familiar with com.oreilly.servlet.multipart.FilePart.
If FilePart represents the file on the client, then it is impossible to get the path of it (there is no reason for a server to know whether a.txt was uploaded from C:\Users\bob\ or from /home/bob/Documents/, so that information is not included).
If FilePart represents the file on the server (if your server saves uploaded files to a temporary directory so that you may access them as actual files), then you should be able to use this to get the actual path to the file:
String path = new File(filePart.getFilePath()).getAbsolutePath();
I hope this was helpful!
It used to be that Internet Explorer would include the full path of the file on the client's computer. I don't know if it does that anymore, but i don't think so, because it's a privacy issue. The server has no business knowing the full path.
getFilePath is only going to work if the client is using Internet Explorer, as it's the only browser that returns the entire file path to the server. Chances are, it'll only work with IE6 at that, as I believe MS finally realized this wasn't a good security practice when IE7 came out.

Need to get a path location via a web page

In firefox 2 I was able to get the path using Browse - I use the path in our project to then write out files to that location. So now that browse does not get the path, does anyone know a way for a user to go to a directory and have the path returned via a web page so I could pass that along to the server for processing?
execCommand does not work in firefox and had limites save type capaility, and entering by hand is not a useable option. Thanks.
The ability to see a complete client file path is now considered a security risk, and all modern browsers prevent you from seeing it (both via Javascript and via information sent back to the server on the form POST).
This is not possible with HTML/JavaScript. In HTML you can at highest use <input type="file"> to select a file, but not a folder or so. In JS you can't do anything at the local disk file system, let alone with a <input type="file"> element in the DOM tree. You're prohibited by security restrictions (you as being an enduser would of course not like if websites are able to do stuff at the local disk file system unaskingly).
You can only do that with a small application which runs straight at the client machine. For example a (signed!) applet which is basically just a piece of Java code served by a webpage which runs right at the client machine. You can communicate between applet and servlet using java.net.URL and consorts. Then, in the applet use Swing's JFileChooser to have a folder or file selection dialogue.
Update: by the way, MSIE and some other ancient browsers sends the full client-side disk file system path along the <input type="file"> to the server side. This is technically wrong (only the filename+extension should have been sent) and completely superfluous. This information is worthless in the server side, because it cannot access the file using the normal java.io.File stuff (unless both the server and the client runs at physically the same machine which of course wouldn't occur in real world). The normal way to get the uploaded file is to parse the multipart/form-data request body (for which one would normally use Apache Commons FileUpload or the Servlet 3.0 provided HttpServletRequest#getParts()).

Categories