reading logs and displaying them on a web browser using Java - java

I have logs in folder /home/a/b (located in a remote server)
I want to display logs in my web browser using Java. To get data in the folder /home/a/b and to display them on my web page, what are some methods(API) I can use?

The simplest approach I can imagine is using a SSH API like JSch,
but I don't know how performatic this is.
Anyway, here goes a good example:
https://stackoverflow.com/a/9019095/7528396
Note that you can read the remote file and render line by line.

Related

Java - File parsing vs fetching html over http

We have a Java class that is supposed to fetch an HTML file and then read some content in it based on the id of certain divs and then return the content to a frontend which will then render it.
Now we have a set of HTML files on a common file system somewhere on the network. Multiple applications will access it. It is like a homegrown GUI help guide for our customer facing screens with a centralized storage.
We have managed to load the html file in 2 ways
Start an Apache web server and put all html files in htdocs. The calling Java class then makes an http call http://someIP:80/helpguide/userguide.html #firstname. This will fetch the help guide related to FirstName field on the screen. The Apache service has to be managed as it is accessed in Live but only accessible within our network.
Create a Shared directory and grant access to it to the Windows logon used to run the Windows service that runs Tomcat where the client facing web application is deployed. Then the Java client class uses new File("<file location>") to load the file and read its content. This works as well.
Basically we have 2 ways to load the html file. Now we are confused whether to use route 1 or 2?
The html files won't be that massive and will be of reasonable size. It may have inline css or youtube video links embedded in them.
Downside of (2) is if we want to include images later it won't work while it should work with (1).
However in terms of performance and efficiency how are teh 2 approaches different? (1) will open a Http socket connection over port 80 and get the html stream back. WIth (2) It will possibly use a File Inputstream to get the file on the server.

J2EE: file access from web server.

I am trying to develop a J2EE web application which reads files from the local machine. The user will be able to enter a path where the file exists and when a button is clicked, the file is read and a database should be uploaded. This feature works fine when I tested it locally, but when I moved the code to the web server, it is not able to find the file. This is because the application is trying to find the file at the server and not the local machine. Could some one please let me know if there is any way I could read the file from the local machine?
I ve been using struts/tomcat for developing this application
Thanks
An option: Check out this Rose India article
Another option: do a google search for "file upload jsp"
try
<input type="file"/>
It is impossible to read a file on a remote computer without sending it to the server... obviously!
Local file access is usually permitted if you run the browser App from the local file system, and not thru an Web server.

java images receiving (web)server

I want to make a system where java client programs send images to a central server. The central server saves them and runs a website that uses these images.
How should I send the images and how should I receive them? Can I use the same webserver for receiving and displaying the website?
You need 3 things:
Upload client Need to know how to do multipart upload. See here
Upload Server There are a couple of ways. Apache Commons Upload is my pet.
Displaying File It's easy. If the files are uploaded somewhere under your web-app directory outside of WEB-INF directory. Just give the path like http://your/apps/base/url/folderName and the listing will come-up for download. There are ways to secure that. But I donot think you need to know that at this stage. By the way this may help.
And yes, same server can be used to upload and display (download) the images/files.
Hope this helps.

Reading a remote file with java on linux

I need to read a remote file using a java app, but the file is in apache server on linux.
I tried with "\\" but doesn't work like windows.
How can i do that?
You'll need to use the URL class:
http://download.oracle.com/javase/1.4.2/docs/api/java/net/URL.html
This is the standard way of reading files from a URL.
Try accessing your file via web browser using url formatted like:
http://server-name-or-ip/path/filename
When you see your file in browser, use that url from your Java app, too.
This depends on a number of things. But we don't really know what question you're asking. Are you asking how to retrieve a document over HTTP? How to do a file copy from Linux? Network shares?
If the file is served by the webserver (in the docroot), the easiest way is probably to request it over HTTP using the URL class as stated above.
If the file is NOT under the webroot (i.e. can't be specified as http://webserver.name/some/path/to/file) then you'll need to use some other method. I'm assuming this is what you meant - you mention \\, the Windows file-sharing (SMB) protocol prefix. The easiest way is to use SSH and scp/sftp, which is probably already installed on the Linux machine - you may need to enable it, and you'll need a login. Then it's as simple as scp user#host:/remote/file/path local/path. You can set up SSH keys to avoid a password.

How to retrieve images stored in file server?

I have a java web service through which I upload images to a file server. I want to access these images from my java web app. How can I make the image files (and eventually other static files) available from this file server?
The only thing I could think of was to use Apache Http server as a proxy to my web app for these images, but that circumvents the security measures of the web app.
UPDATE:
Servlet container: Tomcat
Web app is on separate server from images.
Web service is on same server as images and has direct access to file system.
Both web app and service use spring security for authentication/authorization, I want to continue to use this security framework to for image access.
How are the files stored?
If security is a concern the best option might be to create a Servlet (or something similar) which will load up the image and serve it to the user, once it has checked their credentials.
How you load the image depends on exactly how they're stored, if you can access them via HTTP you can always open up a URLConnection to the file from the Servlet and serve it directly that way (i.e. using the Servlet as a sort of proxy server).
Without more details it's difficult to be specific.
I'm not sure if this will solve your problem, but it sounds like you should set up a context path that will map a URL to the path on your server. This can be done with tomcat's context files.
For a good explanation of the solution, check out a post on How to Program with Java
Sounds similar to Apache Hadoop.
Once image/file is requested, you have to make API call and pull the file out and do one of the following:
Store the temp file to the "temp" directory on web accessible server. You will need, some kind of cleaner/gc running in the background to clean those temp files. This is how Facebook does it with photos.
Instead of storing file on the server check the file type and set HTTP Content-type header to the appropriate file type. Image source will look like this <img src="getPicture.jsp?id=1234" />

Categories

Resources