{"id":14792,"date":"2013-07-01T22:00:04","date_gmt":"2013-07-01T19:00:04","guid":{"rendered":"http:\/\/www.javacodegeeks.com\/?p=14792"},"modified":"2013-07-02T12:47:43","modified_gmt":"2013-07-02T09:47:43","slug":"developing-restful-services-using-apache-cxf","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/2013\/07\/developing-restful-services-using-apache-cxf.html","title":{"rendered":"Developing RESTful Services using Apache CXF"},"content":{"rendered":"<h2>Introduction<\/h2>\n<p>As you already know there are two ways of developing a web service<\/p>\n<ol>\n<li>Simple Object Access Protocol (SOAP)<\/li>\n<li>Representational State Transfer (REST)<\/li>\n<\/ol>\n<p>Before jumping on how to create a REST based web service using Apache CXF we shall see what is REST. <strong>REST<\/strong> is not a technology and certainly is not a standard of some kind. It is merely an architectural style that chalks down how to write a web service in a certain way. This style was defined by a certain Roy Fielding (ring bells? yep you guessed right, he is one of the architects of HTTP) in 2000. Principal protagonist of a REST architecture is a <strong>Resource<\/strong> which can be uniquely identified by an <strong>Uniform Resource Identifier or URI<\/strong>. State of a resource at any given point of time is represented by a document and is called <strong>Representation<\/strong> of resource. The client can update the state of resource by transferring the representation along with the request. The new representation is now returned to client along with the response. \u00a0The representation contains the information in formats like html, xml, JSON etc that is accepted by the resource. The resource which adheres to rules of REST architecture is called a <strong>RESTfull<\/strong> resource and web service that adheres to this rule are called RESTfull web service.<\/p>\n<h2>Create a project to contain your web service<\/h2>\n<p>I generally do my web development in struts2+spring using maven Strut2 starter archetype to create my web project. To use CXF in my project I add following dependencies to my POM<\/p>\n<pre class=\" brush:xml\">&lt;dependency&gt;\r\n\t&lt;groupId&gt;org.apache.cxf&lt;\/groupId&gt;\r\n\t&lt;artifactId&gt;cxf-rt-frontend-jaxws&lt;\/artifactId&gt;\r\n\t&lt;version&gt;${cxf.version}&lt;\/version&gt;\r\n&lt;\/dependency&gt;\r\n&lt;dependency&gt;\r\n\t&lt;groupId&gt;org.apache.cxf&lt;\/groupId&gt;\r\n\t&lt;artifactId&gt;cxf-rt-transports-http&lt;\/artifactId&gt;\r\n\t&lt;version&gt;${cxf.version}&lt;\/version&gt;\r\n&lt;\/dependency&gt;\r\n&lt;dependency&gt;\r\n\t&lt;groupId&gt;org.apache.cxf&lt;\/groupId&gt;\r\n\t&lt;artifactId&gt;cxf-rt-transports-http-jetty&lt;\/artifactId&gt;\r\n\t&lt;version&gt;${cxf.version}&lt;\/version&gt;\r\n&lt;\/dependency&gt;<\/pre>\n<p>The non maven users can find the details of dependencies to be added in following link: <a href=\"http:\/\/cxf.apache.org\/docs\/using-cxf-with-maven.html\">http:\/\/cxf.apache.org\/docs\/using-cxf-with-maven.html<\/a>. The CXF can be directly downloaded from here: <a href=\"http:\/\/cxf.apache.org\/download.html\">http:\/\/cxf.apache.org\/download.html<\/a><\/p>\n<h2>How to Create a CXF RESTfull web-service?<\/h2>\n<p>Suppose you want to create a RESTfull web service using CXF for managing books in your personal bookshelf. \u00a0You would typically want to perform following operations on the bookshelf<\/p>\n<ol>\n<li>Add a book<\/li>\n<li>Update book information<\/li>\n<li>Delete a book from the shelf<\/li>\n<li>Get a book<\/li>\n<li>Get book list<\/li>\n<li>Get book list by\u00a0author\u00a0name<\/li>\n<\/ol>\n<p><strong>Following steps are needed create such a service<\/strong><\/p>\n<ol>\n<li>Create BookVO, BookList (value object) for passing as representation in request and response.<\/li>\n<li>Bind the objects with request and response.<\/li>\n<li>Create the service implementation class to accept request and generate response.<\/li>\n<li>Registering your webservice with CXF container.<\/li>\n<li>Deploy the service in a web container.<\/li>\n<li>Create clients to invoke methods on the service.<\/li>\n<\/ol>\n<h2>Getting the source code for this tutorial<\/h2>\n<p>I have\u00a0committed\u00a0the source files for this tutorial in SVN.<\/p>\n<ul>\n<li><em>You can download\u00a0the web app from: <\/em><a title=\"http:\/\/subversion.assembla.com\/svn\/weblog4j\/Weblog4jDemo\/trunk\" href=\"http:\/\/subversion.assembla.com\/svn\/weblog4j\/Weblog4jDemo\/trunk\">http:\/\/subversion.assembla.com\/svn\/weblog4j\/Weblog4jDemo\/trunk<\/a><\/li>\n<li><em>You can download\u00a0the\u00a0client from: <\/em><a title=\"http:\/\/subversion.assembla.com\/svn\/weblog4j\/DemoClient\/trunk\" href=\"http:\/\/subversion.assembla.com\/svn\/weblog4j\/DemoClient\/trunk\">http:\/\/subversion.assembla.com\/svn\/weblog4j\/DemoClient\/trunk<\/a><\/li>\n<\/ul>\n<p><strong>Note:<\/strong> Both are ItelliJ maven projects so you can directly import them to your intelliJ IDE or copy over the files manually to other IDE<\/p>\n<h2>Create BookVO (value object) for passing as representation in request and response.<\/h2>\n<h4><em>BookVO Class<\/em><\/h4>\n<pre class=\" brush:java\">package com.aranin.weblog4j.vo;\r\n\r\nimport javax.xml.bind.annotation.XmlRootElement;\r\nimport javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;\r\nimport java.io.Serializable;\r\n\r\n@XmlRootElement(name=\"Book\")\r\npublic class BookVO implements Serializable{\r\n\r\nprivate long bookId;\r\nprivate String bookName;\r\nprivate String author;\r\n\r\npublic long getBookId() {\r\nreturn bookId;\r\n}\r\n\r\npublic void setBookId(long bucketId) {\r\nthis.bookId = bookId;\r\n}\r\n\r\npublic String getBookName() {\r\nreturn bookName;\r\n}\r\n\r\npublic void setBookName(String bookName) {\r\nthis.bookName = bookName;\r\n}\r\n\r\npublic String getAuthor() {\r\nreturn author;\r\n}\r\n\r\npublic void setAuthor(String author) {\r\nthis.author = author;\r\n}\r\n}<\/pre>\n<h4>BookList Class<\/h4>\n<pre class=\" brush:java\">package com.aranin.weblog4j.vo;\r\n\r\nimport javax.xml.bind.annotation.XmlRootElement;\r\nimport java.util.ArrayList;\r\nimport java.util.List;\r\n\r\n@XmlRootElement(name=\"BookList\")\r\npublic class BookList {\r\nprivate List&lt;BookVO&gt; bookList;\r\n\r\npublic List&lt;BookVO&gt; getBookList() {\r\nif(bookList == null){\r\nbookList = new ArrayList&lt;BookVO&gt;();\r\n}\r\nreturn bookList;\r\n}\r\n\r\npublic void setBookList(List&lt;BookVO&gt; bookList) {\r\nthis.bookList = bookList;\r\n}\r\n}<\/pre>\n<h2>Bind the Data object i.e. BookVO with request and response<\/h2>\n<p>To bind the BookVO with the request or response it needs to serialized into either XML or JSON streams. The serialization needs to be done using one of the data binding components. CXF uses JAXB for default data binding component. JaXB uses <strong>@XmlRootElement<\/strong> annotation to map the data object to the xml. You can see the use of XmlRootElement annotation in code above.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<h2>Create the service implementation class to accept request and generate response<\/h2>\n<p>Let us see how a CXF RestFull webservice looks. We will create a BookService class which will perform add,update,delete and get operations on BookSelf.<\/p>\n<h4>BookService Class<\/h4>\n<pre class=\" brush:java\">package com.aranin.weblog4j.services.rest;\r\n\r\nimport com.aranin.weblog4j.hashdb.HashDB;\r\nimport com.aranin.weblog4j.vo.BookVO;\r\nimport org.slf4j.Logger;\r\nimport org.slf4j.LoggerFactory;\r\n\r\nimport javax.ws.rs.*;\r\nimport javax.ws.rs.core.Response;\r\nimport java.io.UnsupportedEncodingException;\r\nimport java.net.URLDecoder;\r\n\r\n\/**\r\n * Created by IntelliJ IDEA.\r\n * User: Niraj Singh\r\n * Date: 3\/13\/13\r\n * Time: 3:58 PM\r\n * To change this template use File | Settings | File Templates.\r\n *\/\r\npublic class BookService {\r\n\r\nprotected final Logger log = LoggerFactory.getLogger(BookService.class);\r\n\r\n    @POST\r\n    @Path(\"\/getbook\/{name}\")\r\n    @Produces({\"application\/xml\",\"application\/json\"})\r\n    @Consumes({\"application\/xml\",\"application\/json\",\"application\/x-www-form-urlencoded\"})\r\n    public Response getBucket(@PathParam(\"name\") String name) {\r\n        log.debug(\"name : \" + name);\r\n        BookVO bookVO = null;\r\n        try {\r\n            bookVO = HashDB.getBook(URLDecoder.decode(name, \"UTF-8\"));\r\n        } catch (UnsupportedEncodingException e) {\r\n            e.printStackTrace();  \/\/To change body of catch statement use File | Settings | File Templates.\r\n        }\r\n\r\n        if(bookVO == null){\r\n            return Response.status(Response.Status.BAD_REQUEST).build();\r\n        }else{\r\n            return Response.ok(bookVO).build();\r\n        }\r\n    }\r\n\r\n    @POST\r\n    @Path(\"\/addbook\")\r\n    @Produces({\"application\/xml\",\"application\/json\"})\r\n    @Consumes({\"application\/xml\",\"application\/json\",\"application\/x-www-form-urlencoded\"})\r\n    public Response addBook(@FormParam(\"name\") String bookName,\r\n                            @FormParam(\"author\") String author) {\r\n        log.debug(\"inside addBook\");\r\n        BookVO bookVO = new BookVO();\r\n        bookVO.setBookName(bookName);\r\n        bookVO.setAuthor(author);\r\n        HashDB.insertBook(bookVO);\r\n        if(HashDB.getBook(bookName) == null){\r\n            return Response.status(Response.Status.BAD_REQUEST).build();\r\n        }else{\r\n            return Response.ok(bookVO).build();\r\n        }\r\n\r\n    }\r\n}<\/pre>\n<p>You can see two methods in the BookService class getBook and addBook. They are service methods for getting and adding a book. Rest of the methods for update delete etc can be written in same way. Now lets see what the various annotations and method call means.<\/p>\n<ul>\n<li>@POST \u2013 This indicates that service receives only POST request.<\/li>\n<li>@Path \u2013 This is the path of webservice. So the webservice can be invoked using following Url &lt;base_url&gt;\/bookservice\/getbook\/{name} for fetching, &lt;base_url&gt;\/bookservice\/addbook for adding.<\/li>\n<li>@Produces \u2013 Indicates the MIME type of response generated. In our case it is both application\/xml and application\/json.<\/li>\n<li>@Consumes \u2013 Indicates the MIME type of request which this service can consume.<\/li>\n<\/ul>\n<p>Registering your webservice with CXF container.<\/p>\n<p>One cool thing with CXF is that it uses a spring based configuration for registering its webservice endpoints so let us create a beans.xml in WEB-INF and configure the CXF in web.xml. For this first we need to wire the beans.xml to get loaded by spring container.<\/p>\n<pre class=\" brush:xml\">&lt;context-param&gt;\r\n&lt;param-name&gt;contextConfigLocation&lt;\/param-name&gt;\r\n&lt;param-value&gt;\/WEB-INF\/beans.xml,\/WEB-INF\/applicationContext.xml&lt;\/param-value&gt;\r\n&lt;\/context-param&gt;<\/pre>\n<p>Secondly load the register the CXFServlet in web.xml.<\/p>\n<pre class=\" brush:xml\">&lt;servlet&gt;\r\n&lt;servlet-name&gt;CXFServlet&lt;\/servlet-name&gt;\r\n&lt;display-name&gt;CXF Servlet&lt;\/display-name&gt;\r\n&lt;servlet-class&gt;\r\norg.apache.cxf.transport.servlet.CXFServlet\r\n&lt;\/servlet-class&gt;\r\n&lt;load-on-startup&gt;2&lt;\/load-on-startup&gt;\r\n&lt;\/servlet&gt;\r\n\r\n&lt;servlet-mapping&gt;\r\n&lt;servlet-name&gt;CXFServlet&lt;\/servlet-name&gt;\r\n&lt;url-pattern&gt;\/*&lt;\/url-pattern&gt;\r\n&lt;\/servlet-mapping&gt;<\/pre>\n<p>Now open your bean.xml and register your bookservice end point.<\/p>\n<pre class=\" brush:xml\">&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;\r\n&lt;beans xmlns=\"http:\/\/www.springframework.org\/schema\/beans\"\r\n\txmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\"\r\n\txmlns:jaxws=\"http:\/\/cxf.apache.org\/jaxws\"\r\n    xmlns:jaxrs=\"http:\/\/cxf.apache.org\/jaxrs\"\r\n\txsi: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\/jaxrs\r\n\r\nhttp:\/\/cxf.apache.org\/schemas\/jaxrs.xsd\r\n\r\nhttp:\/\/cxf.apache.org\/jaxws\r\n\r\nhttp:\/\/cxf.apache.org\/schemas\/jaxws.xsd\"&gt;\r\n\r\n\t&lt;import resource=\"classpath:META-INF\/cxf\/cxf.xml\" \/&gt;\r\n\t&lt;import resource=\"classpath:META-INF\/cxf\/cxf-extension-soap.xml\" \/&gt;\r\n\t&lt;import resource=\"classpath:META-INF\/cxf\/cxf-servlet.xml\" \/&gt;\r\n\r\n\t&lt;jaxws:endpoint\r\n\t  id=\"bookShelfService\"\r\n\t  implementor=\"com.aranin.weblog4j.services.BookShelfServiceImpl\"\r\n\t  address=\"\/bookshelfservice\" \/&gt;\r\n\r\n    &lt;bean id=\"bookserviceclass\" class=\"com.aranin.weblog4j.services.rest.BookService\"\/&gt;\r\n\r\n    &lt;jaxrs:server id=\"bookservice\" address=\"\/bookservice\"&gt;\r\n        &lt;jaxrs:serviceBeans&gt;\r\n        &lt;ref bean=\"bookserviceclass\" \/&gt;\r\n        &lt;\/jaxrs:serviceBeans&gt;\r\n    &lt;\/jaxrs:server&gt;\r\n\r\n&lt;\/beans&gt;<\/pre>\n<p>Now your webservice is ready. Build your web application and deploy it in any servlet container.<\/p>\n<h2>Creating Client for your webservice<\/h2>\n<p>Clients can be created in many ways, I have used apache Http Components to write my client. The libraries can be found in\u00a0<a href=\"http:\/\/hc.apache.org\/httpclient-3.x\/\">http:\/\/hc.apache.org\/httpclient-3.x\/<\/a>.<\/p>\n<p>Maven user can pull the Http components jar using following<\/p>\n<pre class=\" brush:xml\">&lt;dependency&gt;\r\n&lt;groupId&gt;commons-httpclient&lt;\/groupId&gt;\r\n&lt;artifactId&gt;commons-httpclient&lt;\/artifactId&gt;\r\n&lt;version&gt;3.1&lt;\/version&gt;\r\n&lt;\/dependency&gt;\r\n\r\n&lt;dependency&gt;\r\n&lt;groupId&gt;org.apache.httpcomponents&lt;\/groupId&gt;\r\n&lt;artifactId&gt;httpclient&lt;\/artifactId&gt;\r\n&lt;version&gt;4.1.3&lt;\/version&gt;\r\n&lt;scope&gt;compile&lt;\/scope&gt;\r\n&lt;\/dependency&gt;\r\n\r\n&lt;dependency&gt;\r\n&lt;groupId&gt;org.apache.httpcomponents&lt;\/groupId&gt;\r\n&lt;artifactId&gt;httpmime&lt;\/artifactId&gt;\r\n&lt;version&gt;4.1.3&lt;\/version&gt;\r\n&lt;scope&gt;compile&lt;\/scope&gt;\r\n&lt;\/dependency&gt;<\/pre>\n<p>Now to invoke the webservice I have created a util class called DemoRestClient.<\/p>\n<pre class=\" brush:java\">package com.aranin.weblog4j.client;\r\n\r\nimport com.aranin.weblog4j.vo.BookVO;\r\nimport org.apache.commons.httpclient.Header;\r\nimport org.apache.commons.httpclient.HttpClient;\r\nimport org.apache.commons.httpclient.methods.PostMethod;\r\n\r\nimport java.net.URLEncoder;\r\n\r\n\/**\r\n * Created by IntelliJ IDEA.\r\n * User: Niraj Singh\r\n * Date: 3\/13\/13\r\n * Time: 4:15 PM\r\n * To change this template use File | Settings | File Templates.\r\n *\/\r\npublic class DemoRestClient {\r\n    public static void main(String[] args){\r\n        DemoRestClient restClient = new DemoRestClient();\r\n        try {\r\n            \/\/restClient.addBook(\"Naked Sun\", \"Issac Asimov\");\r\n            restClient.getBook(\"Naked Sun\");\r\n        } catch (Exception e) {\r\n            e.printStackTrace(); \/\/To change body of catch statement use File | Settings | File Templates.\r\n        }\r\n\r\n    }\r\n\r\n    public BookVO getBook(String bookName) throws Exception {\r\n\r\n        String output = null;\r\n        try{\r\n            String url = \"http:\/\/localhost:8080\/weblog4jdemo\/bookservice\/getbook\/\";\r\n\r\n            url = url + URLEncoder.encode(bookName, \"UTF-8\");\r\n\r\n            HttpClient client = new HttpClient();\r\n            PostMethod mPost = new PostMethod(url);\r\n            client.executeMethod( mPost );\r\n            Header mtHeader = new Header();\r\n            mtHeader.setName(\"content-type\");\r\n            mtHeader.setValue(\"application\/x-www-form-urlencoded\");\r\n            mtHeader.setName(\"accept\");\r\n            mtHeader.setValue(\"application\/xml\");\r\n            mPost.addRequestHeader(mtHeader);\r\n            client.executeMethod(mPost);\r\n            output = mPost.getResponseBodyAsString( );\r\n            mPost.releaseConnection( );\r\n            System.out.println(\"out : \" + output);\r\n        }catch(Exception e){\r\n            throw new Exception(\"Exception in retriving group page info : \" + e);\r\n        }\r\n        return null;\r\n    }\r\n\r\n    public void addBook(String bookName, String author) throws Exception {\r\n\r\n        String output = null;\r\n        try{\r\n            String url = \"http:\/\/localhost:8080\/weblog4jdemo\/bookservice\/addbook\";\r\n            HttpClient client = new HttpClient();\r\n            PostMethod mPost = new PostMethod(url);\r\n            mPost.addParameter(\"name\", \"Naked Sun\");\r\n            mPost.addParameter(\"author\", \"Issac Asimov\");\r\n            Header mtHeader = new Header();\r\n            mtHeader.setName(\"content-type\");\r\n            mtHeader.setValue(\"application\/x-www-form-urlencoded\");\r\n            mtHeader.setName(\"accept\");\r\n            mtHeader.setValue(\"application\/xml\");\r\n            \/\/mtHeader.setValue(\"application\/json\");\r\n            mPost.addRequestHeader(mtHeader);\r\n            client.executeMethod(mPost);\r\n            output = mPost.getResponseBodyAsString( );\r\n            mPost.releaseConnection( );\r\n            System.out.println(\"output : \" + output);\r\n        }catch(Exception e){\r\n        throw new Exception(\"Exception in adding bucket : \" + e);\r\n        }\r\n\r\n    }\r\n\r\n}<\/pre>\n<p>Run this client to see the output of your webservice. Right now it will sending xmloutput as the response accept header is \u201capplication\/xml\u201d. You can change it to application\/json to get an json output.<\/p>\n<p>Thats all folks. This is a very basic introduction to developing RestFull web service using apache CXF, there is a lot more to explore. Happy exploring, till then good bye. Please drop some comments as and if you read this to keep me inspired.<br \/>\n&nbsp;<\/p>\n<div style=\"border: 1px solid #D8D8D8; background: #FAFAFA; width: 100%; padding-left: 5px;\"><b><i>Reference: <\/i><\/b><a href=\"http:\/\/weblog4j.com\/2012\/03\/15\/developing-restful-services-using-apache-cxf\/\">Developing RESTful Services using Apache CXF<\/a> from our <a href=\"http:\/\/www.javacodegeeks.com\/jcg\">JCG partner<\/a> Niraj Singh at the <a href=\"http:\/\/weblog4j.com\/\">Weblog4j<\/a> blog.<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Introduction As you already know there are two ways of developing a web service Simple Object Access Protocol (SOAP) Representational State Transfer (REST) Before jumping on how to create a REST based web service using Apache CXF we shall see what is REST. REST is not a technology and certainly is not a standard of &hellip;<\/p>\n","protected":false},"author":457,"featured_media":112,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[171,54],"class_list":["post-14792","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-enterprise-java","tag-apache-cxf","tag-restful-web-services"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Developing RESTful Services using Apache CXF<\/title>\n<meta name=\"description\" content=\"Introduction As you already know there are two ways of developing a web service Simple Object Access Protocol (SOAP) Representational State Transfer\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.javacodegeeks.com\/2013\/07\/developing-restful-services-using-apache-cxf.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Developing RESTful Services using Apache CXF\" \/>\n<meta property=\"og:description\" content=\"Introduction As you already know there are two ways of developing a web service Simple Object Access Protocol (SOAP) Representational State Transfer\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/2013\/07\/developing-restful-services-using-apache-cxf.html\" \/>\n<meta property=\"og:site_name\" content=\"Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2013-07-01T19:00:04+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2013-07-02T09:47:43+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/enterprise-java-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Niraj Singh\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Niraj Singh\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"10 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/07\\\/developing-restful-services-using-apache-cxf.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/07\\\/developing-restful-services-using-apache-cxf.html\"},\"author\":{\"name\":\"Niraj Singh\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/c1701df4314ba15d96a7e8ee21167280\"},\"headline\":\"Developing RESTful Services using Apache CXF\",\"datePublished\":\"2013-07-01T19:00:04+00:00\",\"dateModified\":\"2013-07-02T09:47:43+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/07\\\/developing-restful-services-using-apache-cxf.html\"},\"wordCount\":990,\"commentCount\":30,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/07\\\/developing-restful-services-using-apache-cxf.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/enterprise-java-logo.jpg\",\"keywords\":[\"Apache CXF\",\"RESTful Web Services\"],\"articleSection\":[\"Enterprise Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/07\\\/developing-restful-services-using-apache-cxf.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/07\\\/developing-restful-services-using-apache-cxf.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/07\\\/developing-restful-services-using-apache-cxf.html\",\"name\":\"Developing RESTful Services using Apache CXF\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/07\\\/developing-restful-services-using-apache-cxf.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/07\\\/developing-restful-services-using-apache-cxf.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/enterprise-java-logo.jpg\",\"datePublished\":\"2013-07-01T19:00:04+00:00\",\"dateModified\":\"2013-07-02T09:47:43+00:00\",\"description\":\"Introduction As you already know there are two ways of developing a web service Simple Object Access Protocol (SOAP) Representational State Transfer\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/07\\\/developing-restful-services-using-apache-cxf.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/07\\\/developing-restful-services-using-apache-cxf.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/07\\\/developing-restful-services-using-apache-cxf.html#primaryimage\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/enterprise-java-logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/enterprise-java-logo.jpg\",\"width\":150,\"height\":150,\"caption\":\"java-interview-questions-answers\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/07\\\/developing-restful-services-using-apache-cxf.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Enterprise Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\\\/enterprise-java\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Developing RESTful Services using Apache CXF\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Developers Resource Center\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.javacodegeeks.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/javacodegeeks\",\"https:\\\/\\\/x.com\\\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/c1701df4314ba15d96a7e8ee21167280\",\"name\":\"Niraj Singh\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/147bedcf1582a3657c88a171d9057c1f6e52c9cc61db7ebff937824d89ed3995?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/147bedcf1582a3657c88a171d9057c1f6e52c9cc61db7ebff937824d89ed3995?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/147bedcf1582a3657c88a171d9057c1f6e52c9cc61db7ebff937824d89ed3995?s=96&d=mm&r=g\",\"caption\":\"Niraj Singh\"},\"sameAs\":[\"http:\\\/\\\/weblog4j.com\\\/\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/niraj-singh\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Developing RESTful Services using Apache CXF","description":"Introduction As you already know there are two ways of developing a web service Simple Object Access Protocol (SOAP) Representational State Transfer","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.javacodegeeks.com\/2013\/07\/developing-restful-services-using-apache-cxf.html","og_locale":"en_US","og_type":"article","og_title":"Developing RESTful Services using Apache CXF","og_description":"Introduction As you already know there are two ways of developing a web service Simple Object Access Protocol (SOAP) Representational State Transfer","og_url":"https:\/\/www.javacodegeeks.com\/2013\/07\/developing-restful-services-using-apache-cxf.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2013-07-01T19:00:04+00:00","article_modified_time":"2013-07-02T09:47:43+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/enterprise-java-logo.jpg","type":"image\/jpeg"}],"author":"Niraj Singh","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Niraj Singh","Est. reading time":"10 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/2013\/07\/developing-restful-services-using-apache-cxf.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/2013\/07\/developing-restful-services-using-apache-cxf.html"},"author":{"name":"Niraj Singh","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/c1701df4314ba15d96a7e8ee21167280"},"headline":"Developing RESTful Services using Apache CXF","datePublished":"2013-07-01T19:00:04+00:00","dateModified":"2013-07-02T09:47:43+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2013\/07\/developing-restful-services-using-apache-cxf.html"},"wordCount":990,"commentCount":30,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2013\/07\/developing-restful-services-using-apache-cxf.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/enterprise-java-logo.jpg","keywords":["Apache CXF","RESTful Web Services"],"articleSection":["Enterprise Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/2013\/07\/developing-restful-services-using-apache-cxf.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/2013\/07\/developing-restful-services-using-apache-cxf.html","url":"https:\/\/www.javacodegeeks.com\/2013\/07\/developing-restful-services-using-apache-cxf.html","name":"Developing RESTful Services using Apache CXF","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2013\/07\/developing-restful-services-using-apache-cxf.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2013\/07\/developing-restful-services-using-apache-cxf.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/enterprise-java-logo.jpg","datePublished":"2013-07-01T19:00:04+00:00","dateModified":"2013-07-02T09:47:43+00:00","description":"Introduction As you already know there are two ways of developing a web service Simple Object Access Protocol (SOAP) Representational State Transfer","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/2013\/07\/developing-restful-services-using-apache-cxf.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/2013\/07\/developing-restful-services-using-apache-cxf.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/2013\/07\/developing-restful-services-using-apache-cxf.html#primaryimage","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/enterprise-java-logo.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/enterprise-java-logo.jpg","width":150,"height":150,"caption":"java-interview-questions-answers"},{"@type":"BreadcrumbList","@id":"https:\/\/www.javacodegeeks.com\/2013\/07\/developing-restful-services-using-apache-cxf.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java","item":"https:\/\/www.javacodegeeks.com\/category\/java"},{"@type":"ListItem","position":3,"name":"Enterprise Java","item":"https:\/\/www.javacodegeeks.com\/category\/java\/enterprise-java"},{"@type":"ListItem","position":4,"name":"Developing RESTful Services using Apache CXF"}]},{"@type":"WebSite","@id":"https:\/\/www.javacodegeeks.com\/#website","url":"https:\/\/www.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Developers Resource Center","publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/c1701df4314ba15d96a7e8ee21167280","name":"Niraj Singh","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/147bedcf1582a3657c88a171d9057c1f6e52c9cc61db7ebff937824d89ed3995?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/147bedcf1582a3657c88a171d9057c1f6e52c9cc61db7ebff937824d89ed3995?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/147bedcf1582a3657c88a171d9057c1f6e52c9cc61db7ebff937824d89ed3995?s=96&d=mm&r=g","caption":"Niraj Singh"},"sameAs":["http:\/\/weblog4j.com\/"],"url":"https:\/\/www.javacodegeeks.com\/author\/niraj-singh"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/14792","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/users\/457"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=14792"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/14792\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media\/112"}],"wp:attachment":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=14792"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=14792"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=14792"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}