views:

1454

answers:

1

Hi Chaps, I tried to deploy a servlet I have created to Glassfish application server, and I seem to have hit a bit of a stumbling block. The code deploys fine to the auto deploy folder, and once it's deployed the following is written to the log file:

[#|2009-03-16T13:41:29.303+0000|INFO|sun-appserver2.1|javax.enterprise.system.tools.deployment|_ThreadID=23;_ThreadName=Timer-7;|[AutoDeploy] Selecting file /opt/glassfish-2.1.b60e/domains/imageTransformer/autodeploy/image-transformer.war for autodeployment.|#]

[#|2009-03-16T13:41:29.304+0000|INFO|sun-appserver2.1|javax.enterprise.system.tools.deployment|_ThreadID=23;_ThreadName=Timer-7;|Autoundeploying application :image-transformer|#]

[#|2009-03-16T13:41:29.360+0000|INFO|sun-appserver2.1|javax.enterprise.system.stream.out|_ThreadID=23;_ThreadName=Timer-7;|
classLoader = WebappClassLoader
  delegate: true
  repositories:
    /WEB-INF/classes/
----------> Parent Classloader:
EJBClassLoader : 
urlSet = []
doneCalled = false 
 Parent -> java.net.URLClassLoader@39cf701c

|#]

[#|2009-03-16T13:41:29.361+0000|INFO|sun-appserver2.1|javax.enterprise.system.stream.out|_ThreadID=23;_ThreadName=Timer-7;|
SharedSecrets.getJavaNetAccess()=java.net.URLClassLoader$7@5e7408d9|#]

[#|2009-03-16T13:41:29.487+0000|INFO|sun-appserver2.1|javax.enterprise.system.tools.deployment|_ThreadID=23;_ThreadName=Timer-7;|[AutoDeploy] Successfully autoundeployed : /opt/glassfish-2.1.b60e/domains/imageTransformer/autodeploy/image-transformer.war.|#]

[#|2009-03-16T13:41:29.612+0000|INFO|sun-appserver2.1|javax.enterprise.system.tools.deployment|_ThreadID=23;_ThreadName=Timer-7;|deployed with moduleid = image-transformer|#]

[#|2009-03-16T13:41:29.783+0000|INFO|sun-appserver2.1|javax.enterprise.system.tools.deployment|_ThreadID=23;_ThreadName=Timer-7;|[AutoDeploy] Successfully autodeployed : /opt/glassfish-2.1.b60e/domains/imageTransformer/autodeploy/image-transformer.war.|#]

So no obvious errors, but after that I get a 404 from accessing the path that the servlet should be bound to. Is there another step that I need to go through?

the web.xml in my WAR file looks like this:

<web-app>
     <servlet>
       <servlet-name>MyServlet</servlet-name>
         <servlet-class>my.servlet.MyServlet</servlet-class>
     </servlet>

    <servlet-mapping>
     <servlet-name>MyServlet</servlet-name>
     <url-pattern>/hello</url-pattern>
    </servlet-mapping>
 </web-app>
A: 

There were a couple of problems with this deployment. Firstly there is a requirement for a second configuration file to be included in the WEB-INF/ directory, named 'sun-web.xml'. It's contents need to be something along the lines of:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sun-web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Application Server 8.1 Servlet 2.4//EN" "http://www.sun.com/software/appserver/dtds/sun-web-app_2_4-1.dtd"&gt;
<sun-web-app error-url="">
    <context-root>/MyServlet </context-root>
</sun-web-app>

It seems to have the potential to get alot more complex than this (See the documentation here: http://docs.sun.com/app/docs/doc/819-2634/6n4tl5kp3?a=view#gchwx)

Secondly I had to change the header for the web.xml file, so it read accordingly:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
   version="2.4">
     <servlet>
       <servlet-name>MyServlet</servlet-name>
         <servlet-class>my.servlet.MyServlet</servlet-class>
     </servlet>

    <servlet-mapping>
        <servlet-name>MyServlet</servlet-name>
        <url-pattern>/hello</url-pattern>
    </servlet-mapping>
 </web-app>

Note the headers indicating that this is servlet spec 2.4.

Finally, it also doesn't seem that you can access this servlet directly, you have to prepend MyServlet/ (or the servlet specific name) to the beginning of the path. so to access this servlet requires you to visit /MyServlet/hello

Ceilingfish