Webserver and application server communcation - java

We have web application,that contains both dynamic and static contents. As our client want Static content in tomcat and dynamic content in web logic . Is it possible to do this type of configuration , how we could achieve this ? what are the support connectors or support for this?

Simple: Make sure that the URLs for the static content can be statically filtered (e.g. place static images in a /image path) and configure the webserver to serve everything that matches this path from static directories, forward the rest to the appserver.
Or vice versa: Filter the dynamic content and serve the rest statically.

Related

How to apply filter to the request to resource which are directly under webapps

I want to apply filter in below URL's.
http://10.78.97.29/robots.txt
http://10.78.97.29/sitemap.xml
https://10.78.97.29/
Since they does not contain any specific URL pattern , I am not getting any idea. And in which web.xml I have to add that filter mapping. I am using Tomcat as a webcontainer.
Thanks in advance.
Tomcat by default uses the web application named ROOT to serve the application at the root folder of the server. You can either handle the requests there or just have the files contained in the web application.
You might want to read about tomcat naming for more details, explaining this behaviour.
Alternatively, you can also have an Apache httpd in front of your tomcat and handle those files there.

Static index.html file - is servlet container being hit first?

In appengine, is index.html served as a static file or there's a servlet container involved first?
For example, lets assume I have the blabla.com host, war/index.html and a user goes to http:/blbla.com/
I don't want a servlet container being hit first in order to determine that it's part of welocme-file-list configured in web.xml and only then appengine will serve it as a static file. Is the only way to avoid server roundtrip is to have a user hit the url http://blabla.com/index.html ?
As per docs https://developers.google.com/appengine/docs/java/gettingstarted/staticfiles say:
By default, App Engine makes all files in the WAR available as static files except JSPs and files in WEB-INF/. Any request for a URL whose path matches a static file serves the file directly to the browser—even if the path also matches a servlet or filter mapping.
So now the question: Which of the following is true If I have specified "index.html" in welcome-file-list and user hits http://blabla.com
appengine knows that it has to servle index.html directly as a static file and my servlet container is not bothered checking welcome-files-list.
appengine doesn't know that it has to serve index.html from static files and my servlet container gets hit just to only check welcome-files-list and then allows appengine to fetch it as a static file.
In case of 2: the only way to have html files served as a static files is having users hit them directly in url, i.e http://blabla.com/index.html?
This is very important moment because it means that your servlet container may be doing additional job of resolving welcome-files-list on every request time which results in wasted cpu which could be avoided should users have specified direct path to the html files.
By default, App Engine makes all files in the WAR available as static files except JSPs and files in WEB-INF/. Any request for a URL whose path matches a static file serves the file directly to the browser—even if the path also matches a servlet or filter mapping. You can configure which files App Engine treats as static files using the appengine-web.xml file.
But you cannot set as static file the url "/".
See the documentation.

Serve files from a folder different of context directory in a servlet container

I got a situation that I must serve files from different folders then the one of the context my web app is running. As an example, suppose my web app is running in a servlet context on "/opt/tomcat/webapps/ROOT/" and I must serve files existent in "/opt/my_other_folder/". These folders can be changed in runtime by the client, so I can't simply add a new context pointing to these directories. I would like a solution that I wouldn't have to rewrite a web server only for that. Also, the product I work on is generic, so I can't have a solution specific to some servlet container.
Thanks!
If you're only serving files, I would consider fronting your servlet container with something like Apache HTTP Server, where you could simply use its various directives to provide a "virtual directory" pointing to an easily configured location.
Otherwise, you could write and configure a standard Java servlet that would do essentially the same thing - storing the actual path in a Java properties file that would be read by the servlet. But while this isn't a lot of work, it would be significantly more work that the above Apache HTTP Server solution. This would be very similar to several of the answers posted at Servlet for serving static content . Specifically, you could either use or extend upon Apache Tomcat's DefaultServlet. (There are some Tomcat-specific classes used in here, but they could be easily replaced with generic equivalents.) http://balusc.blogspot.com/2009/02/fileservlet-supporting-resume-and.html looks even closer to what you'd be looking for, and it is completely generic - while still having some additional, significant features.
Either of these options would be very generic, and not specific to any particular servlet container.

Serve static files with jax.ws

I'm building a web front end to monitor the state of a SOAP service.
Is there any way to serve static files with jax.ws? For example Endpoint.publish("/static", new SomeStaticFileHandler()) where any requests to /static just serve the corresponding static file in my folder? Inside the static file I would like to query the state and update the page with AJAX calls.
Thanks!
The correct way to serve static files is to add a custom servlet to the web.xml.
As for the hack you want to try: serve any file type, with any content-type? It will not work, I believe. Perhaps you can serve XML files if they follow a predefined schema -- JAX-WS implementation classes return objects, not strings or streams. These objects are serialized to SOAP/XML using the schema and binding. You'd need to parse the files into objects and then return to JAX-WS runtime... and you'll get a SOAP envelope over the file content anyway.
Inside the static file I would like to
query the state and update the page
with AJAX calls
This doesn't sound like a static file to me. This is a dynamic method serving XML or JSON. The simplest answer is still a servlet.
JAX-RS (RESTful Java API) is a viable alternative too.

ASP.NET/IIS equivalent of Java/WAS context-root

In Java on WebSphere Application Server if I want my servlets, etc., to start with a certain root path, I use the context-root property in the EAR deployment descriptor (application.xml). For example, my servlet is named GetData, but I want the URL to be www.mysite.com/secure/restricted/GetData, so I set the context-root to secure/restricted.
How do I do that in ASP.NET on IIS? Is the some kind of configuration setting for the application?
One option would be Url Rewritting - http://weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx
On the other hand, if you have your dynamic asp.net site separated from the rest of your content, you can add the folder secure/ and configure in there through the IIS Manager to point restricted to your asp.net site (regardless of where you have it stored).
That said, I don't know whether the WAS context-root give you something extra, for links to other info outside the asp.net site.
In .Net Core 2.0, there is an applicationUrl property in launchSettings.json:
By default, it will be "http://localhost:port/GetData" or "http://localhost:port"
Just change it to your final URL:
"http://localhost:port/secure/restricted/GetData"

Categories