2
votes

I have created a simple Spring MVC web application and trying to expose the services as SOAP based JAX-WS services using JAX-WS commons RI implementation.

After deploying my application on Tomcat 7, when I try accessing my web service, I get a message as 404 Not Found: Invalid Request. Below are my configurations, kindly help in resolving this.

web.xml

<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

    <!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring/root-context.xml</param-value>
    </context-param>

    <!-- Creates the Spring Container shared by all Servlets and Filters -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <!-- Processes SOAP Web Service requests -->
    <servlet>
        <servlet-name>jaxws-servlet</servlet-name>
        <servlet-class>com.sun.xml.ws.transport.http.servlet.WSSpringServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

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

    <!-- Processes application requests -->
    <servlet>
        <servlet-name>appServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

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

</web-app>

WEB-INF/spring/appServlet/servlet-context.xml

    <beans:bean id="customerService" class="com.home.service.CustomerService" />

    <!-- Web Service definition -->
    <beans:bean id="customerWS" class="com.home.ws.CustomerWS">
        <beans:property name="customerService" ref="customerService" />
    </beans:bean>

    <wss:binding url="/ws/CustomerServ">
        <wss:service>
            <ws:service bean="#customerWS" />
        </wss:service>
    </wss:binding>

CustomerWS.java

@WebService
@SOAPBinding(style = Style.DOCUMENT, use = Use.LITERAL)
public class CustomerWS {

    private CustomerService customerService;

    @WebMethod
    public Customer read(long id) {
        return customerService.read(id);
    }

    public void setCustomerService(CustomerService customerService) {
        this.customerService = customerService;
    }
}

CustomerService.java

@Service
public class CustomerService {
    public Customer read(long id) {
        Customer cust = null;
        System.out.println("CustomerService.read invoked");

        return cust;
    }
}

pom.xml - included the dependency of jaxws-spring

    <dependency>
        <groupId>org.jvnet.jax-ws-commons.spring</groupId>
        <artifactId>jaxws-spring</artifactId>
        <version>1.9</version>
    </dependency>

There are no errors while building or deploying the application. When I access the URL, still I see no errors in the server log files. However, the browser displays the message - 404 Not Found: Invalid Request

URL I am trying is - http://localhost:8080/crrs/ws/CustomerServ?wsdl

If I access my HomeController, it works fine. Home page is loaded as expected.

Appreciate any help. Thanks in advance.

2
Did you resolve this? I am trying to do a similar thing.Web User

2 Answers

2
votes

I'm trying to do the same thing. My code is almost the same, I'm just using @Name and @Inject instead of @Service.

Just added extends SpringBeanAutowiringSupport to the @WebService class and it's working

1
votes

The servlet mappings in the web.xml seem to be the cause.

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

[...]

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

The spring DispatcherServlet named appServlet takes care of all urls after http://localhost:8080/crrs, even http://localhost:8080/crrs/ws/CustomerServ?wsdl.

The WSSpringServlet url-pattern cannot be reached.