Deploying another servlet to a wildfly instance - java

I'm trying to deploy a second web application to a Wildfly server currently hosting a single application. I've made the following modifications to standalone.xml (see Accessing Multiple web applications on Jboss7 or Wildfly - my need is essentially the same):
Under <subsystem xlmns="urn:jboss:domain:undertow:8.0>, added
<server name="dispatch-server">
<http-listener name="default" socket-binding="dispatch"/>
<host name="dispatch-host" default-web-module="Dispatch.war" alias="Dispatch.com">
</host>
</server>
Next, under <socket-binding-group name="standard-sockets" default-interface="public" port-offset="${jboss.socket.binding.port-offset:0}">, added
<socket-binding name="dispatch" port="${jboss.https.port:8081}"/>
Finally, under <Deployments>, added
<deployment name="Dispatch.war" runtime-name="Dispatch.war">
<fs-archive path="${jboss.home.dir}/standalone/deployments/Dispatch.war" />
</deployment>
web.xml content for the deployed Dispatch.war:
<servlet>
<servlet-name>DispatchServlet</servlet-name>
<servlet-class>blah.blah.blah.DispatchServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>DispatchServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
I wrote a little application to test connecting to the servlet, using "http://localhost:8081", but I get an HTTP 404 error. I've tried additionally with "http://localhost:8081/DispatchServlet" with no changes.
I found other tutorials mentioning the need for a jboss-web.xml file bundled with Dispatch.war, so I added a barebones one that looks like:
<jboss-web>
<context-root>/</context-root>
</jboss-web>
It didn't impact the behavior I was seeing. I also tried changing the context-root to "DispatchServlet" and then hitting "http://localhost:8081/DispatchServlet" with nothing.
Is there something obvious I'm goofing on?

I think you are over complicating the issue. If you want to deploy multiple web apps, just drop ear war within the deployments directory. When they deploy the log shows their context path, then access any content relative to that path, e.g
/war1/DispatchServlet
/war2/DispatchServlet
If using different paths is not acceptable, then in order to do as you are trying, you need to follow the guides that explain how to use ROOT.war files and the associated changes to standalone-full.xml to disable the inbuilt default

Related

How to redirect application path in wildfly?

Excuse me, I'm new to this. I have developed an application with maven, and when I run the application in my wildfly it opens the following path: "127.0.0.1:8080/myapp-1.0.0" and everything runs perfect, but I simply want that:
x.x.x.x/ point to: x.x.x.x:8080/myapp-x.x.x
I do not know if it is a configuration in standalone.xml as it redirects or something more complicated.
If you only have a single web application, the simplest way is to have jboss-web.xml file in your web application. Put a file like:
<?xml version="1.0" encoding="UTF-8"?>
<jboss-web version="10.0"
xmlns="http://www.jboss.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.jboss.com/xml/ns/javaee http://www.jboss.org/j2ee/schema/jboss-web_10_0.xsd">
<context-root>/</context-root>
</jboss-web>
in your WEB-INF directory. This will make your application run at the / context. Note that this isn't redirection - it's permanently there. Additionally, if you have many webapps running on your Wildfly server they will all need a unique context root.

What controls the first part of a Tomcat app's URL?

