dev@glassfish.java.net

Issue with computing WebComponentDescriptor for jar inside a WAR file

From: Vivek Pandey <Vivek.Pandey_at_Sun.COM>
Date: Tue, 06 Oct 2009 21:33:02 -0700

I was trying to help bhakti with 109 issues and looking in to:
https://glassfish.dev.java.net/issues/show_bug.cgi?id=9823

Basically if there is a webservice bundled as a jar file inside a WAR,
it gets deployed incorrectly and accessing it gives 500.

Here is an example:

sample.war
   /WEB-INF/lib/sample1.jar ( container @WebService StandaloneWS class)
  /WEB-INF/classes/SimpleWS (annotated with @WebService)
 /WEB-INF/web.xml

When deploying sample.war on glassfish its supposed to have 2 web services:

http://localhost:8080/sample/SantaloneWSService
http://localhost:8080/sample/SimpleWSService

However current WebServicesDeploy tries to deploy StanaloneWSService to
contextroot ('/') instead of 'sample'.

The root cause is really how WebServiceHandler creates endpoint and
creates a fake WebComponentDescriptor/WebBundleDescriptor for the jar
file and obviously it has missing contextRoot, this code assume that the
jar file being loaded is a Servlet and the implementation class is
itself! When I try to fix the contextRoot issue by correctly composing
the address where WS is deployed endpoin.composeEndpointAddress() and
then try to access SantaloneWSService, it fails as
CoyoteAdapter/StandardWrapper sees that the implementation class is not
a Servlet (obviously). I I try to fix the code below it cause lots of
other failures from different parts of 109.

WebServiceHandler.java

            if(endpoint.getWebComponentImpl() == null) {
                WebComponentDescriptor webComponent =
(WebComponentDescriptor) webBundle.
                    
getWebComponentByCanonicalName(endpoint.getWebComponentLink());

                // if servlet is not known, we should add it now
                if (webComponent == null) {
                    webComponent = new WebComponentDescriptor();
------> webComponent.setServlet(true);
-----> webComponent.setWebComponentImplementation(((Class)
annElem).getCanonicalName());
                    webComponent.setName(endpoint.getEndpointName());
                    webComponent.addUrlPattern("/"+newWS.getName());
                    webBundle.addWebComponentDescriptor(webComponent);
                }
                endpoint.setWebComponentImpl(webComponent);
            }

There are different people at different times authored the relevant
code in 109 anyone with the idea as whats really going on?

-vivek.