Hi all
Is there any methods to fetch the File List in the Web server from the Application Server using JAVA?
i am finding something like new file ("/webserver_context_root/folder/") method that using the relative path to get the web server's resources from the app server...
PS : The reverse proxy has been set between the web and application servers.
Any ideas?
The HTTP protocol provides no standard way to list a "folder". Indeed, the HTTP and URI / URL specs don't even recognize "folder" as a concept.
If the folder notion is meaningful for your website then there are two approaches that could work:
Many webservers can be configured to produce a listing (e.g. in HTML) for a URL that corresponds to a folder in the webservers content space. (This is usually turned off for security reasons.) You can "scrape" this HTML to extract the list of names of things in the folder.
You could implement a RESTful service to return a list of the "files" in a "folder" as (say) JSON or XML.
Note however, that both approaches will be specific to that website. They won't work for arbitrary websites. I'm also assuming that the "application server" accesses the "web server" using HTTP. If it can access it some other way, there may be other solutions.
Related
Ok, I'm a beginner so this maybe stupid but i afraid that clients can modify static resources (css/javascript files) on server if they can load them directly through URL path (Of course I have to put css/javascript files outside of WEB-INF folder).
If my hypothesis is wrong, could you give me links or quotes to help me expand my knowledge ? Thank you :)
When a user's browser requests resources from your server, they are performing a GET request. This request will not directly change any file on your server. The request will go through your web server and will be processed. In the case of the resources such as css/javascript files, the web server sees the user is requesting the file and sends the contents of the file back. There is no way the user can update the contents of those files on the server unless you write code on the server to allow them to update the files. If the user has direct access to the server via ssh or other protocol and has permissions on the folder that holds the resources, they would be able to change them.
The whole process is much more complex for going through the web server, but for brevity left out here. Here is a good article that explains what really happens when you go to an address in a browser:
https://medium.com/#maneesha.wijesinghe1/what-happens-when-you-type-an-url-in-the-browser-and-press-enter-bb0aa2449c1a
is it possible to retrieve a index of all files on the web server when connecting to a website?
(Something similar to this image: http://www.linuxscrew.com/wp-content/uploads/2008/06/directory_index.png)
I understand that you can achieve similar effect using a web crawler, but there might be some unlisted links on the website, that are public, but invisible. Is there any way to access those files?
Not unless the server is configured to expose such a list. In many cases, there are very few "files", per se, in the first place. Resources are database records that are processed by server-side routines to provide HTML content to the browser.
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.
We have a website which has a decent customer base. We recently started a subdomain which will be used to serve specific content from the website. We need to redirect the users to subdomain when he/she tries to access the designated content from the old domain. For example I have old domain www.marketplace.com and a subdomain www.paper.marketplace.com. The web application serving both the domains is same. So when the user tries access a URL 'www.marketplace.com\paper\viewarticle' he should be redirected to 'www.paper.marketplace.com\paper\viewarticle'. Since it's the same web application serving both the domains I wanted do this using a servlet. The servlet should redirect user to subdomain based on certain configuration. I've thought about using a properties file in each folder that has a flag that determines if the request accessing the .html/.jsp files should be redirected or not.
the .jsp/.html files can be added/removed to deployment at runtime which is also a key for choosing this design.
Please comments on this approach or suggest any other ideas if you think it's better.
Thanks.
you can do this redirect, as long as the redirect follows some sort of convention, using apache rewrite rules. This way the overhead on your server to parse request, redirect and parse request again is reduced to just parsing the CORRECT request. This will for sure improve the performance on your site by reducing the number of requests.
Rewrites can be done with other servers, not just apache. Apache is just the most documented. Read Apache Rewrite Guide for more info.
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" />