Embedded Tomcat, Jersey, and WebApplicationInitializer not loading - java

I am attempting to embed tomcat in my existing Jersey web application.
I am able to get Tomcat running no problem, and even loading my JSP's from the webapp dir. The issue is getting it to see my WebApplicationInitializer class like it does in the full container. I'm fairly certain this is a class path issue, if I add a VirtualDirResource and set the context to it, my Jersey app loads. The issue there is, Jersey can no longer load my JSP Viewables. It returns 404. Again, I have no web.xml anywhere. Not sure what code would be helpful, so ask for code samples if you think you have an answer.

Related

Log4j2 configuration - indentify the webapp

In my webapp I configure Log4j2 with XML file.
The case is there's might be several versions of this webapp deployed on the server (for production purpose). If I don't edit log4j2 configuration, all webapps write logs to the same location.
So I need somehow identify versions of the app and add this identifier to the end of the folder name.
Apps always have different names, so maybe I can use it.
Can anyone please suggests some solution for this?
P. S. I know I could use ${log4j:configParentLocation} or something like this, but this gives me troubles when I deploy the app.
Edit: I don't use Spring boot, just usual Tomcat Servlet webapp with web.xml.

Load webapp on container startup without web.xml in Tomcat+Jersey?

I currently have a Jersey webapp without a web.xml. It deploys nicely, but doesn't start up until it receives its first web request.
To get the webapp to load at startup, I could create a web.xml for the webapp and give a load-on-startup tag. However, I'd strongly prefer not to make a web.xml.
Is there a way to get a JAX-RS application to load at startup without web.xml? I'll even accept a solution that is specific to Jersey and/or Tomcat.
EDIT: I would also accept a solution that loads all apps in a Tomcat instance eagerly.
EDIT: Let me give a little more information on how the app is being deployed, per a comment.
The deployment process is not sophisticated.
The App will live on an EC2 instance running Ubuntu 12.04. I'm setting up one instance of the App by hand; once it works, I will make an AMI of the app and create additional copies of it as needed.
To deploy the app on the initial instance, I'm simply copying the WAR file to /var/lib/tomcat7/webapps and restarting Tomcat. No other webapps will be running on this Tomcat instance.
If any additional information would be useful, let me know! I'll happily add it.
EDIT: For clarity's sake, this is how my webapp Application class looks, at a high level:
#ApplicationPath("/")
public class App extends ResourceConfig {
// ...
}
I'm using the Jersey-specific ResourceConfig class instead of the more general JAX-RS Application class because I'm using Jersey's built-in HK-2 to do some dependency injection.
The only way I can think of to do that is to switch to setting up the Jersey ServletContainer yourself and set its "load on startup" value to something greater than zero. You might use a ServletContainerInitializer (no relation--the naming is just a coincidence) to do it. If you happen to be using Spring, its WebApplicationInitializer offers the same mechanism with a slightly more convenient interface.
Another, rather hacky, way would be to write a class that extends ServletContainer and give it an appropriate Servlet 3.0 annotation, something like #WebServlet(value="/", loadOnStartup=1)
One solution would be to force a first request to the app by simply adding a call to curl or wget to your deployment script. It has the additional advantage of warming up any caches. And it can be used for testing if the deployment and the app really work. (Just check HTTP status code or some text on the response page...)

JSF Beans not accessable when deployed as war

I ran into a Strange Problem. I'm currently working on a project with the following configuration:
Spring Framwork for data services
JSF and Vaadin as web Framwork (2 seperated subcontexts)
Tomcat 7 as application Container
Spring EL resolver
When I deploy this application to my Tomcat Server everything works fine. When I build the application as a war-file with maven and deploy this war file on my Tomcat (the same tomcat!) the Vaadin frontend works fine, but in the JSF all Tags with values from beans stay empty. Tags with just plain text in it are processed correctly.
My biggest Problem is, that I don't get any exception. I'm also a bit confused that I also don't get an exception, when I try to access non-existing beans in my eclipse-deployed environment no error occurs, just no output is produced at that point.
I raised all Log Levels to max, but in the logs everything seems to be fine.
So, has anybody an idea, how to get JSF to display errors, when beans are not accessable and why there are difference when I deploy directly from eclipse or from a war file?
Thanks in advance!
nclaasen

Google App Engine Error 503 - Service Unavailable

For the past couple of days, every time I try to run my web application, Error - 503 has been showing up. This happens even when I try to go to the admin page. Is this a problem with Google?
It's important when creating a GAE project that any .class that extends HttpServlet and are used as entry point to your Google App are mapped in web.xml found in war/WEB-INF as pictured below.
Java Servlets you create that extend HttpServlet must be mapped in the web.xml like the following:-
In this Test GAE project ecipse generated sample code that created a Java Servlet called TestServlet.class that extends HttpServlet and is appropriately mapped.
To run your app you need to include the url mapped to the TestServlet.class found in the web.xml (In this case /test) in your index.html. (In the case of generated project sample code created by eclipse this will already have been done).
Once your Java Servlets are correctly mapped in the web.xml and included in your index.html the mapped url that is clicked will invoke the appropriate Servlet and run your app.
This will eliminate common 503 errors in terms of new project setup.

how to make my files present in a tomcat server to the browser

I have installed Tomcat 5.0 in order to execute a web application. How can I show my files which are present in Tomcat to the web browser? I tried http://hostname:8080/myfolder/login.html, but I can't see the files.
One more thing I know about JDBC and other database connectivity and I have developed a HTML page. How can I let a button in the page execute the code written in a Servlet and perform validations?
The simplest thing is to add to the root webapp. That is webapps/ROOT. Any file you put in there will be served unless you change the default configuration.
You should read about the details, of course.
I have installed Tomcat 5.0 in order to execute a web application.
First of all, why are you using the ancient (8 year old) Tomcat 5.0? If you can, rather grab the latest one, Tomcat 6.0.
How can I show my files which are present in Tomcat to the web browser? I tried http://hostname:8080/myfolder/login.html, but I can't see the files.
Is myfolder the context name or just a folder in your webcontent? If it's a context name, then you need to ensure that it's properly deployed. You can find details in the server logs in the /logs folder. If it is a folder in your webcontent and the webapplication is thus supposedly to be the "root" application, then you need to ensure that it's deployed as ROOT.
To learn more about using Tomcat, go through the documentation.
One more thing I know about JDBC and other database connectivity and I have developed a HTML page. How can I let a button in the page execute the code written in a Servlet and perform validations?
To the point, just create a class which extends HttpServlet, implement the doPost() method, define the servlet in web.xml and let the action attribute of the HTML <form> element point to an URL which is covered by the url-pattern of the servlet mapping in the web.xml.
As the question is pretty broad, I have the impression that you haven't learned in any way how to work with Tomcat and JSP/Servlets. I would strongly recommend to go through those tutorials to familarize yourself with JSP/Servlet on Tomcat and Eclipse (an IDE) first: Beginning and Intermediate-Level Servlet, JSP, and JDBC Tutorials
Tomcat is not a web server like, say, Apache. It's a servlet container. You can not just move file in a subfolder which seem to be what you did. You need to pack your web application in a .war and deploy it.
The URL should rather be http://host:8080/webapp/subfolder/login.jsp
Without much information it's hard to help. Please edit your question and describe what you've done so far.

Categories

Resources