| <!DOCTYPE html> |
| <!-- |
| | Generated by Apache Maven Doxia at 2016-01-18 |
| | Rendered using Apache Maven Fluido Skin 1.4 |
| --> |
| <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="20160118" /> |
| <meta http-equiv="Content-Language" content="en" /> |
| <title>Apache Axis2 – Introducing Axis2</title> |
| <link rel="stylesheet" href="../css/apache-maven-fluido-1.4.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.4.min.js"></script> |
| |
| |
| <meta name="generator" content="HTML Tidy for Windows (vers 14 June 2007), see www.w3.org" /><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: 2016-01-18 |
| <span class="divider">|</span> |
| </li> |
| <li id="projectVersion">Version: 1.7.0 |
| <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 ">Introducing Axis2</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> |
| </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" > |
| |
| <!-- ~ Licensed to the Apache Software Foundation (ASF) under one |
| ~ or more contributor license agreements. See the NOTICE file |
| ~ distributed with this work for additional information |
| ~ regarding copyright ownership. The ASF licenses this file |
| ~ to you under the Apache License, Version 2.0 (the |
| ~ "License"); you may not use this file except in compliance |
| ~ with the License. You may obtain a copy of the License at |
| ~ |
| ~ http://www.apache.org/licenses/LICENSE-2.0 |
| ~ |
| ~ Unless required by applicable law or agreed to in writing, |
| ~ software distributed under the License is distributed on an |
| ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| ~ KIND, either express or implied. See the License for the |
| ~ specific language governing permissions and limitations |
| ~ under the License. --><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> |
| |
| <a name="buildservices" id="buildservices"></a> |
| |
| <h1>Apache Axis2 User's Guide -Building Services</h1> |
| |
| <p>Now that you know how to use Axis2 to generate clients from |
| WSDL, this section digs a little deeper showing you how to create |
| services, and also how to create services and clients "from |
| scratch", so to speak.</p> |
| |
| <ul> |
| |
| <li><a href="userguide.html#intro">Introducing Axis2</a><br /> |
| |
| <ul> |
| |
| <li><a href="userguide.html#whatis">What is Axis2?</a></li> |
| |
| <li><a href="userguide.html#underhood">What's Under the |
| Hood?</a></li> |
| |
| <li><a href="userguide.html#handlessoap">How Axis2 Handles SOAP |
| Messages</a></li> |
| |
| <li><a href="userguide.html#distributions">Axis2 |
| Distributions</a></li> |
| |
| <li><a href="userguide.html#sbd">The Axis2 Standard Binary |
| Distribution</a></li> |
| |
| <li><a href="userguide.html#hierarchy">Axis2.war Directory |
| Hierarchy</a></li> |
| |
| <li><a href="userguide.html#docs">Axis2 Documents |
| Distribution</a></li> |
| |
| <li><a href="userguide.html#clients">Axis2 and Clients</a></li> |
| </ul> |
| </li> |
| |
| <li><a href="userguide-installingtesting.html#installingtesting">Installing and |
| Testing Client Code</a></li> |
| |
| <li><a href="userguide-introtoservices.html#introservices">Introduction to |
| Services</a><br /> |
| |
| <ul> |
| |
| <li><a href="userguide-introtoservices.html#messageexchange">Message Exchange |
| Patterns</a></li> |
| </ul> |
| </li> |
| |
| <li><a href="userguide-creatingclients.html#createclients">Creating |
| Clients</a><br /> |
| |
| <ul> |
| |
| <li><a href="userguide-creatingclients.html#choosingclient">Choosing a Client |
| Generation Method</a></li> |
| |
| <li><a href="userguide-creatingclients.html#generating">Generating |
| Clients</a></li> |
| |
| <li><a href="userguide-creatingclients.html#adb">Axis Data Binding |
| (ADB)</a></li> |
| </ul> |
| </li> |
| |
| <li><a href="userguide-buildingservices.html#buildservices"><b>Building |
| Services</b></a><br /> |
| |
| <ul> |
| |
| <li><a href="userguide-buildingservices.html#getcomfortable"><b>Getting |
| Comfortable with Available Options</b></a></li> |
| |
| <li><a href="userguide-buildingservices.html#createscratch"><b>Creating a |
| Service from Scratch</b></a></li> |
| |
| <li><a href="userguide-buildingservices.html#deploypojo"><b>Deploying |
| Plain Old Java Objects</b></a></li> |
| |
| <li><a href="userguide-buildingservices.html#deployrun"><b>Deploying and |
| Running an Axis2 Service Created from WSDL</b></a></li> |
| </ul> |
| </li> |
| |
| <li><a href="userguide-samples.html">Samples</a></li> |
| |
| <li><a href="userguide-forfurtherstudy.html">For Further |
| Study</a></li> |
| </ul> |
| |
| <p><a name="getcomfortable" id="getcomfortable"></a></p> |
| |
| <div class="section"> |
| <h2><a name="Getting_Comfortable_with_the_Available_Options"></a>Getting Comfortable with the Available Options</h2> |
| |
| <p>Axis2 provides a number of ways to create a service, such |
| as:</p> |
| |
| <ul> |
| |
| <li>Create a service and build it from scratch. In this case, you |
| build your service class to specifically access AXIOM OMElement |
| objects, then create the services.xml file and package it for |
| deployment.</li> |
| |
| <li>Deploy Plain Old Java Objects (POJOs) as a service.</li> |
| |
| <li>Generate the service from WSDL. Just as you can generate |
| clients with WSDL, you can also generate the skeleton of a |
| service.</li> |
| </ul> |
| |
| <p>Let's look at these three options.</p> |
| <a name="createscratch" id="createscratch"></a> |
| |
| <div class="section"> |
| <h2><a name="Creating_a_Service_from_Scratch"></a>Creating a Service from Scratch</h2> |
| |
| <p>Creating a service from scratch is not the most convenient way |
| to do it, but it does give you the most control. The process |
| involves several steps.</p> |
| |
| <p><b>The short story:</b></p> |
| |
| <ol style="list-style-type: decimal"> |
| |
| <li>Create the service class with each operation that is |
| represented by a method that takes an org.apache.axiom.om.OMElement |
| object as its argument. (An OMElement is how the AXIs2 Object Model |
| (AXIOM) represents an XML element.)</li> |
| |
| <li>Create the service descriptor, services.xml, which defines the |
| class to be used by the service and the appropriate message |
| receivers.</li> |
| |
| <li>Create the .aar file, with the classes in their proper |
| locations based on the package and the services.xml file in the |
| META-INF directory.</li> |
| |
| <li>Deploy the .aar file by using the <a href="webadminguide.html">Web Administration application</a> or by |
| copying it to the Axis2 services directory.</li> |
| </ol> |
| |
| <p><b>The long story:</b></p> |
| |
| <p>Start by creating the service class, a plain Java class that |
| uses classes from the Axis2 libraries (see Code Listing 8).</p> |
| |
| <div class="section"> |
| <h3><a name="Code_Listing_8-Creating_the_Service_Class"></a>Code Listing 8-Creating the Service Class</h3> |
| |
| <div> |
| <pre> |
| package org.apache.axis2.axis2userguide; |
| |
| import javax.xml.stream.XMLStreamException; |
| import org.apache.axiom.om.OMAbstractFactory; |
| import org.apache.axiom.om.OMElement; |
| import org.apache.axiom.om.OMFactory; |
| import org.apache.axiom.om.OMNamespace; |
| |
| public class SampleService { |
| |
| public OMElement sayHello(OMElement element) |
| throws XMLStreamException { |
| element.build(); |
| element.detach(); |
| |
| String rootName = element.getLocalName(); |
| System.out.println("Reading "+rootName+" element"); |
| |
| OMElement childElement = element.getFirstElement(); |
| String personToGreet = childElement.getText(); |
| |
| OMFactory fac = OMAbstractFactory.getOMFactory(); |
| OMNamespace omNs = fac.createOMNamespace( |
| "http://example1.org/example1", "example1"); |
| OMElement method = fac.createOMElement("sayHelloResponse", |
| omNs); |
| OMElement value = fac.createOMElement("greeting", omNs); |
| value.addChild(fac.createOMText(value, "Hello, |
| "+personToGreet)); |
| method.addChild(value); |
| |
| return method; |
| } |
| |
| private void ping(){ |
| } |
| |
| } |
| </pre></div> |
| |
| <p>Make sure to include Axis2 libraries in your class path when |
| compiling the source.</p> |
| |
| <p>Axis2 uses AXIOM, or the AXIs Object Model, a DOM (Document |
| Object Model) -like structure that is based on the StAX API ( |
| Streaming API for XML). Methods that act as services must take an |
| OMElement as their argument, which represents the payload of the |
| incoming SOAP message. (An OMElement is just AXIOM's way of |
| representing an XML element, like a DOM Element object.) In this |
| case, you're extracting the contents of the first child of the |
| payload element, adding text to it, and using it as content for the |
| return OMElement. Unless this is an "in only" service, these |
| methods must return an OMElement, because that becomes the payload |
| of the return SOAP message.</p> |
| |
| <p>To turn this class into a service, create the service |
| description file, services.xml, as in Code Listing 9.</p> |
| </div> |
| <div class="section"> |
| <h3><a name="Code_Listing_9_-_Create_the_Service_Description"></a>Code Listing 9 - Create the Service Description</h3> |
| |
| <div> |
| <pre> |
| <service name="UserGuideSampleService"> |
| <description> |
| This is a sample service created in the Axis2 User's Guide |
| </description> |
| |
| <parameter name="ServiceClass" |
| >org.apache.axis2.axis2userguide.SampleService |
| </parameter> |
| |
| <operation name="sayHello"> |
| <messageReceiver |
| class="org.apache.axis2.receivers.RawXMLINOutMessageReceiver"/> |
| </operation> |
| <operation name="ping"> |
| <messageReceiver |
| class="org.apache.axis2.receivers.RawXMLINOnlyMessageReceiver"/> |
| </operation> |
| </service> |
| </pre></div> |
| |
| <p>This document defines the service, called by the <a href="webadminguide.html">Web Administration Application</a>, and the |
| class used to serve requests. For each operation, it defines the |
| appropriate message receiver class.</p> |
| |
| <p>Create a new directory, META-INF, in the main directory for the |
| class. (In this case, that's the same directory that contains the |
| org directory) and place the services.xml file in it.</p> |
| |
| <p>Create the .aar file by typing: jar cvf SampleService.aar |
| ./*</p> |
| |
| <p>Deploy the SampleService.aar file by using the <a href="webadminguide.html">Web Administration application</a> or by |
| copying it to the Axis2 services directory.</p> |
| |
| <p>Now you can create a client class that accesses the service |
| directly (see Code Listing 10).</p> |
| </div> |
| <div class="section"> |
| <h3><a name="Code_Listing_10_-_Create_a_Client_Class_that_Accesses_theService_Directly"></a>Code Listing 10 - Create a Client Class that Accesses the |
| Service Directly</h3> |
| |
| <div> |
| <pre> |
| package org.apache.axis2.axis2userguide; |
| |
| import javax.xml.stream.XMLStreamException; |
| import org.apache.axiom.om.OMAbstractFactory; |
| import org.apache.axiom.om.OMElement; |
| import org.apache.axiom.om.OMFactory; |
| import org.apache.axiom.om.OMNamespace; |
| import org.apache.axis2.addressing.EndpointReference; |
| import org.apache.axis2.client.Options; |
| import org.apache.axis2.Constants; |
| import org.apache.axis2.client.ServiceClient; |
| |
| public class SampleClient { |
| |
| private static EndpointReference targetEPR = |
| new EndpointReference( |
| "http://localhost:8080/axis2/services/UserGuideSampleService"); |
| |
| public static OMElement greetUserPayload(String personToGreet) { |
| OMFactory fac = OMAbstractFactory.getOMFactory(); |
| OMNamespace omNs = fac.createOMNamespace( |
| "http://example1.org/example1", "example1"); |
| OMElement method = fac.createOMElement("sayHello", omNs); |
| OMElement value = fac.createOMElement("personToGreet", |
| omNs); |
| value.addChild(fac.createOMText(value, personToGreet)); |
| method.addChild(value); |
| return method; |
| } |
| |
| public static void main(String[] args) { |
| try { |
| OMElement payload = |
| SampleClient.greetUserPayload("John"); |
| Options options = new Options(); |
| options.setTo(targetEPR); |
| |
| options.setTransportInProtocol(Constants.TRANSPORT_HTTP); |
| |
| ServiceClient sender = new ServiceClient(); |
| sender.setOptions(options); |
| OMElement result = sender.sendReceive(payload); |
| |
| String response = result.getFirstElement().getText(); |
| System.out.println(response); |
| |
| } catch (Exception e) { //(XMLStreamException e) { |
| System.out.println(e.toString()); |
| } |
| } |
| |
| } |
| </pre></div> |
| |
| <p>This class uses the same technique of sending and receiving |
| OMElements, but it's also important to note the use of the Options |
| class. This class enables you to determine properties such as the |
| transport used for the return message (the transport used for the |
| outgoing message can be inferred from the URL of the destination) |
| and the SOAP version to use. In addition to providing setter and |
| getter methods of specific properties that affect how the client |
| interacts with the service, the Options class enables you to create |
| inheritance relationships between Options objects. So if a property |
| is not found in the current Options object used, the client can |
| check the parent Options object of the current Options object.</p> |
| |
| <p>Compile and run the above SampleClient.java. Make sure to have |
| all axis2 libraries in your class path. If all has gone well, |
| 'Hello, John' will be shown as the output in the console.</p> |
| <a name="deploypojo" id="deploypojo"></a> |
| </div> |
| <div class="section"> |
| <h2><a name="Deploying_Plain_Old_Java_Objects_POJOs"></a>Deploying Plain Old Java Objects (POJOs)</h2> |
| |
| <p>One very easy way to create a Web service is simply to deploy |
| the Java objects that represent the service. Start with the class, |
| shown in Code Listing 11.</p> |
| |
| <div class="section"> |
| <h3><a name="Code_Listing_11_-_Creating_the_Class_SampleService"></a><b>Code Listing 11 - Creating the Class SampleService</b></h3> |
| |
| <div> |
| <pre> |
| package org.apache.axis2.axis2userguide; |
| |
| public class SampleService { |
| |
| public void doInOnly(){ |
| return; |
| } |
| |
| public String noParameters(){ |
| return "Hello"; |
| } |
| |
| public String twoWayOneParameterEcho(String toEcho){ |
| return toEcho; |
| } |
| |
| public boolean multipleParametersAdd(float price, int itemId, |
| String description, String itemName){ |
| //Code to handle the logic |
| return true; |
| } |
| |
| } |
| </pre></div> |
| |
| <p>Next, you'll need to tell Axis2 what class corresponds with what |
| Web service calls. Do this by creating a file called services.xml |
| and adding the following shown in Code Listing 12.</p> |
| </div> |
| <div class="section"> |
| <h3><a name="Code_Listing_12_-_Creating_services.xml"></a><b>Code Listing 12 - Creating services.xml</b></h3> |
| |
| <div> |
| <pre> |
| <service name="SampleService" scope="application"> |
| <description> |
| Sample Service |
| </description> |
| <messageReceivers> |
| <messageReceiver |
| mep="http://www.w3.org/ns/wsdl/in-only" |
| class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver"/> |
| <messageReceiver |
| mep="http://www.w3.org/ns/wsdl/in-out" |
| class="org.apache.axis2.rpc.receivers.RPCMessageReceiver"/> |
| </messageReceivers> |
| <parameter name="ServiceClass"> |
| org.apache.axis2.axis2userguide.SampleService |
| </parameter> |
| </service> |
| </pre></div> |
| |
| <p>This file makes the InOnly and InOut MEPs available to the |
| service and tells Axis2 which class to call; operations must match |
| method names. In other words, Axis2 automatically sends a call to |
| the multipleParametersAdd operation to the |
| org.apache.axis2.axis2userguide.SampleService.multipleParametersAdd() |
| method.</p> |
| |
| <p>Now it's time to create the distribution. Arrange your files in |
| the following directory structure (see Code Listing 13).</p> |
| </div> |
| <div class="section"> |
| <h3><a name="Code_Listing_13-_Create_the_Directory_Structure_for_theDistribution"></a><b>Code Listing 13- Create the Directory Structure for the |
| Distribution</b></h3> |
| |
| <div> |
| <pre> |
| - SampleService |
| - META-INF |
| - services.xml |
| - org |
| - apache |
| - axis2 |
| - axis2userguide |
| - SampleService.class |
| </pre></div> |
| |
| <p>Finally, deploy the service by copying the SampleService |
| directory to the webapps/axis2/WEB-INF/services directory on the |
| servlet engine. You can check to make sure that it's been properly |
| deployed by checking http://<host>:<port>/axis2/services/listServices.</p> |
| <a name="deployrun" id="deployrun"></a> |
| </div> |
| <div class="section"> |
| <h2><a name="Deploying_and_Running_an_Axis2_Service_Created_from_WSDL"></a>Deploying and Running an Axis2 Service Created from WSDL</h2> |
| |
| <p>If you have a WSDL file, you can easily create and deploy a |
| service based on that description. For example, to create a service |
| based on the same WSDL file used in the <a href="userguide-creatingclients.html">clients section</a> of this |
| document, you will follow the steps below.</p> |
| |
| <p><b>The short story:</b></p> |
| |
| <ol style="list-style-type: decimal"> |
| |
| <li><a href="../download.cgi"> |
| Download</a> the Axis2 standard distribution, if you have not done |
| so already.</li> |
| |
| <li>Generate the skeleton using the WSDL2Java utility, as in:<br /> |
| |
| <div> |
| <pre> |
| java org.apache.axis2.wsdl.WSDL2Java -uri file:///C:/apps/axis2/samples/zSample/Axis2UserGuide.wsdl -p org.apache.axis2.axis2userguide -d adb -s -wv 1.1 -ss -sd -ssi |
| </pre></div></li> |
| |
| <li>Open the *Skeleton.java file and add the functionality of your |
| service to the generated methods.</li> |
| |
| <li>Build a service using Ant by typing ant jar.server</li> |
| |
| <li>Deploy the service by copying the build/lib/*.aar file to |
| <J2EE_HOME>/webapps/axis2/WEB-INF/services</li> |
| |
| <li>Check |
| http://<server>:<port>/axis2/services/listServices to |
| make sure the service has been properly deployed.</li> |
| </ol> |
| |
| <p><b>The long story:</b></p> |
| |
| <p>As with generating clients, you will need the <a href="../download.cgi"> |
| Axis2 Standard Distribution</a>, because the <a href="../download.cgi"> |
| Axis2 WAR Distribution</a> does not include the WSDL2Java utility. |
| Once you've got it downloaded and unpacked, make sure that you set |
| the AXIS2_HOME variable to point to the location in which you've |
| unpacked it.</p> |
| |
| <p>Now you are ready to generate the actual service. To keep things |
| neat, create a new directory and change to it. The WSDL file is the |
| same one referenced in <a href="userguide-creatingclients.html#generating.xhtml">Generating Clients</a> |
| and includes four operations: NoParameters, TwoWayOneParameterEcho, |
| MultipleParametersAddItem, and DoInOnly. To generate the service, |
| use the WSDL2Java utility, as in Code Listing 14.</p> |
| |
| <div class="section"> |
| <h3><a name="Code_Listing_14_-_Using_the_WSDL2Java_Utility_to_Generate_theService"></a>Code Listing 14 - Using the WSDL2Java Utility to Generate the |
| Service</h3> |
| |
| <p><b>Code Listing 14.1:</b></p> |
| |
| <div> |
| <pre> |
| java org.apache.axis2.wsdl.WSDL2Java -uri |
| file:///C:/apps/axis2/samples/zSample/Axis2UserGuide.wsdl -p |
| org.apache.axis2.axis2userguide -d adb -s -wv 1.7.0 -ss -sd |
| </pre></div> |
| |
| <p>Note: Make sure all the .jar files in the Axis2 lib directory is |
| set to the CLASSPATH before you run the above code.</p> |
| |
| <p>This statement tells the utility you want to create a service |
| out of the operations in the file <a href="userguide-codelisting5.html">Axis2UserGuide.wsdl</a>, and that the |
| Java classes generated should be in the |
| org.apache.axis2.axis2userguide package (-p). (You can view the |
| appropriate directories created.) It also indicates that you want |
| to use the Axis2 DataBinding Framework, or ADB (-d), to generate |
| only synchronous or blocking code (-s), and to generate server-side |
| code (-ss) as opposed to a client, including the services.xml |
| service descriptor file (-sd). It also specifies version |
| 1.7.0 for the WSDL file (-wv)<b>.</b></p> |
| |
| <p><b>Code Listing 14.2:</b></p> |
| |
| <p>You can also use the following script files to achieve the same. |
| In this case you do not have the set the CLASSPATH manually.</p> |
| |
| <p>For Linux:</p> |
| |
| <div> |
| <pre> |
| $AXIS2_HOME/bin/wsdl2java.sh -uri file:///C:/apps/axis2/samples/zSample/Axis2UserGuide.wsdl |
| -p org.apache.axis2.axis2userguide -o target_directory_name -d adb -s -wv 1.7.0 -ss -sd |
| </pre></div> |
| |
| <p>For MS Windows:</p> |
| |
| <div> |
| <pre> |
| %AXIS2_HOME%\bin\wsdl2java.bat -uri file:\\\C:\apps\axis2\samples\zSample\Axis2UserGuide.wsdl |
| -p org.apache.axis2.axis2userguide -o target_directory_name -d adb -s -wv 1.7.0 -ss -sd |
| </pre></div> |
| |
| <p>In both instances, at this point, you should see four new items |
| in your chosen directory: the build.xml file, which includes |
| instructions for Ant, the src directory, which includes all the |
| generated classes and stubs, the resources directory, which |
| includes a regenerated version of the WSDL, and the services.xml |
| file, which ultimately controls the service's behavior.</p> |
| |
| <p>You can compile the service at this point, but it doesn't |
| actually do anything yet. You can solve that problem by opening the |
| src\org\apache\axis2\axis2userguide\Axis2UserGuideServiceSkeleton.java |
| file and either editing the code in bold -- make sure you manage |
| parameter numbers -- or replacing all the code with the following |
| in Code Listing 15.</p> |
| </div> |
| <div class="section"> |
| <h3><a name="Code_Listing_15_-_Compiling_the_Service"></a>Code Listing 15 - Compiling the Service</h3> |
| |
| <div> |
| <pre> |
| /** |
| * Axis2UserGuideServiceSkeleton.java |
| * |
| * This file was auto-generated from WSDL |
| * by the Apache Axis2 version: SNAPSHOT Oct 15, 2006 (11:23:18 |
| GMT+00:00) |
| */ |
| package org.apache.axis2.axis2userguide; |
| /** |
| * Axis2UserGuideServiceSkeleton java skeleton for the axisService |
| */ |
| public class Axis2UserGuideServiceSkeleton { |
| |
| |
| /** |
| * Auto generated method signature |
| |
| * @param param7 |
| |
| */ |
| public org.apache.axis2.axis2userguide.NoParametersResponse |
| NoParameters |
| (org.apache.axis2.axis2userguide.NoParametersRequest param7) |
| |
| { |
| <b>System.out.println(param7); |
| |
| NoParametersResponse res = |
| new NoParametersResponse(); |
| |
| return res;</b> |
| } |
| |
| |
| /** |
| * Auto generated method signature |
| |
| * @param param9 |
| |
| */ |
| public |
| org.apache.axis2.axis2userguide.TwoWayOneParameterEchoResponse |
| TwoWayOneParameterEcho |
| ( |
| org.apache.axis2.axis2userguide.TwoWayOneParameterEchoRequest |
| param9 |
| ) |
| |
| { |
| <b>System.out.println(param9.getEchoString()); |
| |
| TwoWayOneParameterEchoResponse res = |
| new TwoWayOneParameterEchoResponse(); |
| |
| res.setEchoString(param9.getEchoString()); |
| |
| return res;</b> |
| } |
| |
| |
| /** |
| * Auto generated method signature |
| |
| * @param param11 |
| |
| */ |
| public void DoInOnly |
| ( |
| org.apache.axis2.axis2userguide.DoInOnlyRequest param11 |
| ) |
| |
| { |
| <b>System.out.println(param11.getMessageString());</b> |
| } |
| |
| |
| /** |
| * Auto generated method signature |
| |
| * @param param12 |
| |
| */ |
| public |
| org.apache.axis2.axis2userguide.MultipleParametersAddItemResponse |
| MultipleParametersAddItem |
| ( |
| |
| org.apache.axis2.axis2userguide.MultipleParametersAddItemRequest |
| param12 |
| ) |
| |
| { |
| <b>System.out.println(param12.getPrice()); |
| System.out.println(param12.getItemId()); |
| System.out.println(param12.getDescription()); |
| System.out.println(param12.getItemName()); |
| |
| MultipleParametersAddItemResponse res = |
| new MultipleParametersAddItemResponse(); |
| |
| res.setSuccessfulAdd(true); |
| res.setItemId(param12.getItemId()); |
| |
| return res;</b> |
| } |
| |
| } |
| </pre></div> |
| |
| <p>As with generating clients, all these classes, such as |
| MultipleParametersAddItemRequest and |
| TwoWayOneParameterEchoResponse, are generated by the utility, and |
| can be found in the same directory as the skeleton file. They |
| include methods such as setSuccessfulAdd(), which sets the value of |
| the content of an element in the response, and getItemName(), which |
| retrieves the content of elements in the request.</p> |
| |
| <p>Save the file and compile it by typing: ant jar.server</p> |
| |
| <p>If all goes well, you should see the BUILD SUCCESSFUL message in |
| your window, and the Axis2UserGuideService.aar file in the newly |
| created build/lib directory.</p> |
| |
| <p><img src="images/fig05.jpg" alt="The BUILD SUCCESSFUL message in your window" /></p> |
| |
| <p>Now you need to deploy the service to the server. To do that, |
| copy the Axis2UserGuideService.aar file to the WEB-INF/services |
| directory of the application server. (You also have the option to |
| use the administration tools. See the <a href="webadminguide.html">Web Administrator's Guide</a> for more |
| information.)</p> |
| |
| <p>To verify that the service has been properly deployed, check the |
| list of services at http://<host>:<port>/axis2/services/listServices.</p> |
| |
| <p><img src="images/fig06.jpg" alt="Checking the list of services" /></p> |
| |
| <p>Now you should be able to access the service using any of the |
| clients built in the <a href="userguide-creatingclients.html#generating">Generating Clients</a> |
| document.</p> |
| |
| <p><b>See Next Section</b>- <a href="userguide-samples.html">Samples</a></p> |
| </div> |
| </html> |
| </div> |
| </div> |
| </div> |
| |
| <hr/> |
| |
| <footer> |
| <div class="container-fluid"> |
| <div class="row-fluid"> |
| <p >Copyright © 2004–2016 |
| <a href="http://www.apache.org/">The Apache Software Foundation</a>. |
| All rights reserved. |
| |
| </p> |
| </div> |
| |
| |
| </div> |
| </footer> |
| </body> |
| </html> |