| <!DOCTYPE html> |
| <!-- |
| | Generated by Apache Maven Doxia Site Renderer 1.7.4 at 2018-05-19 |
| | Rendered using Apache Maven Fluido Skin 1.6 |
| --> |
| <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> |
| <head> |
| <meta charset="UTF-8" /> |
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> |
| <meta name="Date-Revision-yyyymmdd" content="20180519" /> |
| <meta http-equiv="Content-Language" content="en" /> |
| <title>Apache Axis2 – RESTful Web Services Support</title> |
| <link rel="stylesheet" href="../css/apache-maven-fluido-1.6.min.css" /> |
| <link rel="stylesheet" href="../css/site.css" /> |
| <link rel="stylesheet" href="../css/print.css" media="print" /> |
| <script type="text/javascript" src="../js/apache-maven-fluido-1.6.min.js"></script> |
| <meta http-equiv="content-type" content="" /> </head> |
| <body class="topBarDisabled"> |
| <div class="container-fluid"> |
| <div id="banner"> |
| <div class="pull-left"><a href="http://www.apache.org/" id="bannerLeft"><img src="http://www.apache.org/images/asf_logo_wide.png" alt="Apache Axis2"/></a></div> |
| <div class="pull-right"><a href=".././" id="bannerRight"><img src="../images/axis.jpg" /></a></div> |
| <div class="clear"><hr/></div> |
| </div> |
| |
| <div id="breadcrumbs"> |
| <ul class="breadcrumb"> |
| <li id="publishDate">Last Published: 2018-05-19<span class="divider">|</span> |
| </li> |
| <li id="projectVersion">Version: 1.7.8<span class="divider">|</span></li> |
| <li class=""><a href="http://www.apache.org" class="externalLink" title="Apache">Apache</a><span class="divider">/</span></li> |
| <li class=""><a href="../index.html" title="Axis2/Java">Axis2/Java</a><span class="divider">/</span></li> |
| <li class="active ">RESTful Web Services Support</li> |
| </ul> |
| </div> |
| <div class="row-fluid"> |
| <div id="leftColumn" class="span2"> |
| <div class="well sidebar-nav"> |
| <ul class="nav nav-list"> |
| <li class="nav-header">Axis2/Java</li> |
| <li><a href="../index.html" title="Home"><span class="none"></span>Home</a> </li> |
| <li><a href="../download.html" title="Downloads"><span class="none"></span>Downloads</a> </li> |
| <li><a href="javascript:void(0)" title="Release Notes"><span class="icon-chevron-down"></span>Release Notes</a> |
| <ul class="nav nav-list"> |
| <li><a href="../release-notes/1.6.1.html" title="1.6.1"><span class="none"></span>1.6.1</a> </li> |
| <li><a href="../release-notes/1.6.2.html" title="1.6.2"><span class="none"></span>1.6.2</a> </li> |
| <li><a href="../release-notes/1.6.3.html" title="1.6.3"><span class="none"></span>1.6.3</a> </li> |
| <li><a href="../release-notes/1.6.4.html" title="1.6.4"><span class="none"></span>1.6.4</a> </li> |
| <li><a href="../release-notes/1.7.0.html" title="1.7.0"><span class="none"></span>1.7.0</a> </li> |
| <li><a href="../release-notes/1.7.1.html" title="1.7.1"><span class="none"></span>1.7.1</a> </li> |
| <li><a href="../release-notes/1.7.2.html" title="1.7.2"><span class="none"></span>1.7.2</a> </li> |
| <li><a href="../release-notes/1.7.3.html" title="1.7.3"><span class="none"></span>1.7.3</a> </li> |
| <li><a href="../release-notes/1.7.4.html" title="1.7.4"><span class="none"></span>1.7.4</a> </li> |
| <li><a href="../release-notes/1.7.5.html" title="1.7.5"><span class="none"></span>1.7.5</a> </li> |
| <li><a href="../release-notes/1.7.6.html" title="1.7.6"><span class="none"></span>1.7.6</a> </li> |
| <li><a href="../release-notes/1.7.7.html" title="1.7.7"><span class="none"></span>1.7.7</a> </li> |
| <li><a href="../release-notes/1.7.8.html" title="1.7.8"><span class="none"></span>1.7.8</a> </li> |
| </ul> |
| </li> |
| <li><a href="../modules/index.html" title="Modules"><span class="none"></span>Modules</a> </li> |
| <li><a href="../tools/index.html" title="Tools"><span class="none"></span>Tools</a> </li> |
| <li class="nav-header">Documentation</li> |
| <li><a href="../docs/toc.html" title="Table of Contents"><span class="none"></span>Table of Contents</a> </li> |
| <li><a href="../docs/installationguide.html" title="Installation Guide"><span class="none"></span>Installation Guide</a> </li> |
| <li><a href="../docs/quickstartguide.html" title="QuickStart Guide"><span class="none"></span>QuickStart Guide</a> </li> |
| <li><a href="../docs/userguide.html" title="User Guide"><span class="none"></span>User Guide</a> </li> |
| <li><a href="../docs/jaxws-guide.html" title="JAXWS Guide"><span class="none"></span>JAXWS Guide</a> </li> |
| <li><a href="../docs/pojoguide.html" title="POJO Guide"><span class="none"></span>POJO Guide</a> </li> |
| <li><a href="../docs/spring.html" title="Spring Guide"><span class="none"></span>Spring Guide</a> </li> |
| <li><a href="../docs/webadminguide.html" title="Web Administrator's Guide"><span class="none"></span>Web Administrator's Guide</a> </li> |
| <li><a href="../docs/migration.html" title="Migration Guide (from Axis1)"><span class="none"></span>Migration Guide (from Axis1)</a> </li> |
| <li class="nav-header">Resources</li> |
| <li><a href="../faq.html" title="FAQ"><span class="none"></span>FAQ</a> </li> |
| <li><a href="../articles.html" title="Articles"><span class="none"></span>Articles</a> </li> |
| <li><a href="http://wiki.apache.org/ws/FrontPage/Axis2/" class="externalLink" title="Wiki"><span class="none"></span>Wiki</a> </li> |
| <li><a href="../refLib.html" title="Reference Library"><span class="none"></span>Reference Library</a> </li> |
| <li><a href="../apidocs/index.html" title="Online Java Docs"><span class="none"></span>Online Java Docs</a> </li> |
| <li class="nav-header">Get Involved</li> |
| <li><a href="../overview.html" title="Overview"><span class="none"></span>Overview</a> </li> |
| <li><a href="../svn.html" title="Checkout the Source"><span class="none"></span>Checkout the Source</a> </li> |
| <li><a href="../mail-lists.html" title="Mailing Lists"><span class="none"></span>Mailing Lists</a> </li> |
| <li><a href="../release-process.html" title="Release Process"><span class="none"></span>Release Process</a> </li> |
| <li><a href="../guidelines.html" title="Developer Guidelines"><span class="none"></span>Developer Guidelines</a> </li> |
| <li><a href="../siteHowTo.html" title="Build the Site"><span class="none"></span>Build the Site</a> </li> |
| <li class="nav-header">Project Information</li> |
| <li><a href="../team-list.html" title="Project Team"><span class="none"></span>Project Team</a> </li> |
| <li><a href="../issue-tracking.html" title="Issue Tracking"><span class="none"></span>Issue Tracking</a> </li> |
| <li><a href="http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/" class="externalLink" title="Source Code"><span class="none"></span>Source Code</a> </li> |
| <li><a href="../thanks.html" title="Acknowledgements"><span class="none"></span>Acknowledgements</a> </li> |
| <li class="nav-header">Apache</li> |
| <li><a href="http://www.apache.org/licenses/LICENSE-2.0.html" class="externalLink" title="License"><span class="none"></span>License</a> </li> |
| <li><a href="http://www.apache.org/foundation/sponsorship.html" class="externalLink" title="Sponsorship"><span class="none"></span>Sponsorship</a> </li> |
| <li><a href="http://www.apache.org/foundation/thanks.html" class="externalLink" title="Thanks"><span class="none"></span>Thanks</a> </li> |
| <li><a href="http://www.apache.org/security/" class="externalLink" title="Security"><span class="none"></span>Security</a> </li> |
| </ul> |
| <hr /> |
| <div id="poweredBy"> |
| <div class="clear"></div> |
| <div class="clear"></div> |
| <div class="clear"></div> |
| <div class="clear"></div> |
| <a href="http://maven.apache.org/" title="Built by Maven" class="poweredBy"><img class="builtBy" alt="Built by Maven" src="../images/logos/maven-feather.png" /></a> |
| </div> |
| </div> |
| </div> |
| <div id="bodyColumn" class="span10" > |
| <html> |
| |
| |
| <h1>RESTful Web Services Support</h1> |
| |
| |
| <p>This document presents an introduction on REST and REST with HTTP POST and |
| GET.</p> |
| |
| |
| <div class="section"> |
| <h2><a name="Content"></a>Content</h2> |
| |
| <ul> |
| |
| <li><a href="#intro">Introduction</a></li> |
| |
| <li><a href="#rest_with_post">Doing REST Web Services with HTTP POST</a> |
| |
| <ul> |
| |
| <li><a href="#sample">Sample REST - HTTP POST Client</a></li> |
| </ul> |
| </li> |
| |
| <li><a href="#rest_with_get">Access a REST Web Service via HTTP GET</a></li> |
| </ul> |
| <a name="intro"></a> |
| |
| |
| <div class="section"> |
| <h2><a name="Introduction"></a>Introduction</h2> |
| |
| |
| <p>WSDL 2.0 HTTP Binding defines a way to implement REST (Representational |
| State Transfer) with Web services. Axis2 implements the most defined HTTP |
| binding specification. REST Web services are a reduced subset of the usual |
| Web service stack.</p> |
| |
| |
| <p>The Axis2 REST implementation assumes the following properties:</p> |
| |
| <ol style="list-style-type: decimal"> |
| |
| <li>REST Web services are Synchronous and Request Response in nature.</li> |
| |
| <li>When REST Web services are accessed via GET, the service and the |
| operations are identified based on the URL. The parameters are assumed as |
| parameters of the Web service. In this case, the GET based REST Web |
| services support only simple types as arguments and it should adhere to |
| the <a class="externalLink" href="http://www.w3.org/TR/2006/CR-wsdl20-adjuncts-20060327/#_operation_iri_style">IRI |
| style</a>.</li> |
| |
| <li>POST based Web services do not need a SOAP Envelope or a SOAP Body. |
| REST Web Services do not have Headers and the payload is sent |
| directly.</li> |
| </ol> |
| |
| |
| <p>Axis2 can be configured as a REST Container and can be used to send and |
| receive RESTful Web service requests and responses. REST Web services can be |
| accessed using HTTP GET and POST.</p> |
| <a name="rest_with_post"></a> |
| |
| |
| <div class="section"> |
| <h2><a name="REST_Web_Services_with_HTTP_POST"></a>REST Web Services with HTTP POST</h2> |
| |
| |
| <p>If REST is enabled, the Axis2 server will act as both a REST endpoint and |
| a SOAP endpoint. When a message is received, if the content type is text/xml |
| and if the SOAPAction Header is missing, then the message is treated as a |
| RESTful Message, if not it is treated as a usual SOAP Message.</p> |
| |
| |
| <p>On sending a message, whether the message is RESTful or not, can be |
| decided from the client API.<br /> |
| Set a property in the client API.<br /> |
| </p> |
| |
| <div> |
| <pre>... |
| Options options = new Options(); |
| options.setProperty(Constants.Configuration.ENABLE_REST, Constants.VALUE_TRUE); |
| ...</pre></div> |
| <a name="sample"></a> |
| |
| |
| <div class="section"> |
| <h3><a name="Sample_REST_-_HTTP_POST_Client"></a>Sample REST - HTTP POST Client</h3> |
| |
| |
| <p>There is an example named, userguide.clients.RESTClient.java found in |
| AXIS2_HOME/samples/userguide/src/userguide/clients which demonstrates the |
| usage of the above. It uses the "echo" operation of the |
| <tt>userguide.example1.MyService </tt>of the |
| AXIS2_HOME/samples/userguide/src/userguide/example1.</p> |
| |
| |
| <p>The class source will be as follows:</p> |
| |
| <div> |
| <pre>public class RESTClient { |
| |
| private static String toEpr = "http://localhost:8080/axis2/services/MyService"; |
| |
| public static void main(String[] args) throws AxisFault { |
| |
| Options options = new Options(); |
| options.setTo(new EndpointReference(toEpr)); |
| options.setTransportInProtocol(Constants.TRANSPORT_HTTP); |
| |
| options.setProperty(Constants.Configuration.ENABLE_REST, Constants.VALUE_TRUE); |
| |
| ServiceClient sender = new ServiceClient(); |
| sender.engageModule(Constants.MODULE_ADDRESSING); |
| sender.setOptions(options); |
| OMElement result = sender.sendReceive(getPayload()); |
| |
| try { |
| XMLStreamWriter writer = XMLOutputFactory.newInstance() |
| .createXMLStreamWriter(System.out); |
| result.serialize(writer); |
| writer.flush(); |
| } catch (XMLStreamException e) { |
| e.printStackTrace(); |
| } catch (FactoryConfigurationError e) { |
| e.printStackTrace(); |
| } |
| } |
| |
| private static OMElement getPayload() { |
| OMFactory fac = OMAbstractFactory.getOMFactory(); |
| OMNamespace omNs = fac.createOMNamespace( |
| "http://example1.org/example1", "example1"); |
| OMElement method = fac.createOMElement("echo", omNs); |
| OMElement value = fac.createOMElement("Text", omNs); |
| value.addChild(fac.createOMText(value, "Axis2 Echo String ")); |
| method.addChild(value); |
| |
| return method; |
| } |
| }</pre></div> |
| <a name="rest_with_get"></a> |
| |
| </div> |
| <div class="section"> |
| <h2><a name="Access_a_REST_Web_Service_via_HTTP_GET"></a>Access a REST Web Service via HTTP GET</h2> |
| |
| |
| <p>Axis2 allows users to access Web services that have simple type parameters |
| via HTTP GET. For example, the following URL requests the Version Service via |
| HTTP GET. However, the Web service arriving via GET assumes REST. Other |
| parameters are converted into XML and put into the SOAP body.</p> |
| |
| <div> |
| <pre>http://127.0.0.1:8080/axis2/services/Version/getVersion</pre></div> |
| |
| <p>The result can be shown in the browser as follows:</p> |
| <img src="images/userguide/http-get-ws.jpg" alt="" /> |
| |
| |
| <p>For example, the following request,</p> |
| |
| <div> |
| <pre>http://127.0.0.1:8080/axis2/services/Version/getVersion</pre></div> |
| will be converted into the following SOAP message for processing by |
| Axis2. |
| |
| <div> |
| <pre> |
| <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> |
| <soapenv:Body> |
| <axis2:getVersion xmlns:axis2="http://ws.apache.org/goGetWithREST" /> |
| </soapenv:Body> |
| </soapenv:Envelope> |
| </pre></div> |
| |
| |
| <div class="section"> |
| <h2><a name="Resources"></a>Resources</h2> |
| |
| |
| <p>How I Explained REST to My Wife, By Ryan Tomayko- <a class="externalLink" href="http://naeblis.cx/articles/2004/12/12/rest-to-my-wife">http://naeblis.cx/articles/2004/12/12/rest-to-my-wife</a></p> |
| |
| |
| <p>Building Web Services the REST Way, By Roger L. Costello- <a class="externalLink" href="http://www.xfront.com/REST-Web-Services.html"> |
| http://www.xfront.com/REST-Web-Services.html</a></p> |
| |
| |
| <p>Resource-oriented vs. activity-oriented Web services, By James Snell- <a class="externalLink" href="http://www-128.ibm.com/developerworks/webservices/library/ws-restvsoap/">http://www-128.ibm.com/developerworks/webservices/library/ws-restvsoap/</a></p> |
| |
| </html> |
| </div> |
| </div> |
| </div> |
| <hr/> |
| <footer> |
| <div class="container-fluid"> |
| <div class="row-fluid"> |
| <p>Copyright ©2004–2018 |
| <a href="https://www.apache.org/">The Apache Software Foundation</a>. |
| All rights reserved.</p> |
| </div> |
| </div> |
| </footer> |
| </body> |
| </html> |