For a web service project, I need to install two API versions of a Java EE web on my web server at
example.com/myservice/v1 and
example.com/myservice/v2
The safest way to separate the different versions seems to be deploying them in different WAR files, one for v1 and one for v2.
I created and deployed two JBoss 6 Java EE 6 Web Profile applications with these entries in jboss-web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<jboss-web>
<context-root>/test/v1</context-root>
</jboss-web>
and
<?xml version="1.0" encoding="UTF-8"?>
<jboss-web>
<context-root>/test/v2</context-root>
</jboss-web>
Both war files deployed and ran without errors. JBoss did not complain that they use the same root context part /test.
Is this a standard behaviour of a servlet container (specified) or just a JBoss feature and not guaranteed to be portable?
For example, Oracle docs for Glassfish say that A context root must start with a forward slash (/); and end with a string - no restrictions of slash inside the context root.
Another example is JBoss docs where there is an example of two web applications with nested context roots (paragraph 1).
Tomcat also supports nested context paths - see Naming section of Apache Context Configuration doc.
There is no requirement of not having slash inside the context root in the specification also. I think it means that as well as any other feature you may assume that it works on your application server, but the way it is configured may differ, and of course you have to test your application before moving to another container.
Regarding context root JBoss says:
The context root of a web application determines which URLs Tomcat
will delegate to your web application. If your application's context
root is myapp then any request for /myapp or /myapp/* will be handled
by your application unless a more specific context root exists. If a
second web application were assigned the context root myapp/help, a
request for /myapp/help/help.jsp would be handled by the second web
application, not the first.
Two context root that you have defined in jboss-web.xml are i) /test/v1 and ii) /test/v2. These two are entirely different since they specify two different URLs.
So your apprehension that:
JBoss did not complain that they use the same root context part /test.
does not hold good as they are different from one another.
Related
I am trying to migrate an enterprise application from JBoss to Websphere 8.5. The application is configured with Spring MVC and tiles. The application is hosted in the server root of the JBoss Server, i.e. to access the application we just type https://localhost/ in the browser.For this reason all the links and association in the applications are currently written as follows:
<link href="/resources/jQuery.js" .../>
...
Home
etc.
But in WebSphere the application needs to be in a context root viz. https://localhost:9443/MigratedApplication.
The problem is that all the links and resources mapped in the application now are inside https://localhost:9443/MigratedApplication/resources but they are still looked for in https://localhost:9443/resources resulting in errors on the application throughout.
Any ways to resolve the issue by configuration in WebSphere?
Unfortunately you have hardcoded paths in your application, so you have 2 choices:
change the context root of the application on WebSphere to / as in JBoss (probably easier one, as doesnt require changes in application)
change all links to relative ones (this should be done in the first place during application development to make it independent of context root)
I have two applications that I need to deploy to GlassFish and I'd like to know how to put the two in the same GlassFish root context. I know that to put an application in the root context, I need to write the following line in glassfish-web.xml:
<context-root> / </ context-root>
So, when I acess http://localhost:8080 this address will open my application. But how to deploy both in the root context? Will I have to change the port?
Servlet specification SRV.3.2 says
Servlets in a container that were not deployed as part of aWeb
application are implicitly part of a “default” Web application and
have a default ServletContext.
so how can we create serlvets those are not part of web application and what is the use of them?
Take a look at section SRV.9.1:
SRV.9.1 Web Applications Within Web Servers
A web application is rooted at a specific path within a web server. For
example, a catalog application could be located at
http://www.example.com/catalog. All requests that start with this prefix will be routed to the
ServletContext which represents the catalog application.
Servlets that are not part of a web application are therefore servlets that are not rooted at a specific path. In other words, they're rooted at the / path, and their use is to serve content from there.
Note that this is pretty awkward to begin with (as the verbose text already shows), so most web application servers let you designate an application to run at the 'root' context path in some other way.
A java webapp must choose between either static context or "webcontext". Why do we need a webcontext just for a web server like jetty and why must we route everything to the same "webcontext" ?
Because Jetty is a JEE servlet container and in the JEE world there is a one to one relationship between a webapplication and the web context. The intention is to be able to run several independent webapplications within the same servlet container. So it is easy to route to the appropriate webapplication by the first part of the URL path.
Theoretically it would be possible to declare more than one webcontext for a webapplication but it is specified otherwise. See section 10.2 "Relationship to ServletContext" in Java Servlet Specification 3.1:
The servlet container must enforce a one to one correspondence between
a Web application and a ServletContext. A ServletContext object
provides a servlet with its view of the application.
I have two web application deployed in JBoss within same server. I have observed classpath is shared between this two web applications.
So how do I prevent classpath saring between applications. I mean whatever classes and jar files available in one application should not be visible in another application in same server in jboss.
For most versions of jBoss AS you need to update your jboss-web.xml file:
<jboss-web>
<class-loading>
<loader-repository>com.example:archive=unique-archive-name</loader-repository>
</class-loading>
</jboss-web>
See the following reference for more info:
jBoss class loading configuration
jBoss class loading background & use cases
The JBoss wiki states:
In jboss-3.2.3, the
jbossweb-tomcat41.sar is configured to
use a unified class loader as the web
application class loader. This is
controlled by the UseJBossWebLoader
attribute in the
jbossweb-tomcat41.sar/META-INF/jboss-service.xml
descriptor. The use of a unified class
loader means that the classes
available in the war inside of the
WEB-INF/classes and WEB-INF/lib
are incorporated into the default
shared class loader repository. This
may not be what you want as its
contrary to the default servlet 2.3
class loading model and can result in
sharing of classes/resources between
web applications. You can disable this
by setting this attribute to false.
It goes on to say that this behaviour was changed in 4.0.2, so it is a reasonable assumption that you still need to do this in 4.0.1.