Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache CXF and tomcat

Tags:

java

tomcat

cxf

I am fairly new to Apache CXF and tomcat. I am trying to build a simple web service and deploy it on tomcat. below is my web.xml However when I try to access the 'services' folder using my browser it says No services have been found. I tried creating java web service client but it is not able to locate the service either. What could be wrong in this?

<?xml version="1.0" encoding="UTF-8"?>
<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">
    <display-name>Sample web service provider</display-name>
    <listener>
        <!-- For Metro, use this listener-class instead: 
             com.sun.xml.ws.transport.http.servlet.WSServletContextListener -->
        <listener-class>
              org.springframework.web.context.ContextLoaderListener
        </listener-class>
    </listener>
    <!-- Remove below context-param element if using Metro -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
              classpath:META-INF/cxf/cxf.xml
        </param-value>
    </context-param>
    <servlet>
        <servlet-name>WebServicePort</servlet-name>
        <!-- For Metro, use this servlet-class instead: 
             com.sun.xml.ws.transport.http.servlet.WSServlet  -->
        <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>WebServicePort</servlet-name>
        <url-pattern>/services/*</url-pattern>
    </servlet-mapping>
    <session-config>
        <session-timeout>60</session-timeout>
    </session-config>
</web-app>
like image 262
Furkkanali Avatar asked Feb 28 '13 03:02

Furkkanali


People also ask

What is Apache CXF used for?

Apache CXF™ is an open source services framework. CXF helps you build and develop services using frontend programming APIs, like JAX-WS and JAX-RS. These services can speak a variety of protocols such as SOAP, XML/HTTP, RESTful HTTP, or CORBA and work over a variety of transports such as HTTP, JMS or JBI.

What is CXF endpoint?

In Apache Camel, the Camel CXF component is the key to integrating routes with Web services. You can use the Camel CXF component to create a CXF endpoint, which can be used in either of the following ways: Consumer — (at the start of a route) represents a Web service instance, which integrates with the route.

Where do I put CXF XML?

For both web service clients and servers, the default location that CXF will look for a configuration for is "/cxf. xml" on the class path. For example, when running your application in a servlet container, this file is expected to be located in a /WEB-INF/classes folder of your web application.

What is CXF servlet?

Fuse Services Framework provides a standard servlet, the CXF servlet, which acts as an adapter for the Web service endpoints. The CXF servlet is the easiest method for deploying Web services into a servlet container.


2 Answers

This means that you don't have any services exposed in your application. Your web.xml seems to be correct but I've just missed one thing, your Spring configuration. Add your Spring config location in your web.xml, for e.g.:

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

Also, you have to create a class which will implement your web service interface and expose it as the CXF endpoint in your Spring applicationContext.xml configuration file. For e.g.:

<bean id="candidateImpl" class="some.pckg.CandidateImpl"/>

<jaxws:endpoint id="candidateEndpoint"
                implementor="#candidateImpl"
                address="/Candidate"
        />

Your CandidateImpl class should have @WebService annotation. For e.g.:

@WebService(targetNamespace = "http://something.com/ws/candidate",
        portName = "CandidateService",
        serviceName = "Candidate",
        endpointInterface = "some.pckg.types.CandidateService",
        wsdlLocation = "WEB-INF/wsdl/CandidateService.wsdl")
public class CandidateImpl implements CandidateService {
     //Implementation of all methods from CandidateService.
}

If you've done everything correctly you should see that there is one service available under:

http(s)://whateverhost.com:<somePort>/SomeContextPath/services

And you should be able to get the WSDL file like this:

http(s)://whateverhost.com:<somePort>/SomeContextPath/services/Candidate?wsdl

See also:

  • Writing a Web Service with Spring
like image 170
Paulius Matulionis Avatar answered Sep 25 '22 21:09

Paulius Matulionis


You need to set the spring configuration file location to make this work. You can set it as follows.

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>WEB-INF/applicationContext.xml</param-value>
</context-param>
like image 28
ravana Avatar answered Sep 24 '22 21:09

ravana