I'm upgrading an old web app (was Tomcat 5 and JSF 1). I'm pretty new to Tomcat.
URLs into the app are all like this: "http://localhost:8181/app/esp/..."
But, currently the only way I can get the request through to the app is to use a URL like this: "http://localhost:8181/esp/esp/...".
So, how and where do I need to configure this "/app"? (Bear in mind this was working fine in the previous version).
My current environment is Eclipse Kepler, Tomcat 7 and JSF 2. Tomcat starts fine from Eclipse and will display an html page with "Run as server", for example: "http://localhost:8181/esp/esp/logout.html"
But this page has a link to "http://localhost:8181/app/esp/main" which results in a message "HTTP Status 404 - /app/esp/main - The requested resource is not available." If I overwrite the "app" with "esp" the request is handled.
My web.xml (stripped down by now) is like this:
<?xml version="1.0" encoding="UTF-8"?>
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
ESP
<servlet>
<display-name>ESPServlet</display-name>
<servlet-name>ESPServlet</servlet-name>
<servlet-class>ch.eds.esp.controller.ESPServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>ESPServlet</servlet-name>
<url-pattern>/esp/main/*</url-pattern>
</servlet-mapping>
Server.xml defines a Context in a Host, like this:
<Host appBase="webapps" debug="0" name="localhost" unpackWARs="true">
<Context reloadable="true" path="/app" />
</Host>
So, to cut a long story short, a URL like this ".../esp/esp/mypage..." works, and a URL like this ".../app/esp/mypage..." doesn't. And the second form is the way it needs to work.
But why? And how?
Following David99World's suggestion below, I tried changing these things.
In Eclipse I changed the "Web Project Settings/Context Root" from "esp" to "app". This produced no change when trying to "run on server" from Eclipse.
I tried exporting a WAR file from my project (using "Export...) to either a esp.war or a app.war. Putting them into /webapps and clearing away the previous stuff and restarting Tomcat.
If I use esp.war, then the usual 404 happens.
If I use app.war, I have a folder structure /webapps/app/esp etc. And requesting "http://localhost:8181/app/esp/main" seems to give an interesting result. It first redirects to "http://localhost:8181/app/esp/login.jsp" which then results in an exception "bean exceptionHeaderBean not found within scope".
So, some good progress (I'll go find that bean).
But how to get the same result from inside Eclipse?
I don't want to keep exporting a war to do each little incremental test.
Ah! You need to modify the Context Root (as noted above) - and then you need to (on the servers tab of Eclipse) "publish to server". Just stopping and starting are not enough.
Change the war file name that builds from app to esp, the first location after localhost:8080 is the deployed war application.

Clarification for Javamelody in Tomcat

I have setup Javamelody in my Tomcat container to view the statistics of my currently used website.
My website is configured in server.xml as follows and is not deployed as war but the classes and the jsp files are manually copied to "/dun/student/webapps" location as shown in the mapping:
<Context path="/stud" docBase="/dun/student/webapps" crossContext="false" debug="0" reloadable="true">
</Context>
I have copied the jar files javamelody.jar and jrobin-1.5.9.1.jar in the lib directory of my web-app.
Now I have modified the web.xml of my web-app to have the following lines and I have pasted it above my servlet declarations.
<filter>
<filter-name>monitoring</filter-name>
<filter-class>net.bull.javamelody.MonitoringFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>monitoring</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
I have restarted tomcat as well.
Now I'm trying to access my java melody statistics using the url:
http://student.studentgrade.com:8080/stud/monitoring
But I'm getting a 404 status saying requested resource is not available.
Now my web app which has many jsp files which were working fine too cannot be accessed and there too I'm getting a 404 error.
http://student.studentgrade.com:8080/stud/hello.jsp
But if I remove those lines which I added for javamelody in the web.xml file my jsp can be accessed.
What am I doing wrong here.
Please advice how I can fix this.
Do you add
net.bull.javamelody.SessionListener
into your web.xml?

How to eliminate hardcoded values in the web.xml

Let's say that I have something like this in my web.xml file.
<filter name="foo">
<init-param>
<param-name>fooBarUrl</param-name>
<param-value>http://foo.bar.com</param-value>
</init-param>
</filter>
Say there are different url values (for the param-value above) for dev/test/production. Is there a way that you can use filters and/or profiles in the pom to eliminate the need for changing this every time the application moves to a different stage? I.E. for dev it would be http://localfoo.com, and for test it would be http://testserver.com, etc.
You can use Maven's resource filtering ro replace properties with values at build time, e.g. by using different Maven profiles to set the properties values.
On the other hand you could use servlet parameters and move them to the context configuration, so your web.xml references them and they are actually configured in the application server where the .war file is deployed. That way, the application server administrator can reuse the same war file for each environment by just configuring it at server level.
In Tomcat for example, you can set the values in the context.xml file:
<Context>
...
<Parameter name="targetURL" value="http://testserver.com"
override="true"/>
...
</Context>
maven-replacer-plugin is what we use in our project for doing such text, pattern and version replacements during build time.

JBoss error report: HTTP Status 404 - Servlet is not available

I'm trying to create a very basic web project called "web" using MyEclipse and JBoss 5 as an application server. I've created one package called "pages" and inside it one servlet called "UserInterface". The problem is when I deploy the project and run the server I always get the error report: HTTP Status 404 - Servlet is not available.
This is a part of my web.xml:
<servlet>
<servlet-name>UserInterface</servlet-name>
<servlet-class>pages.UserInterface</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>UserInterface</servlet-name>
<url-pattern>/UserInterface</url-pattern>
</servlet-mapping>
and I'm navigating in the browser to: http://localhost:8080/web/UserInterface
What am I doing wrong here?
Thanks
404 means the URL you're trying to access does not point to an existing resource on your server. Check the address again, maybe the "web" (from http://localhost:8080/web/UserInterface) part is not correct because maybe the app is not deployed with that name. By default the app context name is derrived from the filename of the ".war" file such as if your file is "myApp.war", your app should be available at http://localhost:8080/myApp
Also, if you're actually deploying your war inside an .ear file that that ear file will contain an application.xml aplpication descriptor which can map your app file to a specific context, no-matter what the .war filename is, something like:
<module>
<web>
<web-uri>myApp.war</web-uri>
<context-root>theApp</context-root>
</web>
</module>
Finally, if you're autodeploying from Eclipse with the JBoss Eclipse connector, sometimes the thing bugs out and doesn't in fact deploy your app properly (even though the app itself is fine). If that's the case, trying manually deploying the .war to an application server and check it that way.
HTTP Status 404 - Servlet is not available.
The loading of the servlet has failed (if the servlet wasn't properly declared in web.xml or the URL was wrong, then you should instead have seen "404 - Resource not found"). Simply put, the <servlet-class> is wrong or the concrete class file isn't present in /WEB-INF/classes.
I still dont know what was wrong, but I've created another servlet called user, and in the web.xml I've added /servlet before the class and navigated to it in the browser (http://localhost:8080/web/servlet/User) and it worked.
<servlet>
<servlet-name>User</servlet-name>
<servlet-class>pages.User</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>User</servlet-name>
<url-pattern>/servlet/User</url-pattern>
</servlet-mapping>
Thanks everyone for your help!

Categories

Resources