| <!DOCTYPE html> |
| |
| |
| <!-- |
| | Generated by Apache Maven Doxia Site Renderer 2.0.0 from src/site/xdoc/docs/rest-ws.xml at 2026-05-18 |
| | Rendered using Apache Maven Fluido Skin 2.0.0-M11 |
| --> |
| <html xmlns="http://www.w3.org/1999/xhtml" lang="en"> |
| <head> |
| <meta charset="UTF-8" /> |
| <meta name="viewport" content="width=device-width, initial-scale=1" /> |
| <meta name="generator" content="Apache Maven Doxia Site Renderer 2.0.0" /> |
| <title>RESTful Web Services Support – Apache Axis2</title> |
| <link rel="stylesheet" href="../css/apache-maven-fluido-2.0.0-M11.min.css" /> |
| <link rel="stylesheet" href="../css/site.css" /> |
| <link rel="stylesheet" href="../css/print.css" media="print" /> |
| <script src="../js/apache-maven-fluido-2.0.0-M11.min.js"></script> |
| <meta http-equiv="content-type" content="" /> </head> |
| <body> |
| <div class="container-fluid container-fluid-top"> |
| <header> |
| <div id="banner"> |
| <div class="pull-left"><div id="bannerLeft"><h1><a href="https://www.apache.org/"><img class="class java.lang.Object" src="https://www.apache.org/images/asf_logo_wide.png" /> Apache Axis2</a></h1></div></div> |
| <div class="pull-right"><div id="bannerRight"><h1><a href="https://axis.apache.org/axis2/java/core/"><img class="class java.lang.Object" src="https://axis.apache.org/axis2/java/core/images/axis.jpg" /></a></h1></div></div> |
| <div class="clear"><hr/></div> |
| </div> |
| |
| <div id="breadcrumbs"> |
| <ul class="breadcrumb"> |
| <li id="publishDate">Last Published: 2026-05-17<span class="divider">|</span> |
| </li> |
| <li id="projectVersion">Version: 2.0.1<span class="divider">|</span></li> |
| <li><a href="https://www.apache.org" class="externalLink">Apache</a><span class="divider">/</span></li> |
| <li><a href="../index.html">Axis2/Java</a><span class="divider">/</span></li> |
| <li class="active">RESTful Web Services Support</li> |
| </ul> |
| </div> |
| </header> |
| <div class="row-fluid"> |
| <header id="leftColumn" class="span2"> |
| <nav class="well sidebar-nav"> |
| <ul class="nav nav-list"> |
| <li class="nav-header">Axis2/Java</li> |
| <li><a href="../index.html">Home</a></li> |
| <li><a href="../download.html">Downloads</a></li> |
| <li><a href="javascript:void(0)"><span class="icon-chevron-down"></span>Release Notes</a> |
| <ul class="nav nav-list"> |
| <li><a href="../release-notes/1.6.1.html">1.6.1</a></li> |
| <li><a href="../release-notes/1.6.2.html">1.6.2</a></li> |
| <li><a href="../release-notes/1.6.3.html">1.6.3</a></li> |
| <li><a href="../release-notes/1.6.4.html">1.6.4</a></li> |
| <li><a href="../release-notes/1.7.0.html">1.7.0</a></li> |
| <li><a href="../release-notes/1.7.1.html">1.7.1</a></li> |
| <li><a href="../release-notes/1.7.2.html">1.7.2</a></li> |
| <li><a href="../release-notes/1.7.3.html">1.7.3</a></li> |
| <li><a href="../release-notes/1.7.4.html">1.7.4</a></li> |
| <li><a href="../release-notes/1.7.5.html">1.7.5</a></li> |
| <li><a href="../release-notes/1.7.6.html">1.7.6</a></li> |
| <li><a href="../release-notes/1.7.7.html">1.7.7</a></li> |
| <li><a href="../release-notes/1.7.8.html">1.7.8</a></li> |
| <li><a href="../release-notes/1.7.9.html">1.7.9</a></li> |
| <li><a href="../release-notes/1.8.0.html">1.8.0</a></li> |
| <li><a href="../release-notes/1.8.1.html">1.8.1</a></li> |
| <li><a href="../release-notes/1.8.2.html">1.8.2</a></li> |
| <li><a href="../release-notes/2.0.0.html">2.0.0</a></li> |
| <li><a href="../release-notes/2.0.1.html">2.0.1</a></li> |
| </ul></li> |
| <li><a href="../modules/index.html">Modules</a></li> |
| <li><a href="../tools/index.html">Tools</a></li> |
| <li class="nav-header">Documentation</li> |
| <li><a href="../docs/toc.html">Table of Contents</a></li> |
| <li><a href="../docs/installationguide.html">Installation Guide</a></li> |
| <li><a href="../docs/quickstartguide.html">QuickStart Guide</a></li> |
| <li><a href="../docs/userguide.html">User Guide</a></li> |
| <li><a href="../docs/jaxws-guide.html">JAXWS Guide</a></li> |
| <li><a href="../docs/pojoguide.html">POJO Guide</a></li> |
| <li><a href="../docs/spring.html">Spring Guide</a></li> |
| <li><a href="../docs/webadminguide.html">Web Administrator's Guide</a></li> |
| <li><a href="../docs/migration.html">Migration Guide (from Axis1)</a></li> |
| <li class="nav-header">Resources</li> |
| <li><a href="../faq.html">FAQ</a></li> |
| <li><a href="https://github.com/apache/axis-axis2-java-core" class="externalLink">Source Code</a></li> |
| <li class="nav-header">Get Involved</li> |
| <li><a href="../overview.html">Overview</a></li> |
| <li><a href="../mail-lists.html">Mailing Lists</a></li> |
| <li><a href="../release-process.html">Release Process</a></li> |
| <li><a href="../guidelines.html">Developer Guidelines</a></li> |
| <li><a href="../siteHowTo.html">Build the Site</a></li> |
| <li class="nav-header">Project Information</li> |
| <li><a href="https://github.com/apache/axis-axis2-java-core/graphs/contributors" class="externalLink">Contributors</a></li> |
| <li><a href="https://issues.apache.org/jira/projects/AXIS2/issues" class="externalLink">Issues</a></li> |
| <li class="nav-header">Apache</li> |
| <li><a href="https://www.apache.org/licenses/LICENSE-2.0.html" class="externalLink">License</a></li> |
| <li><a href="https://www.apache.org/foundation/sponsorship.html" class="externalLink">Sponsorship</a></li> |
| <li><a href="https://www.apache.org/foundation/thanks.html" class="externalLink">Thanks</a></li> |
| <li><a href="https://www.apache.org/security/" class="externalLink">Security</a></li> |
| </ul> |
| </nav> |
| <div class="well sidebar-nav"> |
| <div id="poweredBy"> |
| <div class="clear"></div> |
| <div class="clear"></div> |
| <a href="https://maven.apache.org/" class="builtBy" target="_blank"><img class="builtBy" alt="Built by Maven" src="../images/logos/maven-feather.png" /></a> |
| </div> |
| </div> |
| </header> |
| <main id="bodyColumn" class="span10"> |
| <html> |
| |
| <section><a id="RESTful_Web_Services_Support"></a> |
| <h1>RESTful Web Services Support</h1> |
| |
| |
| <p>This document presents an introduction on REST and REST with HTTP POST and |
| GET.</p> |
| |
| <section><a id="Content"></a> |
| <h2>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 id="intro"></a> |
| |
| </section><section><a id="Introduction"></a> |
| <h2>Introduction</h2> |
| |
| |
| <p>REST (Representational State Transfer) Web services are a reduced |
| subset of the usual Web service stack. Axis2 supports exposing services |
| over HTTP GET and POST without requiring a SOAP envelope.</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.</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 id="rest_with_post"></a> |
| |
| </section><section><a id="REST_Web_Services_with_HTTP_POST"></a> |
| <h2>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> |
| |
| <pre>... |
| Options options = new Options(); |
| options.setProperty(Constants.Configuration.ENABLE_REST, Constants.VALUE_TRUE); |
| ...</pre> |
| <a id="sample"></a> |
| |
| <section><a id="Sample_REST_-_HTTP_POST_Client"></a> |
| <h3>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 |
| <code>userguide.example1.MyService </code>of the |
| AXIS2_HOME/samples/userguide/src/userguide/example1.</p> |
| |
| |
| <p>The class source will be as follows:</p> |
| |
| <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> |
| <a id="rest_with_get"></a> |
| |
| </section></section><section><a id="Access_a_REST_Web_Service_via_HTTP_GET"></a> |
| <h2>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> |
| |
| <pre>http://127.0.0.1:8080/axis2/services/Version/getVersion</pre> |
| |
| <p>The result can be shown in the browser as follows:</p> |
| <img src="images/userguide/http-get-ws.jpg" /> |
| |
| |
| <p>For example, the following request,</p> |
| |
| <pre>http://127.0.0.1:8080/axis2/services/Version/getVersion</pre> |
| will be converted into the following SOAP message for processing by |
| Axis2. |
| |
| <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> |
| |
| </section><section><a id="Resources"></a> |
| <h2>Resources</h2> |
| |
| |
| <p>How I Explained REST to My Wife, By Ryan Tomayko- <a href="http://naeblis.cx/articles/2004/12/12/rest-to-my-wife" class="externalLink">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 href="http://www.xfront.com/REST-Web-Services.html" class="externalLink"> |
| http://www.xfront.com/REST-Web-Services.html</a></p> |
| |
| |
| <p>Resource-oriented vs. activity-oriented Web services, By James Snell- <s><a href="http://www-128.ibm.com/developerworks/webservices/library/ws-restvsoap/" class="externalLink">http://www-128.ibm.com/developerworks/webservices/library/ws-restvsoap/</a></s> <em>(Old IBM DeveloperWorks URL format may be inaccessible)</em></p> |
| </section> |
| </html> </main> |
| </div> |
| </div> |
| <hr/> |
| <footer> |
| <div class="container-fluid"> |
| <div class="row-fluid"> |
| <p>© 2004–2026 |
| <a href="https://www.apache.org/">The Apache Software Foundation</a> |
| </p> |
| </div> |
| </div> |
| </footer> |
| </body> |
| </html> |