3 Replies Latest reply on Feb 10, 2011 7:55 AM by sejersbol

    Context root of EJB @WebService in WAR

    sejersbol

      Hi,

       

      I have created a web service from a @stateless EBJ located in a WAR, which is possible with JBoss AS 6. It works (with transactions, @Inject and so on), but when I deploy it my endpoint looks like this http://localhost:8080/ws-1.0.0-SNAPSHOT/Ws . I was of the assumption the <context-root> in the jboss-web.xml would override "ws-1.0.0-SNAPSHOT", but this does not happen. Can anyone explain this? And what is the solution?

       

      I have attached the test web service as both source code and WAR (note that I have included the XSDs because of JBAS-8776).

       

      Thanks in advance!

       

       

      Kind regards,

       

      Anders Sejersbøl

        • 1. Context root of EJB @WebService in WAR
          nickarls

          Does it react to @WebContext.contextRoot ?

          • 2. Re: Context root of EJB @WebService in WAR
            sejersbol

            I have tried:

             

            package com.example;
            
            
            import javax.ejb.Stateless;
            
            
            import javax.jws.WebMethod;
            import javax.jws.WebService;
            
            
            import org.jboss.wsf.spi.annotation.WebContext;
            
            
            @Stateless
            @WebService
            @WebContext(contextRoot = "/webservices")
            public class Ws {
                private String message = new String("Hello, ");
            
                @WebMethod
                public String sayHello(String name) {
                    return message + name + ".";
                }
            }
            
            

             

            But it does not change a thing, I still get endpoint http://localhost:8080/ws-1.0.0-SNAPSHOT/Ws ... Maybe this is a bug in AS 6?

            • 3. Re: Context root of EJB @WebService in WAR
              sejersbol

              Don't know if you can call it a solution to the problem, maybe more of a workaround. The following works:

               

              Instead of setting @WebService on the @Stateless, intect the local bean in the web service:

               

              @WebService
              public class Ws {
                  @Inject SpeakQuery bean;
              
                  @WebMethod
                  public String sayHello(String name) throws Exception {
              
                      return bean.sayHello(name);
                  }
              }
              

               

              Where SpeakQuery and SimpleSpeakQuery would look like this:

               

              public interface SpeakQuery {
                        public String sayHello(String name) throws Exception;
              }
              
              @Stateless
              public class SimpleSpeakQuery implements SpeakQuery {
                  private String message = new String("Hello, ");
              
                  public String sayHello(String name) throws Exception { 
                      return message + name + ".";
                  }
              }
              
              

               

              With the above you get it all - nice web service with context root configured in jboss-web and transactions.