parchambeau
parchambeau

Reputation: 1141

Spring with Apache Camel and Web services getting started

I am starting to try to figure out how to work with Apache Camel within a Spring framework. The first thing that I want to try to get a grasp on would be running simple web service calls over this but I have no idea where to start.

Right now all I have is a basic HelloWorld Spring project set up and am trying to figure out what needs to be configured Apache Camel wise and where to get started on creating a simple web service.

I have taken a look at the examples on the Apache site but I was hoping maybe someone here knew of a tutorial that was a basic start to finish of something like I am trying to do.

Thanks for any tips or help that you all have!

Upvotes: 2

Views: 5567

Answers (2)

efirat
efirat

Reputation: 3867

I had the same question, and I have found this article

Step by step introduction to Web services creation using CXF and Spring: http://www.ibm.com/developerworks/webservices/library/ws-pojo-springcxf/index.html?ca=drs-

In short, there is four steps to create a web service

1 - Create a service endpoint interface (SEI) and define a method to be exposed as a Web service.

package demo.order;

import javax.jws.WebService;

@WebService
public interface OrderProcess {
  String processOrder(Order order);
}

2 - Create the implementation class and annotate it as a Web service.

package demo.order;

import javax.jws.WebService;

@WebService(endpointInterface = "demo.order.OrderProcess")
public class OrderProcessImpl implements OrderProcess {

 public String processOrder(Order order) {
  return order.validate();
 }
}

3 - Create beans.xml and define the service class as a Spring bean using a JAX-WS front end.

<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="orderProcess" 
  implementor="demo.order.OrderProcessImpl" 
  address="/OrderProcess" />

</beans>

4 - Create web.xml to integrate Spring and CXF.

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

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

 <servlet>
  <servlet-name>CXFServlet</servlet-name>
  <display-name>CXF Servlet</display-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>

Upvotes: -1

Petter Nordlander
Petter Nordlander

Reputation: 22279

I really found this one useful once: http://camel.apache.org/spring-ws-example.html (and complete source code in the camel distribution).

There are multiple ways you can deal with web services with Camel. Either use the spring web services as in the example I mention, or use Apache CXF.

Spring Web services are really easy to get started with, compared to CXF. Although CXF is a more complete web service stack.

There are multiple Camel and CXF examples here: http://camel.apache.org/examples.html

If you go with CXF, you may well benefit from actually learning a few "CXF only" examples before mixing with Camel.

There are essentially two ways to do web services, contract first start with a WSDL, then auto generate classes/interfaces. The other approach is code first - where the you start with java classes and then get an auto generated WSDL.

There are some rather good articles over here: http://cxf.apache.org/resources-and-articles.html

But to answer your question, I don't know of any good step-by-step tutorial on this matter. The examples in the links are really good though.

Upvotes: 5

Related Questions