{"id":50,"date":"2010-05-16T17:11:11","date_gmt":"2010-05-16T11:41:11","guid":{"rendered":"http:\/\/naveenbalani.com\/?p=50"},"modified":"2016-09-17T22:40:01","modified_gmt":"2016-09-17T17:10:01","slug":"cxf-and-spring-tutorial","status":"publish","type":"post","link":"https:\/\/navveenbalani.dev\/index.php\/articles\/cxf-and-spring-tutorial\/","title":{"rendered":"CXF and Spring tutorial"},"content":{"rendered":"<p>In this blog we will look at how to develop a simple web service using CXF and <em>Spring-based configurations<\/em>. We will take a use case of a Order Processing Application and than develop a web service and client for this use case.<\/p>\n<p><strong>The Order Processing Application<\/strong><\/p>\n<p>The objective of the Order Processing Application is to process a customer order. The order process functionality will generate the customer order, thereby making the order valid and approved. A typical scenario will be a customer making an order request to buy a particular item. The purchase department will receive the order request from the customer and prepare a formal purchase order. The purchase order will hold the details of the customer, the name of the item to be purchased, the quantity, and the price. Once the order is prepared, it will be sent to the Order Processing department for the necessary approval. If the order is valid and approved, then the department will generate the unique order ID and send it back to the Purchase department. The Purchase department will communicate the order ID back to the customer.<\/p>\n<p>For simplicity, we will look at the following use cases:<\/p>\n<p>&#8211; Prepare an order<\/p>\n<p>&#8211; Place the order<\/p>\n<p><!--more--><\/p>\n<p>The client application will prepare an order and send it to the server application through a business method call. The server application will contain a web service that will process the order and generate a unique order ID. The generation of the unique order ID will signify order approval.<\/p>\n<p style=\"margin-left: 40px; margin-right: 40px;\"><em>In real world applications a unique order ID is always accompanied by the date the order was approved. However, in this example we chose to keep it simple by only generating order ID.<\/em><\/p>\n<p><strong>Developing a service<\/strong><\/p>\n<p>Let&#8217;s look specifically at how to create an Order Processing Web Service and then register it as a Spring bean using a JAX-WS frontend.<\/p>\n<p style=\"margin-left: 40px; margin-right: 40px;\"><em>The Sun-based JAX-WS specification can be found at the following URL: <a href=\"http:\/\/jcp.org\/aboutJava\/communityprocess\/final\/jsr224\/index.html\" target=\"blank\">http:\/\/jcp.org\/aboutJava\/communityprocess\/final\/jsr224\/index.html<\/a><\/em><\/p>\n<p>JAX-WS frontend offers two ways of developing a web service : \u201dCode-first and Contract-first. We will use the <em>Code-first<\/em> approach, that is, we will first create a Java class and convert this into a web service component. The first set of tasks will be to create server-side components.<\/p>\n<p style=\"margin-left: 40px; margin-right: 40px;\"><em>In web service terminology, Code-first is termed as the Bottoms Up approach, and Contract-first is referred to as the Top Down approach.<\/em><\/p>\n<p>To achieve this, we typically perform the following steps:<\/p>\n<ul>\n<li>Create a <strong>Service Endpoint Interface (SEI)<\/strong> and define a business method to be used with the web service.<\/li>\n<li>Create the implementation class and annotate it as a web service.<\/li>\n<li>Create beans.xml and define the service class as a Spring bean using a JAX-WS frontend.<\/li>\n<\/ul>\n<p><strong>Creating a Service Endpoint Interface (SEI)<\/strong><\/p>\n<p>Let&#8217;s first create the SEI for our Order Processing Application. We will name our SEI <em>OrderProcess<\/em>. The following code illustrates the <em>OrderProcess<\/em> SEI:<\/p>\n<pre>package demo.order;\r\n\r\nimport javax.jws.WebService;\r\n\r\n@WebService\r\n\r\npublic interface OrderProcess {\r\n\r\n@WebMethod\r\n\r\nString processOrder(Order order);\r\n\r\n}\r\n\r\n<\/pre>\n<p>As you can see from the preceding code, we created a Service Endpoint Interface named <em>OrderProcess<\/em>. The SEI is just like any other Java interface. It defines an abstract business method <em>processOrder<\/em>. The method takes an Order bean as a parameter and returns an order ID String value. The goal of the <em>processOrder<\/em> method is to process the order placed by the customer and return the unique order ID.<\/p>\n<p>One significant thing to observe is the <em>@WebService<\/em> annotation. The annotation is placed right above the interface definition. It signifies that this interface is not an ordinary interface but a web service interface. This interface is known as <strong>Service Endpoint Interface<\/strong> and will have a business method exposed as a service method to be invoked by the client.<\/p>\n<p>The <em>@WebService<\/em> annotation is part of the JAX-WS annotation library. JAX-WS provides a library of annotations to turn Plain Old Java classes into web services and specifies detailed mapping from a service defined in WSDL to the Java classes that will implement that service. The <em>javax.jws.WebService<\/em> annotation also comes with attributes that completely define a web service. For the moment we will ignore these attributes and proceed with our development.<\/p>\n<p>The <em>javax.jws.@WebMethod<\/em> annotation is optional and is used for customizing the web service operation. The <em>@WebMethod<\/em> annotation provides the operation name and the action elements which are used to customize the <em>name<\/em> attribute of the operation and the SOAP action element in the WSDL document.<\/p>\n<p>The following code shows the <em>Order<\/em> class:<\/p>\n<pre>package demo.order;\r\n\r\nimport javax.xml.bind.annotation.XmlRootElement;\r\n\r\n@XmlRootElement(name = \"Order\")\r\n\r\npublic class Order {\r\n\r\nprivate String customerID;\r\n\r\nprivate String itemID;\r\n\r\nprivate int qty;\r\n\r\nprivate double price;\r\n\r\n\/\/ Contructor\r\n\r\npublic Order() {\r\n\r\n}\r\n\r\npublic String getCustomerID() {\r\n\r\nreturn customerID;\r\n\r\n}\r\n\r\npublic void setCustomerID(String customerID) {\r\n\r\nthis.customerID = customerID;\r\n\r\n}\r\n\r\npublic String getItemID() {\r\n\r\nreturn itemID;\r\n\r\n}\r\n\r\npublic void setItemID(String itemID) {\r\n\r\nthis.itemID = itemID;\r\n\r\n}\r\n\r\npublic int getQty() {\r\n\r\nreturn qty;\r\n\r\n}\r\n\r\npublic void setQty(int qty) {\r\n\r\nthis.qty = qty;\r\n\r\n}\r\n\r\npublic double getPrice() {\r\n\r\nreturn price;\r\n\r\n}\r\n\r\npublic void setPrice(double price) {\r\n\r\nthis.price = price;\r\n\r\n}\r\n\r\n}\r\n\r\n<\/pre>\n<p>As you can see, we have added an <em>@XmlRootElement<\/em> annotation to the <em>Order<\/em> class. The <em>@XmlRootElement<\/em> is part of the <strong>Java Architecture for XML Binding (JAXB)<\/strong> annotation library. JAXB provides data binding capabilities by providing a convenient way to map XML schema to a representation in Java code. The JAXB shields the conversion of XML schema messages in SOAP messages to Java code without having the developers know about XML and SOAP parsing. CXF uses JAXB as the default data binding component.<\/p>\n<p>The <em>@XmlRootElement<\/em> annotations associated with <em>Order<\/em> class map the <em>Order<\/em> class to the XML root element. The attributes contained within the <em>Order<\/em> object by default are mapped to <em>@XmlElement<\/em>. The <em>@XmlElement<\/em> annotations are used to define elements within the XML. The <em>@XmlRootElement<\/em> and <em>@XmlElement<\/em> annotations allow you to customize the namespace and name of the XML element. If no customizations are provided, then the JAXB runtime by default would use the same name of attribute for the XML element. CXF handles this mapping of Java objects to XML using the JAXB Binding.<\/p>\n<p><strong>Developing a service implementation class<\/strong><\/p>\n<p>We will now develop the implementation class that will realize our <em>OrderProcess<\/em> SEI. We will name this implementation class <em>OrderProcessImpl<\/em>. The following code illustrates the service implementation class <em>OrderProcessImpl<\/em>:<\/p>\n<pre>@WebService\r\n\r\npublic class OrderProcessImpl implements OrderProcess {\r\n\r\npublic String processOrder(Order order) {\r\n\r\nString orderID = validate(order);\r\n\r\nreturn orderID;\r\n\r\n}\r\n\r\n\/**\r\n\r\n* Validates the order and returns the order ID\r\n\r\n**\/\r\n\r\nprivate String validate(Order order) {\r\n\r\nString custID = order.getCustomerID();\r\n\r\nString itemID = order.getItemID();\r\n\r\nint qty = order.getQty();\r\n\r\ndouble price = order.getPrice();\r\n\r\nif (custID != null &amp;amp;amp;amp;amp;amp;amp;amp;&amp;amp;amp;amp;amp;amp;amp;amp; itemID != null &amp;amp;amp;amp;amp;amp;amp;amp;&amp;amp;amp;amp;amp;amp;amp;amp; !custID.equals(\"\")\r\n\r\n&amp;amp;amp;amp;amp;amp;amp;amp;&amp;amp;amp;amp;amp;amp;amp;amp; !itemID.equals(\"\") &amp;amp;amp;amp;amp;amp;amp;amp;&amp;amp;amp;amp;amp;amp;amp;amp; qty &amp;amp;amp;amp;amp;amp;amp;gt; 0\r\n\r\n&amp;amp;amp;amp;amp;amp;amp;amp;&amp;amp;amp;amp;amp;amp;amp;amp; price &amp;amp;amp;amp;amp;amp;amp;gt; 0.0) {\r\n\r\nreturn \"ORD1234\";\r\n\r\n}\r\n\r\nreturn null;\r\n\r\n}\r\n\r\n}\r\n\r\n<\/pre>\n<p>As we can see from the preceding code, our implementation class <em>OrderProcessImpl<\/em> is pretty straightforward. It also has <em>@WebService<\/em> annotation defined above the class declaration. The class <em>OrderProcessImpl<\/em> implements <em>OrderProcess<\/em> SEI. The class implements the <em>processOrder<\/em> method. The <em>processOrder<\/em> method checks for the validity of the order by invoking the <em>validate<\/em> method. The <em>validate<\/em> method checks whether the <em>Order<\/em> bean has all the relevant properties valid and not null.<\/p>\n<p>Next we will look at how to publish the OrderProcess JAX-WS web service using Spring configuration.<\/p>\n<p><strong>Spring-based server bean<\/strong><\/p>\n<p>What makes CXF the obvious choice as a web service framework is its use of Spring-based configuration files to publish web service endpoints. It is the use of such configuration files that makes the development of web service convenient and easy with CXF.<\/p>\n<p>Spring provides a lightweight container which works on the concept of <strong>Inversion of Control (IoC)<\/strong> or <strong>Dependency Injection (DI)<\/strong> architecture; it does so through the implementation of a configuration file that defines Java beans and its dependencies. By using Spring you can abstract and wire all the class dependencies in a single configuration file. The configuration file is often referred to as an Application Context or Bean Context file.<\/p>\n<p>We will create a server side Spring-based configuration file and name it as <em>beans.xml<\/em>. The following code illustrates the <em>beans.xml<\/em> configuration file:<\/p>\n<pre><span style=\"font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; line-height: 1.5;\">&lt;beans xmlns=\"http:\/\/www.springframework.org\/schema\/beans\"\r\n\r\nxmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\"\r\n\r\nxmlns:jaxws=\"http:\/\/cxf.apache.org\/jaxws\"\r\n\r\nxsi:schemaLocation=\"\r\n\r\nhttp:\/\/www.springframework.org\/schema\/beans\r\n\r\nhttp:\/\/www.springframework.org\/schema\/beans\/spring-beans.xsd\r\n\r\nhttp:\/\/cxf.apache.org\/jaxws http:\/\/cxf.apache.org\/schemas\/jaxws.xsd\"\/&gt;\r\n\r\n&lt;import resource=\"classpath:META-INF\/cxf\/cxf.xml\" \/&gt;\r\n\r\n&lt;import resource=\"classpath:META-INF\/cxf\/cxf-extension-soap.xml\" \/&gt;\r\n\r\n&lt;import resource=\"classpath:META-INF\/cxf\/cxf-servlet.xml\" \/&gt;\r\n\r\n&lt;jaxws:endpoint\r\n\r\nid=\"orderProcess\"\r\n\r\nimplementor=\"demo.order.OrderProcessImpl\"\r\n\r\naddress=\"\/OrderProcess\" \/&gt;\r\n\r\n&lt;\/beans&gt;\r\n\r\nLet's examine the previous code and understand what it really means. It first defines the necessary namespaces. It then defines a series of <\/span><em style=\"font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; line-height: 1.5;\">&lt;import&gt;<\/em><span style=\"font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; line-height: 1.5;\"> statements. It imports <\/span><em style=\"font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; line-height: 1.5;\">cxf.xml<\/em><span style=\"font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; line-height: 1.5;\">, <\/span><em style=\"font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; line-height: 1.5;\">cxf-extension-soap.xml<\/em><span style=\"font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; line-height: 1.5;\">, and <\/span><em style=\"font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; line-height: 1.5;\">cxf-servlet.xml<\/em><span style=\"font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; line-height: 1.5;\">. These files are Springbased configuration files that define core components of CXF. They are used to kick start CXF runtime and load the necessary infrastructure objects such as WSDL manager, conduit manager, destination factory manager, and so on.<\/span>\r\n<\/pre>\n<p>The <em>&lt;jaxws:endpoint&gt;<\/em> element in the <em>beans.xml<\/em> file specifies the <em>OrderProcess<\/em> web service as a JAX-WS endpoint. The element is defined with the following three attributes:<\/p>\n<ul>\n<li><em>id<\/em> specifies a unique identifier for a bean. In this case, <em>jaxws:endpoint<\/em> is a bean, and the <em>id<\/em> name is <em>orderProcess<\/em>.<\/li>\n<li><em>implementor<\/em> specifies the actual web service implementation class. In this case, our implementor class is <em>OrderProcessImpl<\/em>.<\/li>\n<li><em>address<\/em> specifies the URL address where the endpoint is to be published. The URL address must to be relative to the web context. For our example, the endpoint will be published using the relative path <em>\/OrderProcess<\/em>.<\/li>\n<\/ul>\n<p>The <em>&lt;jaxws:endpoint&gt;<\/em> element signifies that the CXF internally uses JAX-WS frontend to publish the web service. This element definition provides a short and convenient way to publish a web service. A developer need not have to write any Java class to publish a web service.<\/p>\n<p><strong>Developing a client<\/strong><\/p>\n<p>In the previous section we discussed and illustrated how to develop and publish a web service. We now have the server-side code that publishes our <em>OrderProcess<\/em> web service. The next set of tasks will be to create the client-side code that will consume or invoke our <em>OrderProcess<\/em> web service. To achieve this, we will perform the following steps:<\/p>\n<ul>\n<li>Develop the client-beans.xml to define the client factory class as a Spring bean using JAX-WS frontend<\/li>\n<li>Develop a client Java application to invoke the web service<\/li>\n<\/ul>\n<p><strong>Developing a Spring-based client bean<\/strong><\/p>\n<p>We will create a client-side Spring-based configuration file and name it as <em>client-beans.xml<\/em>. The following code illustrates the <em>client-beans.xml<\/em> configuration file:<\/p>\n<pre>&lt;beans xmlns=\"http:\/\/www.springframework.org\/schema\/beans\"\r\n\r\nxmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\"\r\n\r\nxmlns:jaxws=\"http:\/\/cxf.apache.org\/jaxws\"\r\n\r\nxsi:schemaLocation=\"\r\n\r\nhttp:\/\/www.springframework.org\/schema\/beans\r\n\r\nhttp:\/\/www.springframework.org\/schema\/beans\/spring-beans.xsd\r\n\r\nhttp:\/\/cxf.apache.org\/jaxws http:\/\/cxf.apache.org\/schemas\/jaxws.xsd\"\/&gt;\r\n\r\n&lt;jaxws:client id=\"orderClient\" serviceClass=\r\n\r\n\"demo.order.OrderProcess\" address=\r\n\r\n\"http:\/\/localhost:8080\/orderapp\/OrderProcess\" \/&gt;\r\n\r\n&lt;\/beans&gt;\r\n<\/pre>\n<p>The <em>&lt;jaxws:client&gt;<\/em> element in the <em>client-beans.xml<\/em> file specifies the client bean using JAX-WS frontend. The element is defined with the following three attributes:<\/p>\n<ul>\n<li><em>id<\/em> specifies a unique identifier for a bean. In this case, <em>jaxws:client<\/em> is a bean and the <em>id<\/em> name is <em>orderClient<\/em>. The bean will represent an SEI.<\/li>\n<li><em>serviceClass<\/em> specifies the web service SEI. In this case our SEI class is <em>OrderProcess<\/em><\/li>\n<li><em>address<\/em> specifies the URL address where the endpoint is published. In this case the endpoint is published at the URL address: <em>http:\/\/localhost:8080\/orderapp\/OrderProcess<\/em><\/li>\n<\/ul>\n<p><em>&lt;jaxws:client&gt;<\/em> signifies the client bean that represents an <em>OrderProcess<\/em> SEI. The client application will make use of this SEI to invoke the web service. Again, CXF internally uses JAX-WS frontend to define this client-side component.<\/p>\n<p><strong>Developing web service client code<\/strong><\/p>\n<p>We will now create a standalone Java class to invoke our <em>OrderProcess<\/em> web service. The following code illustrates the client invocation of a web service method:<\/p>\n<pre>public final class Client {\r\n\r\npublic Client() {\r\n\r\n}\r\n\r\npublic static void main(String args[]) throws Exception {\r\n\r\n\/\/ START SNIPPET: client\r\n\r\nClassPathXmlApplicationContext context\r\n\r\n= new ClassPathXmlApplicationContext(new String[]\r\n\r\n{\"demo\/order\/client\/client-beans.xml\"});\r\n\r\nOrderProcess client = (OrderProcess) context.\r\n\r\ngetBean(\"orderClient\");\r\n\r\n\/\/ Populate the Order bean\r\n\r\nOrder order = new Order();\r\n\r\norder.setCustomerID(\"C001\");\r\n\r\norder.setItemID(\"I001\");\r\n\r\norder.setQty(100);\r\n\r\norder.setPrice(200.00);\r\n\r\nString orderID = client.processOrder(order);\r\n\r\nString message = (orderID == null) ?\r\n\r\n\"Order not approved\" : \"Order approved;\r\n\r\norder ID is \" + orderID;\r\n\r\nSystem.out.println(message);\r\n\r\nSystem.exit(0);\r\n\r\n<\/pre>\n<p>As you can see from the above code, we have the <em>main<\/em> method that first loads the <em>client-beans.xml<\/em> configuration file. It uses the Spring application context component <em>ClassPathXmlApplicationContext<\/em> to load the configuration file. The context component&#8217;s <em>getBean<\/em> method is passed the bean ID <em>orderClient<\/em>. This method will return the <em>OrderProcess<\/em> SEIcomponent. Using the SEI, we then invoke the web service method <em>processOrder<\/em>. One thing to observe here is that the client always uses the interface to invoke a web service method.<\/p>\n<p>We have now finished developing server and client side components. To summarize, we created the <em>OrderProcess<\/em> service endpoint interface and the implementation class. We then created server and client-side Spring-based configuration files and finally we created the client application. The relevant components are developed and we are all set to run or execute our code. But before we do that, you will have to create one final component that will integrate Spring and CXF.<\/p>\n<p>We need to wire Spring and CXF through <em>web.xml<\/em>. The following code illustrates the <em>web.xml<\/em> file:<\/p>\n<pre>&lt;web-app&gt;\r\n\r\n&lt;context-param&gt;\r\n\r\n&lt;param-name&gt;contextConfigLocation&lt;\/param-name&gt;\r\n\r\n&lt;param-value&gt;WEB-INF\/beans.xml&lt;\/param-value&gt;\r\n\r\n&lt;\/context-param&gt;\r\n\r\n&lt;listener&gt;\r\n\r\n&lt;listener-class&gt;\r\n\r\norg.springframework.web.context.ContextLoaderListener\r\n\r\n&lt;\/listener-class&gt;\r\n\r\n&lt;\/listener&gt;\r\n\r\n&lt;servlet&gt;\r\n\r\n&lt;servlet-name&gt;CXFServlet&lt;\/servlet-name&gt;\r\n\r\n&lt;display-name&gt;CXF Servlet&lt;\/display-name&gt;\r\n\r\n&lt;servlet-class&gt;\r\n\r\norg.apache.cxf.transport.servlet.CXFServlet\r\n\r\n&lt;\/servlet-class&gt;\r\n\r\n&lt;load-on-startup&gt;1&lt;\/load-on-startup&gt;\r\n\r\n&lt;\/servlet&gt;\r\n\r\n&lt;servlet-mapping&gt;\r\n\r\n&lt;servlet-name&gt;CXFServlet&lt;\/servlet-name&gt;\r\n\r\n&lt;url-pattern&gt;\/*&lt;\/url-pattern&gt;\r\n\r\n&lt;\/servlet-mapping&gt;\r\n\r\n&lt;\/web-app&gt;\r\n<\/pre>\n<p>Let&#8217;s go through the above piece of code. The <em>web.xml<\/em>, as we know, is the web application configuration file that defines a servlet and its properties. The file defines <em>CXFServlet<\/em>, which acts as a front runner component that initiates the CXF environment. It defines the <em>listener<\/em> class <em>ContextLoaderListener<\/em>, which is responsible for loading the server-side configuration file <em>beans.xml<\/em>. So upon the web server startup, the order process web service endpoint will be registered and published.<\/p>\n<p><strong>Running the program<\/strong><\/p>\n<p>Before running the program, we will organize the code so far developed in the appropriate folder structure. You can create the folder structure, as shown in the following screenshot, and put the components in the respective sub folders. Following shows the code layout of the project<\/p>\n<p>&nbsp;<\/p>\n<p>The developed code will go into the following:<\/p>\n<ul>\n<li>The Java code will go into the respective package folders<\/li>\n<li>The <em>beans.xml<\/em> and <em>web.xml<\/em> will go into the <em>webapp\\WEB-INF<\/em> folder (the folder name &#8211; WEB-INF should be in caps)<\/li>\n<li>The <em>client-beans.xml<\/em> file will go into the <em>demoorderclient<\/em> folder<\/li>\n<\/ul>\n<p>Once the code is organized, we will go about building and deploying it in the Tomcat server. It will typically involve three steps:<\/p>\n<ul>\n<li>Building the code<\/li>\n<li>Deploying the code<\/li>\n<li>Executing the code<\/li>\n<\/ul>\n<p><strong>Building the code<\/strong><\/p>\n<p>Building the code means compiling the source Java code. We will use the ANT tool to do this. The ANT file is provided in <em>Chapter2orderapp<\/em> folder. The following code illustrates the sample <em>build.xml<\/em> build script:<\/p>\n<pre>&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;\r\n\r\n&lt;project name=\"CXF Chapter2 example\" default=\"build\" basedir=\".\"&gt;\r\n\r\n&lt;import file=\"common_build.xml\"\/&gt;\r\n\r\n&lt;target name=\"client\" description=\r\n\r\n\"run demo client\" depends=\"build\"&gt;\r\n\r\n&lt;property name=\"param\" value=\"\"\/&gt;\r\n\r\n&lt;cxfrun classname=\"demo.order.client.Client\" \/&gt;\r\n\r\n&lt;\/target&gt;\r\n\r\n&lt;target name=\"server\" description=\r\n\r\n\"run demo server\" depends=\"build\"&gt;\r\n\r\n&lt;cxfrun classname=\"demo.spring.servlet.Server\"\/&gt;\r\n\r\n&lt;\/target&gt;\r\n\r\n&lt;property name=\"cxf.war.file.name\" value=\"orderapp\"\/&gt;\r\n\r\n&lt;target name=\"war\" depends=\"build\"&gt;\r\n\r\n&lt;cxfwar filename=\"${cxf.war.file.name}.war\" webxml=\r\n\r\n\"webapp\/WEB-INF\/web.xml\" \/&gt;\r\n\r\n&lt;\/target&gt;\r\n\r\n&lt;\/project&gt;\r\n<\/pre>\n<p>Alongside <em>build.xml<\/em>, you will also find <em>common_build.xml<\/em> in the same folder. The <em>common_buid.xml<\/em> refers to <em>CATALINA_HOME<\/em> environment variable to find location of tomcat installation. Please set <em>CATALINA_HOME <\/em>environment to point to tomcat installation installation. Open the command prompt window, go to <em>C:\/orderapp<\/em> folder and run the <strong>ant<\/strong> command. It will build the code and put the class files under the newly created <em>build<\/em> folder. The following figure shows the output generated upon running the <em>ant<\/em> command.<\/p>\n<p><strong>Deploying the code<\/strong><\/p>\n<p>Having built the code, we will deploy it. Deployment effectively means building and moving the code archive to the server deploy path. We will be using the Tomcat web container to deploy and run the application. To deploy our built code, navigate to<em> project root<\/em> folder, and enter the following command:<\/p>\n<p><strong>ant deploy<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>This will build the WAR file and put it under the Tomcat server <em>webapp<\/em> path. For example, if you have installed the Tomcat under the root folder, then the WAR will be deployed to <em>\/Tomcat\/webapp<\/em> folder.<\/p>\n<p><strong>Executing the code<\/strong><\/p>\n<p>Following code deployment, we are all set to run the Order Process Application. You will execute the Java client program <em>Client.java<\/em> to invoke the Order Process web service. The program will invoke the <em>processOrder<\/em> method that will generate the order ID if the specified order is approved. Before running the client program, we need to start the Tomcat web server. There are several ways of starting the Tomcat server depending on the Tomcat version that is installed. Once the server is started, you need to run the client program by giving the following command at the command prompt window:<\/p>\n<p><strong>ant client<\/strong><br \/>\nUpon executing this command, it will print the order id on the console.\u00a0Thus we have successfully executed the order processing web service.<\/p>\n<p><strong>Summary<\/strong><\/p>\n<p>In this blog we provided an overview of a sample Order Processing Application and saw how to develop a web service with Spring-based configuration. We also saw how to build, deploy, and execute a web service using ANT and Tomcat.<\/p>\n<p>To know, more about how to develop SOAP and RESTful web services, get a copy of my Apache CXF Web Service Book &#8211;<br \/>\n<a href=\"https:\/\/www.amazon.com\/Apache-CXF-Web-Service-Development-ebook\/dp\/B0057EUR9I\/ref=as_li_ss_il?ie=UTF8&amp;qid=1474088993&amp;sr=8-2&amp;keywords=cxf&amp;linkCode=li2&amp;tag=enterpriseiot-20&amp;linkId=a7da16794dec62f516a6e5c2c1b59f61\" target=\"_blank\"><img src=\"\/\/ws-na.amazon-adsystem.com\/widgets\/q?_encoding=UTF8&amp;ASIN=B0057EUR9I&amp;Format=_SL160_&amp;ID=AsinImage&amp;MarketPlace=US&amp;ServiceVersion=20070822&amp;WS=1&amp;tag=enterpriseiot-20\" border=\"0\" \/><\/a><img loading=\"lazy\" style=\"border: none !important; margin: 0px !important;\" src=\"https:\/\/ir-na.amazon-adsystem.com\/e\/ir?t=enterpriseiot-20&amp;l=li2&amp;o=1&amp;a=B0057EUR9I\" alt=\"\" width=\"1\" height=\"1\" border=\"0\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this blog we will look at how to develop a simple web service using CXF and Spring-based configurations. We will take a use case of a Order Processing Application and than develop a web service and client for this use case. The Order Processing Application The objective of the Order Processing Application is to [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[3,13,10,6],"tags":[258,18,14,16],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v16.0.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>CXF and Spring tutorial - Current and Future Technology Trends by Navveen Balani<\/title>\n<meta name=\"description\" content=\"CXF and Spring tutorial -\" \/>\n<link rel=\"canonical\" href=\"https:\/\/navveenbalani.dev\/index.php\/articles\/cxf-and-spring-tutorial\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"CXF and Spring tutorial - Current and Future Technology Trends by Navveen Balani\" \/>\n<meta property=\"og:description\" content=\"CXF and Spring tutorial -\" \/>\n<meta property=\"og:url\" content=\"https:\/\/navveenbalani.dev\/index.php\/articles\/cxf-and-spring-tutorial\/\" \/>\n<meta property=\"og:site_name\" content=\"Current and Future Technology Trends by Navveen Balani\" \/>\n<meta property=\"article:published_time\" content=\"2010-05-16T11:41:11+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2016-09-17T17:10:01+00:00\" \/>\n<meta property=\"og:image\" content=\"\/\/ws-na.amazon-adsystem.com\/widgets\/q?_encoding=UTF8&#038;ASIN=B0057EUR9I&#038;Format=_SL160_&#038;ID=AsinImage&#038;MarketPlace=US&#038;ServiceVersion=20070822&#038;WS=1&#038;tag=enterpriseiot-20\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\">\n\t<meta name=\"twitter:data1\" content=\"16 minutes\">\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"https:\/\/navveenbalani.dev\/#website\",\"url\":\"https:\/\/navveenbalani.dev\/\",\"name\":\"Current and Future Technology Trends by Navveen Balani\",\"description\":\"Current and Future Technology Trends by Navveen Balani\",\"publisher\":{\"@id\":\"https:\/\/navveenbalani.dev\/#\/schema\/person\/51f7ab14b20611d95e3c7fd4ea0950bf\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":\"https:\/\/navveenbalani.dev\/?s={search_term_string}\",\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/navveenbalani.dev\/index.php\/articles\/cxf-and-spring-tutorial\/#primaryimage\",\"inLanguage\":\"en-US\",\"url\":\"\/\/ws-na.amazon-adsystem.com\/widgets\/q?_encoding=UTF8&amp;ASIN=B0057EUR9I&amp;Format=_SL160_&amp;ID=AsinImage&amp;MarketPlace=US&amp;ServiceVersion=20070822&amp;WS=1&amp;tag=enterpriseiot-20\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/navveenbalani.dev\/index.php\/articles\/cxf-and-spring-tutorial\/#webpage\",\"url\":\"https:\/\/navveenbalani.dev\/index.php\/articles\/cxf-and-spring-tutorial\/\",\"name\":\"CXF and Spring tutorial - Current and Future Technology Trends by Navveen Balani\",\"isPartOf\":{\"@id\":\"https:\/\/navveenbalani.dev\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/navveenbalani.dev\/index.php\/articles\/cxf-and-spring-tutorial\/#primaryimage\"},\"datePublished\":\"2010-05-16T11:41:11+00:00\",\"dateModified\":\"2016-09-17T17:10:01+00:00\",\"description\":\"CXF and Spring tutorial -\",\"breadcrumb\":{\"@id\":\"https:\/\/navveenbalani.dev\/index.php\/articles\/cxf-and-spring-tutorial\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/navveenbalani.dev\/index.php\/articles\/cxf-and-spring-tutorial\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/navveenbalani.dev\/index.php\/articles\/cxf-and-spring-tutorial\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"item\":{\"@type\":\"WebPage\",\"@id\":\"https:\/\/navveenbalani.dev\/\",\"url\":\"https:\/\/navveenbalani.dev\/\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"position\":2,\"item\":{\"@type\":\"WebPage\",\"@id\":\"https:\/\/navveenbalani.dev\/index.php\/articles\/cxf-and-spring-tutorial\/\",\"url\":\"https:\/\/navveenbalani.dev\/index.php\/articles\/cxf-and-spring-tutorial\/\",\"name\":\"CXF and Spring tutorial\"}}]},{\"@type\":\"Article\",\"@id\":\"https:\/\/navveenbalani.dev\/index.php\/articles\/cxf-and-spring-tutorial\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/navveenbalani.dev\/index.php\/articles\/cxf-and-spring-tutorial\/#webpage\"},\"author\":{\"@id\":\"https:\/\/navveenbalani.dev\/#\/schema\/person\/51f7ab14b20611d95e3c7fd4ea0950bf\"},\"headline\":\"CXF and Spring tutorial\",\"datePublished\":\"2010-05-16T11:41:11+00:00\",\"dateModified\":\"2016-09-17T17:10:01+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/navveenbalani.dev\/index.php\/articles\/cxf-and-spring-tutorial\/#webpage\"},\"commentCount\":2,\"publisher\":{\"@id\":\"https:\/\/navveenbalani.dev\/#\/schema\/person\/51f7ab14b20611d95e3c7fd4ea0950bf\"},\"image\":{\"@id\":\"https:\/\/navveenbalani.dev\/index.php\/articles\/cxf-and-spring-tutorial\/#primaryimage\"},\"keywords\":\"CXF,SOA,spring,tutorial\",\"articleSection\":\"Articles,CXF,Featured,Web Services\",\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/navveenbalani.dev\/#\/schema\/person\/51f7ab14b20611d95e3c7fd4ea0950bf\",\"name\":\"Navveen\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/navveenbalani.dev\/#personlogo\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/navveenbalani.dev\/wp-content\/uploads\/2019\/07\/navveen_balani.jpeg\",\"width\":200,\"height\":200,\"caption\":\"Navveen\"},\"logo\":{\"@id\":\"https:\/\/navveenbalani.dev\/#personlogo\"},\"sameAs\":[\"http:\/\/naveenbalani.com\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","_links":{"self":[{"href":"https:\/\/navveenbalani.dev\/index.php\/wp-json\/wp\/v2\/posts\/50"}],"collection":[{"href":"https:\/\/navveenbalani.dev\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/navveenbalani.dev\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/navveenbalani.dev\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/navveenbalani.dev\/index.php\/wp-json\/wp\/v2\/comments?post=50"}],"version-history":[{"count":22,"href":"https:\/\/navveenbalani.dev\/index.php\/wp-json\/wp\/v2\/posts\/50\/revisions"}],"predecessor-version":[{"id":2282,"href":"https:\/\/navveenbalani.dev\/index.php\/wp-json\/wp\/v2\/posts\/50\/revisions\/2282"}],"wp:attachment":[{"href":"https:\/\/navveenbalani.dev\/index.php\/wp-json\/wp\/v2\/media?parent=50"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/navveenbalani.dev\/index.php\/wp-json\/wp\/v2\/categories?post=50"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/navveenbalani.dev\/index.php\/wp-json\/wp\/v2\/tags?post=50"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}