1
votes

I'm trying to deploy a simple Web Service using eclipse, tomcat and cxf.

The steps i'm following are:

1) Create a wsdl file in a dynamic web project, in the WebContent folder.

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://www.negozio.org" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.negozio.org">

<wsdl:types>
<xsd:schema attributeFormDefault="unqualified" elementFormDefault="qualified"  targetNamespace="http://www.negozio.org" >

    <xsd:complexType name="findTicketsRequest">
        <xsd:sequence>
            <xsd:element name="from" type="xsd:string" />
            <xsd:element name="to" type="xsd:string" />
            <xsd:element name="hour" type="tns:hourType" />
        </xsd:sequence>
    </xsd:complexType>

    <xsd:complexType name="findTicketsResponse">
        <xsd:sequence maxOccurs="unbounded">
            <xsd:element name="ID" type="tns:IDType" />
            <xsd:element name="hour" type="tns:hourType" />
            <xsd:element name="minutes" type="tns:minutesType" />
            <xsd:element name="quantity" type="xsd:integer" />
        </xsd:sequence>
    </xsd:complexType>

    <xsd:simpleType name="hourType">
        <xsd:restriction base="xsd:integer">
            <xsd:minInclusive value="0"/>
            <xsd:maxInclusive value="23"/>
        </xsd:restriction>
    </xsd:simpleType>

    <xsd:simpleType name="minutesType">
        <xsd:restriction base="xsd:integer">
            <xsd:minInclusive value="0"/>
            <xsd:maxInclusive value="59"/>
        </xsd:restriction>
    </xsd:simpleType>

    <xsd:simpleType name="IDType">
        <xsd:restriction base="xsd:string">
            <xsd:pattern  value="[0-9]{4}"/>
        </xsd:restriction>
    </xsd:simpleType>

    <xsd:element name="ricercaRequest" type="tns:findTicketsRequest"></xsd:element>
    <xsd:element name="ricercaResponse" type="xsd:boolean" />

</xsd:schema>   
</wsdl:types>

<wsdl:message name="ricercaMessage">
 <wsdl:part name="ricercaMessagePart" element="tns:ricercaRequest"/>
</wsdl:message>

<wsdl:message name="ricercaResponseMessage">
 <wsdl:part  name="ricercaResponsePart" element="tns:ricercaResponse"/>
</wsdl:message>

<wsdl:portType name="ServiceSearchPortType">
 <wsdl:operation name="findTickets">
   <wsdl:input message="tns:ricercaMessage" />
   <wsdl:output message="tns:ricercaResponseMessage" />
 </wsdl:operation>
</wsdl:portType>

<wsdl:binding name="ServiceSearchBinding" type="tns:ServiceSearchPortType">
 <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />
   <wsdl:operation name="findTickets">
   <soap:operation soapAction="" />
   <wsdl:input>
     <soap:body use="literal" />
   </wsdl:input>
   <wsdl:output>
     <soap:body use="literal" />
   </wsdl:output>
 </wsdl:operation>
</wsdl:binding>

<wsdl:service name="SearchTicketsService">
  <wsdl:port  name="SearchPort" binding="tns:ServiceSearchBinding">
    <soap:address location="http://localhost:8080/WS1/ServiceSearchPortType" />
  </wsdl:port>
</wsdl:service>

</wsdl:definitions>

2) In order to generate the skeleton of java classes and methods, i use the following command in the folder of my project named WS1: /Users/Federico/apache-cxf-2.3.3/bin/wsdl2java -wsdlLocation WebContent/WSsearch.wsdl -impl -d src/ -frontend jaxws21 WebContent/WSsearch.wsdl

3) All seem to work fine. Added the web.xml and beans.xml files to WEB-INF folder:

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" 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">

<listener>
    <listener-class>
        org.springframework.web.context.ContextLoaderListener
    </listener-class>
</listener>

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>WEB-INF/beans.xml</param-value>
</context-param>

<servlet>
    <display-name>CXF Servlet</display-name>        
    <servlet-name>CXFServlet</servlet-name>
    <servlet-class>
        org.apache.cxf.transport.servlet.CXFServlet
    </servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
        <servlet-name>CXFServlet</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>
</web-app>

beans.xml

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">

<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />

<jaxws:endpoint 
  id="ricerca" 
  implementor="org.negozio.ServiceSearchPortTypeImpl" 
  address="/ServiceSearchPortType" />

</beans>

4) Now i try to deploy my web service exporting it in WAR at putting in tomcat's webapps folder, start tomcat to see the wsdl of my service in localhost:8080/WS1, but i get a 404 error and i don't understand why...

Maybe i've written a wrong wsdl, or beans.xml is incorrect.

I had another project with same build path in eclipse and it works fine, so i would exclude a library problem. I copied all cxf libraries in tomcat's "lib" folder.

Is it possible that a personal implementation of methods automatically generated by wsdl2java will change something?

Have i forgotten some passages? Suggestions or solutions? If you want more info or if i hadn't been clear just ask please. Thank you all.

1

1 Answers

4
votes

The URL you are using seems wrong.

  1. Log into tomcat manager http://localhost:8080/manager/html
  2. Get the path of your web application(context path).
  3. Now browser for http://localhost:8080/[context path you got in previous step]/services
  4. The servcies will list all the available WSDL or WADLs( bsically endpoints) in that application.
  5. You can click on the WSDL url to view WSDL