6 Replies Latest reply on Oct 30, 2003 8:48 AM by raphead

    Deploy servlet at root (/)

    droolinggeezer

      Can anyone describe how to deploy a servlet at the http root on a JBoss 3.2.1/Tomcat config?

      <web-app>
      The web descriptor for the redirect servlet

      <servlet-name>redirectservlet</servlet-name>
      <servlet-class>redirectservlet.redirectservlet</servlet-class>


      <servlet-mapping>
      <servlet-name>redirectservlet</servlet-name>
      <url-pattern>/</url-pattern>
      </servlet-mapping>
      </web-app>

      Results in the following exceptions from the deployer:
      08:58:25,687 ERROR [MainDeployer] could not start deployment: file:/E:/jboss-3.
      .1_tomcat-4.1.24/server/default/deploy/redirect.war
      org.jboss.deployment.DeploymentException: Error during deploy; - nested throwab
      e: (java.lang.IllegalArgumentException: addChild: Child name '' is not unique)
      at org.jboss.web.AbstractWebContainer.start(AbstractWebContainer.java:3
      9)
      at org.jboss.deployment.MainDeployer.start(MainDeployer.java:832)
      at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:640)
      at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:613)
      at sun.reflect.GeneratedMethodAccessor34.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcce
      sorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:324)
      at org.jboss.mx.capability.ReflectedMBeanDispatcher.invoke(ReflectedMBe
      nDispatcher.java:284)
      at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:549)
      at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:177)
      at $Proxy7.deploy(Unknown Source)
      at org.jboss.deployment.scanner.URLDeploymentScanner.deploy(URLDeployme
      tScanner.java:302)
      at org.jboss.deployment.scanner.URLDeploymentScanner.scan(URLDeployment
      canner.java:458)
      at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread
      doScan(AbstractDeploymentScanner.java:200)
      at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread
      loop(AbstractDeploymentScanner.java:211)
      at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread
      run(AbstractDeploymentScanner.java:190)
      Caused by: java.lang.IllegalArgumentException: addChild: Child name '' is not
      nique
      at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBas
      .java:815)
      at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:8
      7)
      at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:579

      at org.jboss.web.catalina.EmbeddedCatalinaService41.createWebContext(Em
      eddedCatalinaService41.java:417)
      at org.jboss.web.catalina.EmbeddedCatalinaService41.performDeploy(Embed
      edCatalinaService41.java:266)
      at org.jboss.web.AbstractWebContainer.start(AbstractWebContainer.java:3
      7)
      ... 15 more

        • 1. Re: Deploy servlet at root (/)
          jonlee

          You will need to set your context so that your WAR fields requests for the root context. This is easiest done by including a jboss-web.xml in your WAR. See this message and it's linking thread for more information:
          http://www.jboss.org/modules/bb/index.html?module=bb&op=viewtopic&t= it explains this clearly.

          • 2. Re: Deploy servlet at root (/)
            droolinggeezer

            Thank you for your help but the reference post communicated nothing due to my lack of expertise on JBoss. Would you please spell it out for me?

            If I have a servlet class [ a.class ] that I want to deploy on a host with an IP of 200.1.1.1 at port 80 such that a GET to URL

            http://200.1.1.1/

            invokes the doGet of the servlet, what must I put in my web.xml and jboss-web.xml files?

            • 3. Re: Deploy servlet at root (/)

              This is not possible.

              The only allowed resource to let the server load when file is not specified, is one of the welcome-files. And this file must be a physical file.

              If you want this to be a servlet, the you have to use a JSP-file, and in this you can set a response.sendredirect to the servlet you want.

              • 4. I stand corrected...

                It is possible.

                First you have to make sure the application is mapped to root-context the ususal way.

                Then you edit the web.xml to have the servlet ansver to index.html (or any file actually), and make sure the same file is the first in the list of welcome-files.

                • 5. Re: Deploy servlet at root (/)
                  jonlee

                  OK. This is a bit beyond the scope of JBoss/Servlet discussions as it is really a pure servlet/web server tutorial.

                  You want all the content in this WAR to be served from the ROOT context, '/'. That is, any URI pointing to content located in your WAR, will be prefixed by '/'. So if you had a JSP index.jsp located in the top most directory of this WAR, you would access that content with the URI, /index.jsp. If you had an image file, jboss.gif located in a directory called images in the WAR, you would access this with the URI, /images/jboss.gif.

                  With JBoss deployment, you need a special file jboss-web.xml included in your WAR to tell JBoss that the context is explicitly somewhere. Otherwise, JBoss determines the context by the name of the WAR. So normally, if you deployed a WAR called myapp.war to JBoss's deployment directory the context would be myapp. So immediately, you have a problem trying to deploy content served from the root context as you can't have a WAR called /.war.

                  This is where jboss-web.xml comes in. You put this file in the WEB-INF directory of your WAR package. For the root context, the content would be:
                  <?xml version="1.0"?>
                  <jboss-web>
                  <context-root>/</context-root>
                  </jboss-web>

                  This just tells JBoss that we are over-riding the default mapping and explicitly mapping the content of this WAR to reside directly under the root context. We don't specify the server (or IP address) to which the request is directed, and by default any request to any of the interfaces on the server will be accepted. More detailed information on virtual hosts is better dealt with by the Apache web server tutorials which are in abundance.

                  Your web.xml is purely a servlet mapping process. server/default/jbossweb-jetty.sar/webdefault.xml for Jetty and server/default/jbossweb-tomcat.sar/web.xml for Tomcat provide the same general mappings and operational defaults for the respective embedded servlet containers. The welcome files specified in these configurations means that if the URI specifies a directory it should look for the existance of index.jsp, index.htm or index.html. I don't know if this takes precedence over your servlet mapping but you can experiment.

                  Your existing mapping should be fine - or at least it works for Jetty when you supply http://myserver/. I didn't have an index file in the WAR.
                  <?xml version="1.0"?>
                  <web-app>
                  The web descriptor for the redirect servlet

                  <servlet-name>redirectservlet</servlet-name>
                  <servlet-class>redirectservlet.redirectservlet</servlet-class>


                  <servlet-mapping>
                  <servlet-name>redirectservlet</servlet-name>
                  <url-pattern>/</url-pattern>
                  </servlet-mapping>
                  </web-app>

                  • 6. Re: Deploy servlet at root (/)
                    raphead

                    Forget About the .war Stuff which I read here:

                    http://www.jboss.org/modules/bb/index.html?module=bb&op=viewtopic&t= jboss-web.xml mapping works just fine!