Maxim Suponya
Maxim Suponya

Reputation: 1514

WebSphere 8, web.xml version="3.0", default servlet-mapping?

Migrating a legacy application from WebSphere v.6 to WebSphere v.8. The application's web.xml only contains declarations of servlets but not servlet-mappings. Yet all servlets without a servlet-mapping are accessible by a default url pattern /servlet/[servlet name]. However, on WAS8, if web.xml is updated with attribute version set to "3.0":

 <web-app xmlns="http://java.sun.com/xml/ns/javaee"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
       **version="3.0"**> 

servlets loose default mapping and need to be explicitly mapped otherwise it's 404 page not found.

Is there a way in servlet 3.0 or at least WebSphere 8, to define a default url pattern for all servlets? There's InvokerServlet for tomcat, is there a version of it for WebSphere v.8?

Upvotes: 5

Views: 10515

Answers (2)

Prince
Prince

Reputation: 20862

Looking at your answer there is a way to do what you want. For Servlet 3.0, the ibm-web-ext.xmi file is replaced by ibm-web-ext.xml and those settings that you mentioned can be applied. Here is a sample code for ibm-web-ext.xml file:

<?xml version="1.0" encoding="UTF-8"?><web-ext
xmlns="http://websphere.ibm.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://websphere.ibm.com/xml/ns/javaee http://websphere.ibm.com/xml/ns/javaee/ibm-web-ext_1_0.xsd"
version="1.0">

<reload-interval value="3"/>
<enable-directory-browsing value="false"/>
<enable-file-serving value="true"/>
<enable-reloading value="true"/>
<enable-serving-servlets-by-class-name value="true" /></web-ext>

For further reading take a look at EJB 3.0 application bindings overview.

Upvotes: 3

Maxim Suponya
Maxim Suponya

Reputation: 1514

Turns out older versions of WebSphere used proprietary ibm-web-*.xmi descriptors to define vendor specific deployment options. However, since v8.0 the support for .xmi files got dropped (yet still supported for backwards compatibility in applications declared as servlet "2.4"). The old application I was migrating contained the following ibm-web-ext.xmi in WEB-INF:

<?xml version="1.0" encoding="UTF-8"?>
<com.ibm.ejs.models.base.extensions.webappext:WebAppExtension xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:com.ibm.ejs.models.base.extensions.webappext="webappext.xmi" xmi:id="WebApp_ID_Ext" reloadingEnabled="true" fileServingEnabled="true" directoryBrowsingEnabled="false" serveServletsByClassnameEnabled="true">
  <webApp href="WEB-INF/web.xml#cchange"/>
  <extendedServlets xmi:id="ServletExtension_1">
    <extendedServlet href="WEB-INF/web.xml#Servlet_1"/>
  </extendedServlets>
  <jspAttributes xmi:id="JSPAttribute_1" name="keepgenerated" value="true"/>
  <jspAttributes xmi:id="JSPAttribute_1333518196516" name="reloadEnabled" value="true"/>
  <jspAttributes xmi:id="JSPAttribute_1333518196517" name="reloadInterval" value="10"/>
</com.ibm.ejs.models.base.extensions.webappext:WebAppExtension>

so the attribute serveServletsByClassnameEnabled="true" made the old app map servlets by name without servlet-mapping. This is not supported if the application is servlet 3.0..

Upvotes: 3

Related Questions