JAX-WS multiple endpoints in sun-jaxws.xml
Asked Answered
C

2

6

Just started using JAX-WS. I created 2 test web services in the one WAR file as follows....

package com.djs;

import javax.jws.WebService;

@WebService()
public class AddTwoInts {

    public int performAdd(int firstNum, int secondNum) {
        return firstNum + secondNum;
    }
}

And.....

package com.djs;

import javax.jws.WebService;

@WebService()
public class SayHello {

    public String sayHello(String inwards) {
        return "Hello " + inwards;
    }
}

This is my web.xml

<?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">

    <listener>
        <listener-class>
            com.sun.xml.ws.transport.http.servlet.WSServletContextListener
        </listener-class>
    </listener>

    <servlet>
        <servlet-name>jaxws</servlet-name>
        <servlet-class>com.sun.xml.ws.transport.http.servlet.WSServlet</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>jaxws</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

</web-app>

This is the sun-jaxws.xml

<?xml version="1.0" encoding="UTF-8"?>
<endpoints xmlns='http://java.sun.com/xml/ns/jax-ws/ri/runtime' version='2.0'>  
    <endpoint name='performAdd' implementation='com.djs.AddTwoInts' url-pattern='/AddTwoInts' />
    <endpoint name='sayHello' implementation='com.djs.SayHello' url-pattern='/SayHello' />
</endpoints> 


I deploy into Tomcat 7 and use http://localhost:8080/MyApp/AddTwoInts?wsdl to get the WSDL for AddTwoInts OK.... But when I execute http://localhost:8080/MyApp/SayHello?wsdl I get a 404 page not found error....

Any advice appreciated.

Categorical answered 30/5, 2011 at 5:6 Comment(0)
E
15

Dave,

I guess you are missing the servlet-mapping for the two end points you have.

Add the following to your web.xml and try again. Let me know if this solve the problem.

<servlet>
    <servlet-name>AddTwoInts</servlet-name>
    <servlet-class>com.sun.xml.ws.transport.http.servlet.WSServlet</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>AddTwoInts</servlet-name>
    <url-pattern>/AddTwoInts</url-pattern>
</servlet-mapping>

<servlet>
    <servlet-name>SayHello</servlet-name>
    <servlet-class>com.sun.xml.ws.transport.http.servlet.WSServlet</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>SayHello</servlet-name>
    <url-pattern>/SayHello</url-pattern>
</servlet-mapping>
Estaestablish answered 2/6, 2011 at 8:47 Comment(3)
That fixed it, Thankyou....... Out of interest, why can't I point both endpoints at the same servlet ?? I thought the JAXWS servlet used the endpoint mappings in sun-jaxws to figure out which endpoint class to call. Therefore if I point all URL's to the one servlet, it should be able to figure out what to do....Categorical
I guess it is possible to map your multiple endpoints to one servlet, however your "sun-jaxws" should have all enpoints defined separately. Try this: **web.xml:** <servlet> <servlet-name>SomeName</servlet-name> <servlet-class>com.sun.xml.ws.transport.http.servlet.WSServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>SomeName</servlet-name> <url-pattern>/*</url-pattern> </servlet-mapping> sun-jaxws.xml: No change.`Estaestablish
A single servlet-mapping can have one servlet-name and multiple url-pattern entries, which would be what you'd want to do if a wildcard incorrectly matched non-web service resources in the same container (static resources, JSF or JSP, etc.). No need to specify the servlet twice.Averett
E
2

You want the web.xml to reference only one servlet, at urlMapping /:

  <servlet>
    <servlet-name>services</servlet-name>
    <servlet-class>com.sun.xml.ws.transport.http.servlet.WSServlet
      </servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>services</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>

Then, include multiple endpoints at the full desired path in sun-jaxws.xml:

<endpoint name='performAdd' implementation='com.djs.AddTwoInts' url-pattern='/AddTwoInts' />
<endpoint name='sayHello' implementation='com.djs.SayHello' url-pattern='/couldhavemore/SayHello' />

Note the "couldhavemore" in there... you can add to the relevant path in the sun-jaxws.xml file to get the full desired path. I've gotten a single service to work with a web.xml entry of something other than /, but then you need a web.xml entry for every service. It seems to get multiple to work you need to use / and then put the full path in sun-jaxws.xml.

Erving answered 25/5, 2013 at 2:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.