geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Geronimo v2.2 > Developing a simple Calculator Web service
Date Tue, 18 Aug 2009 01:57:00 GMT
<html>
<head>
    <base href="http://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/1519/1/1/_/styles/combined.css?spaceKey=GMOxDOC22&amp;forWysiwyg=true"
type="text/css">
    </head>
<body style="background-color: white" bgcolor="white">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
     <h2><a href="http://cwiki.apache.org/confluence/display/GMOxDOC22/Developing+a+simple+Calculator+Web+service">Developing
a simple Calculator Web service</a></h2>
     <h4>Page <b>edited</b> by             <a href="http://cwiki.apache.org/confluence/display/~sophia">Ying
Tang</a>
    </h4>
     
          <br/>
     <div class="notificationGreySide">
         <style type='text/css'>/*<![CDATA[*/
table.ScrollbarTable  {border: none;padding: 3px;width: 100%;padding: 3px;margin: 0px;background-color:
#f0f0f0}
table.ScrollbarTable td.ScrollbarPrevIcon {text-align: center;width: 16px;border: none;}
table.ScrollbarTable td.ScrollbarPrevName {text-align: left;border: none;}
table.ScrollbarTable td.ScrollbarParent {text-align: center;border: none;}
table.ScrollbarTable td.ScrollbarNextName {text-align: right;border: none;}
table.ScrollbarTable td.ScrollbarNextIcon {text-align: center;width: 16px;border: none;}

/*]]>*/</style><div class="Scrollbar"><table class='ScrollbarTable'><tr><td
class='ScrollbarPrevIcon'><a href="/confluence/display/GMOxDOC22/Developing+a+JAX-WS+POJO+Web+Service"><img
border='0' align='middle' src='/confluence/images/icons/back_16.gif' width='16' height='16'></a></td><td
width='33%' class='ScrollbarPrevName'><a href="/confluence/display/GMOxDOC22/Developing+a+JAX-WS+POJO+Web+Service">Developing
a JAX-WS POJO Web Service</a>&nbsp;</td><td width='33%' class='ScrollbarParent'><sup><a
href="/confluence/display/GMOxDOC22/Developing+Web+services"><img border='0' align='middle'
src='/confluence/images/icons/up_16.gif' width='8' height='8'></a></sup><a
href="/confluence/display/GMOxDOC22/Developing+Web+services">Developing Web services</a></td><td
width='33%' class='ScrollbarNextName'>&nbsp;<a href="/confluence/display/GMOxDOC22/Developing+Clients+for+a+JAX-WS+Web+Service">Developing
Clients for a JAX-WS Web Service</a></td><td class='ScrollbarNextIcon'><a
href="/confluence/display/GMOxDOC22/Developing+Clients+for+a+JAX-WS+Web+Service"><img
border='0' align='middle' src='/confluence/images/icons/forwd_16.gif' width='16' height='16'></a></td></tr></table></div>
<p>This tutorial will walk you through building and developing the JAX-WS calculator
that ships with the samples package for Geronimo. After completing this tutorial, you should
be able to understand how to build simple Web services with Apache Geronimo<br/>
using the Eclipse development environment.</p>

<p>To run this tutorial, as a minimum you will be required to have installed the following
prerequisite software.</p>

<ol>
	<li>Sun JDK 6.0+ (J2SE 1.6)</li>
	<li>Eclipse IDE for Java EE Developers, which is platform specific</li>
	<li>Apache Geronimo Eclipse Plugin 2.2.x</li>
	<li>Apache Geronimo Server 2.2.x
<div class='panelMacro'><table class='noteMacro'><colgroup><col width='24'><col></colgroup><tr><td
valign='top'><img src="/confluence/images/icons/emoticons/warning.gif" width="16" height="16"
align="absmiddle" alt="" border="0"></td><td><p>Geronimo version 2.2,
Java 1.6 runtime, and Eclipse Ganymede are used is used in this tutorial but other versions
can be used instead (for example, Geronimo version 2.1, Java 1.5, Eclipse Europa)</p></td></tr></table></div></li>
</ol>


<p>Details on installing eclipse are provided in the <a href="/confluence/display/GMOxDOC22/Development+environment"
title="Development environment">Development environment</a> section. This tutorial
is organized in the following sections:</p>
<div>
<ul>
    <li><a href='#DevelopingasimpleCalculatorWebservice-SettingEclipseforapplicationdevelopment'>Setting
Eclipse for application development</a></li>
<ul>
    <li><a href='#DevelopingasimpleCalculatorWebservice-CreateaDynamicWebproject'>Create
a Dynamic Web project</a></li>
    <li><a href='#DevelopingasimpleCalculatorWebservice-Axis2configuration'>Axis2
configuration</a></li>
</ul>
    <li><a href='#DevelopingasimpleCalculatorWebservice-CreatingtheWebservicesimplementationcode'>Creating
the Web services implementation code</a></li>
    <li><a href='#DevelopingasimpleCalculatorWebservice-GeneratingtheWSDLfortheWebservice'>Generating
the WSDL for the Web service</a></li>
    <li><a href='#DevelopingasimpleCalculatorWebservice-DevelopingaWebclientforCalculator'>Developing
a Web client for Calculator</a></li>
    <li><a href='#DevelopingasimpleCalculatorWebservice-SettinguptheDeploymentDescriptorandDeploymentPlan'>Setting
up the Deployment Descriptor and Deployment Plan</a></li>
    <li><a href='#DevelopingasimpleCalculatorWebservice-DeployandRun'>Deploy and
Run</a></li>
</ul></div>

<h1><a name="DevelopingasimpleCalculatorWebservice-SettingEclipseforapplicationdevelopment"></a>Setting
Eclipse for application development</h1>
<h2><a name="DevelopingasimpleCalculatorWebservice-CreateaDynamicWebproject"></a>Create
a Dynamic Web project</h2>
<ol>
	<li>Select <b>File -&gt; New</b>, select <b>Other...</b>.<br/>
<img src="/confluence/download/attachments/93417/CreateProject.png" align="absmiddle" border="0"
/><br clear="all" /> <br clear="all" /> <br clear="all" /></li>
	<li>In the popup window select <b>Web -&gt; Dynamic Web Project</b>
category and click <b>Next</b>.<br/>
<img src="/confluence/download/attachments/93417/CreateProject2.png" align="absmiddle"
border="0" /><br clear="all" /> <br clear="all" /> <br clear="all" /></li>
	<li>Type in <em>jaxws-calculator</em> as the <em>Project name</em>
and select <b>Next</b>.<br/>
<img src="/confluence/download/attachments/93417/CreateProject3.png" align="absmiddle"
border="0" /><br clear="all" /> <br clear="all" /> <br clear="all" /></li>
	<li>Make sure <b>Generate Deployment Descriptor</b> is selected and click
<b>Next</b>.<br/>
<img src="/confluence/download/attachments/93417/CreateProject5.png" align="absmiddle"
border="0" /><br clear="all" /> <br clear="all" /> <br clear="all" /></li>
	<li>Modify the <em>Group Id</em> to: <em>org.apache.geronimo.samples.jws</em>
and <em>Artifact Id</em> to: <em>Calculator</em>.<br/>
<img src="/confluence/download/attachments/93417/CreateProject6.png" align="absmiddle"
border="0" /><br clear="all" /> <br clear="all" /> <br clear="all" />
<div class='panelMacro'><table class='infoMacro'><colgroup><col width='24'><col></colgroup><tr><td
valign='top'><img src="/confluence/images/icons/emoticons/information.gif" width="16"
height="16" align="absmiddle" alt="" border="0"></td><td><b>Useful Information</b><br
/><ul>
	<li>Group ID: A name that identifies the group of a module. The default value is default.</li>
	<li>Artifact ID: A name of the module in a group. The default value is &lt;blank&gt;.</li>
	<li>Version: The version of module. The default value is 1.0</li>
	<li>Type: The type of module, such as system module (car), jar module (jar), web archive
(war), enterprise archive (ear), and so on. The default value is car. A module is stored inside
a repository as repository/groupId/artifactId/version/artifactIdversion.<br/>
type. This repository structure gives a more standardized and easily maintainable<br/>
structure to Geronimo applications.</li>
</ul>
</td></tr></table></div></li>
</ol>



<h2><a name="DevelopingasimpleCalculatorWebservice-Axis2configuration"></a>Axis2
configuration</h2>
<ol>
	<li>Select <b>Window -&gt; Preferences.</b><br/>
<img src="/confluence/download/attachments/93417/CreateProject8.png" align="absmiddle"
border="0" /><br clear="all" /> <br clear="all" /> <br clear="all" /></li>
	<li>Select <b>Web Services</b> -&gt; <b>Axis2 Preferences</b>.</li>
	<li>Under <em>Axis2 Runtime</em> tab, browse to the installation root of
the Axis2 runtime installation to be used in Eclipse. Select <b>OK.</b>
<div class='panelMacro'><table class='infoMacro'><colgroup><col width='24'><col></colgroup><tr><td
valign='top'><img src="/confluence/images/icons/emoticons/information.gif" width="16"
height="16" align="absmiddle" alt="" border="0"></td><td><b>Useful Information</b><br
/><p>A separate Axis2 runtime is required for use by the Eclipse Axis2 project facet.
You can use the pre-integrated Axis2 1.4 binaries (axis-1.4.jar) from the local Geronimo repository
under &lt;Geronimo_home&gt;/repository/axis/axis/1.4</p></td></tr></table></div>
<p><img src="/confluence/download/attachments/93417/axis2-runtime.jpg" align="absmiddle"
border="0" /></p></li>
	<li>Righ click on the <b>jaxws-calculator</b> project and select <b>Properties</b>,
then select <b>Project Facets</b>.</li>
	<li>On the next screen check the box for <b>Axis2 Web Services</b>.<br/>
<img src="/confluence/download/attachments/93417/CreateProject4.png" align="absmiddle"
border="0" /><br clear="all" /> <br clear="all" /> <br clear="all" /></li>
	<li>Select <b>Finish</b>.<br/>
This completes the configuration of Eclipse for application development.</li>
</ol>


<h1><a name="DevelopingasimpleCalculatorWebservice-CreatingtheWebservicesimplementationcode"></a>Creating
the Web services implementation code</h1>
<p>To implement the <b>Calculator</b> Web service we are going to create
a package called <em>org.apache.geronimo.samples.jws</em>. This package will contain
two classes: a <em>Calculator interface</em>, and a <em>CalculatorService</em>
which implements the <b>Calculator interface</b>. Let's go step by step with creating
the package, interface class and implementation class.</p>
<ol>
	<li>Right click on <b>Java Resources: src</b> and select <b>New -&gt;
Package.</b><br/>
<img src="/confluence/download/attachments/93417/createpackage.png" align="absmiddle" border="0"
/><br clear="all" /> <br clear="all" /> <br clear="all" /></li>
	<li>Name the package as <em>org.apache.geronimo.samples.jws</em>. Select
<b>Finish.</b><br/>
<img src="/confluence/download/attachments/93417/createpackage2.png" align="absmiddle"
border="0" /><br clear="all" /> <br clear="all" /> <br clear="all" /></li>
	<li>Right click on the new package and Select <b>New -&gt; Interface</b>.<br/>
<img src="/confluence/download/attachments/93417/createinterface.png" align="absmiddle"
border="0" /><br clear="all" /> <br clear="all" /> <br clear="all" /></li>
	<li>Name the interface as <em>Calculator</em>. Select <b>Finish.</b><br/>
<img src="/confluence/download/attachments/93417/createinterface2.png" align="absmiddle"
border="0" /><br clear="all" /> <br clear="all" /> <br clear="all" /></li>
	<li>Add the following code to the <b>Calculator</b> interface class:
<div class="code panel" style="border-style: solid;border-width: 1px;"><div class="codeHeader
panelHeader" style="border-bottom-width: 1px;border-bottom-style: solid;"><b>Calculator.class</b></div><div
class="codeContent panelContent">
<pre class="code-java">
<span class="code-keyword">package</span> org.apache.geronimo.samples.jws;

<span class="code-keyword">import</span> javax.jws.WebService;
<span class="code-keyword">import</span> javax.jws.WebMethod;
<span class="code-keyword">import</span> javax.jws.WebParam;

@WebService(name=<span class="code-quote">"CalculatorPortType"</span>,
            targetNamespace = <span class="code-quote">"http:<span class="code-comment">//jws.samples.geronimo.apache.org"</span>)
</span><span class="code-keyword">public</span> <span class="code-keyword">interface</span>
Calculator {

    @WebMethod
    <span class="code-keyword">public</span> <span class="code-object">int</span>
add(@WebParam(name = <span class="code-quote">"value1"</span>) <span class="code-object">int</span>
value1,
                   @WebParam(name = <span class="code-quote">"value2"</span>)
<span class="code-object">int</span> value2);

}
</pre>
</div></div></li>
	<li>Right click on the package <b>org.apache.geronimo.samples.jws</b> and
select <b>New -&gt; Class</b>.</li>
	<li>Name the class <em>CalculatorService</em>.</li>
	<li>Accept all the defaults and Select <b>Finish.</b>.<br/>
<img src="/confluence/download/attachments/93417/createClass.png" align="absmiddle" border="0"
/><br clear="all" /> <br clear="all" /> <br clear="all" /></li>
	<li>Add the following code to <b>CalculatorService</b> class:
<div class="code panel" style="border-style: solid;border-width: 1px;"><div class="codeHeader
panelHeader" style="border-bottom-width: 1px;border-bottom-style: solid;"><b>CalculatorService.class</b></div><div
class="codeContent panelContent">
<pre class="code-java">
<span class="code-keyword">package</span> org.apache.geronimo.samples.jws;

<span class="code-keyword">import</span> javax.annotation.Resource;
<span class="code-keyword">import</span> javax.jws.WebService;
<span class="code-keyword">import</span> javax.xml.ws.WebServiceContext;

@WebService(serviceName = <span class="code-quote">"Calculator"</span>,
            portName=<span class="code-quote">"CalculatorPort"</span>,
            endpointInterface = <span class="code-quote">"org.apache.geronimo.samples.jws.Calculator"</span>,
            targetNamespace = <span class="code-quote">"http:<span class="code-comment">//jws.samples.geronimo.apache.org"</span>
</span>            )
<span class="code-keyword">public</span> class CalculatorService <span class="code-keyword">implements</span>
Calculator {

    @Resource
    <span class="code-keyword">private</span> WebServiceContext context;

    <span class="code-keyword">public</span> <span class="code-object">int</span>
add(<span class="code-object">int</span> value1, <span class="code-object">int</span>
value2) {
        <span class="code-object">System</span>.out.println(<span class="code-quote">"User
Principal: "</span> + context.getUserPrincipal());
        <span class="code-keyword">return</span> value1 + value2;
    }
}
</pre>
</div></div></li>
</ol>


<p>Let us try to understand each annotation.</p>
<ul>
	<li><b>@WebService</b>- This annotation can be used with a Java class as
well as with interface. In our case we used it with both interface as well as the POJO. This
annotation declares the POJO as a WebService. @WebService annotation is utilized in generating
the WSDL file.
	<ul>
		<li><b>serviceName</b> is same as the WSDL element service</li>
		<li><b>name</b> is same as the WSDL element &lt;portType name&gt;</li>
		<li><b>endpointInterface</b> suggests the user defined name for the Service
Endpoint Interface (SEI).</li>
		<li><b>portName</b> is the element portName</li>
		<li><b>targetNamespace</b> is the XML namespace of the WSDL and some of
the XML elements generated from the WebService</li>
	</ul>
	</li>
	<li><b>@WebMethod</b>- This annotation is applied to a method to expose
it as a WebService method. In case you have multiple methods you can use this annotation to
selectively expose methods as WebService method. If you donot use this annotation all the
public methods will be exposed as WebService.</li>
	<li><b>@WebParam</b>- This annotation is used along with @WebMethod annotation
to define the WebService. It is used to customize parameter used in the message part of the
WSDL.</li>
</ul>


<p>This completes the development of the Web Service Implementation code.</p>

<h1><a name="DevelopingasimpleCalculatorWebservice-GeneratingtheWSDLfortheWebservice"></a>Generating
the WSDL for the Web service</h1>
<p>Geronimo provides a new jaxws-tools.bat which helps in generating the WSDL file from
service endpoint interface.</p>
<ul>
	<li>Export the source files to a jar as shown in the following three figures.<br/>
<img src="/confluence/download/attachments/93417/souirce_export.png" align="absmiddle"
border="0" /><br clear="all" /> <br clear="all" /> <br clear="all" />
<img src="/confluence/download/attachments/93417/souirce_export2.png" align="absmiddle"
border="0" /><br clear="all" /> <br clear="all" /> <br clear="all" />
<img src="/confluence/download/attachments/93417/souirce_export1.png" align="absmiddle"
border="0" /><br clear="all" /> <br clear="all" /> <br clear="all" /></li>
	<li>Open a command prompt and point it to the <b>bin</b> directory of server
installation.
	<ol>
		<li>Run the command:
<div class="code panel" style="border-style: solid;border-width: 1px;"><div class="codeHeader
panelHeader" style="border-bottom-width: 1px;border-bottom-style: solid;"><b>WSDL
Generation command</b></div><div class="codeContent panelContent">
<pre class="code-java">
Administrator@T60J9:/&gt; jaxws-tools.bat wsgen -classpath C:/WSDL/source.jar -d C:/WSDL/
-wsdl:soap1.1 org.apache.geronimo.samples.jws.CalculatorService
</pre>
</div></div>
<p>In this command <b>-classpath</b> is used to set the <b>source.jar</b>
exported from Eclipse in the classpath, <b>-d</b> defines the location where all
the generated artifacts will be placed, <b>-wsdl:soap1.1</b> suggests a WSDL generation
following soap1.1 protocol, and <b>org.apache.geronimo.samples.jws.CalculatorService</b>
is the SEI used to generate the WSDL.</p></li>
		<li>Once the above command is run <tt>Calculator_schema1.xsd</tt> and
<tt>Calculator.wsdl</tt> will be generated at <tt>C:/WSDL/</tt>. <br
clear="all" /> <br clear="all" /></li>
		<li>Rename <tt>Calculator.wsdl</tt> as <tt>CalculatorService.wsdl</tt>
and add both the generated files to WEB-INF directory of the project.</li>
	</ol>
	</li>
</ul>


<h1><a name="DevelopingasimpleCalculatorWebservice-DevelopingaWebclientforCalculator"></a>Developing
a Web client for Calculator</h1>
<p>This section will take you through the creation of two JSP's: <tt>index.jsp</tt>
and <tt>result.jsp</tt>. <tt>index.jsp</tt> will prompt the user to
enter two whole number values to add together. After submitting the form, the action will
be forwarded to the <tt>result.jsp</tt>, which will call the <b>Calculator</b>
Web Service.</p>
<ol>
	<li>Right click on the Web Content folder and Select <b>New --&gt; JSP</b>.
<br clear="all" /> <br clear="all" /></li>
	<li>Name the JSP as <em>index.jsp</em> and select <b>Finish.</b><br/>
<img src="/confluence/download/attachments/93417/webclientjsp.png" align="absmiddle" border="0"
/><br clear="all" /> <br clear="all" /> <br clear="all" /></li>
	<li>Add the following code to <tt>index.jsp</tt>:
<div class="code panel" style="border-style: solid;border-width: 1px;"><div class="codeHeader
panelHeader" style="border-bottom-width: 1px;border-bottom-style: solid;"><b>index.jsp</b></div><div
class="codeContent panelContent">
<pre class="code-java">
&lt;%@ page
<span class="code-keyword">import</span>="java.net.URL,javax.xml.namespace.QName,javax.xml.ws.Service,org
.apache.geronimo.samples.jws.Calculator"%&gt;
&lt;html xmlns=<span class="code-quote">"http:<span class="code-comment">//www.w3.org/1999/xhtml"</span>
xml:lang=<span class="code-quote">"en"</span>&gt;
</span>&lt;head&gt;
&lt;title&gt;Calculator&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;form action=<span class="code-quote">"result.jsp"</span>&gt;
Please enter 2 whole numbers to add: &lt;input type=<span class="code-quote">"text"</span>
name=<span class="code-quote">"value1"</span>&gt; + &lt;input type=<span
class="code-quote">"text"</span> name=<span class="code-quote">"value2"</span>&gt;
&lt;input type=<span class="code-quote">"submit"</span>
value=<span class="code-quote">"="</span>&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
</div></div></li>
	<li>Right click on the Web Content folder and Select <b>New -&gt; JSP</b>.
<br clear="all" /> <br clear="all" /></li>
	<li>Name the JSP as <em>result.jsp</em> and select <b>Finish.</b>
<br clear="all" /> <br clear="all" /></li>
	<li>Add the following code to <tt>result.jsp</tt>:
<div class="code panel" style="border-style: solid;border-width: 1px;"><div class="codeHeader
panelHeader" style="border-bottom-width: 1px;border-bottom-style: solid;"><b>result.jsp</b></div><div
class="codeContent panelContent">
<pre class="code-java">
&lt;%@ page
<span class="code-keyword">import</span>="java.net.URL,javax.xml.namespace.QName,javax.xml.ws.Service,org
.apache.geronimo.samples.jws.Calculator"%&gt;
&lt;html xmlns=<span class="code-quote">"http:<span class="code-comment">//www.w3.org/1999/xhtml"</span>
xml:lang=<span class="code-quote">"en"</span>&gt;
</span>&lt;head&gt;
&lt;title&gt;Calculator Result&lt;/title&gt;
&lt;/head&gt;
&lt;%
<span class="code-object">int</span> value1 = 0;
<span class="code-object">int</span> value2 = 0;
<span class="code-object">int</span> sum = 0;
<span class="code-keyword">try</span> {
<span class="code-object">System</span>.out.println( request.getParameter( <span
class="code-quote">"value1"</span> ) + <span class="code-quote">" "</span>
+
request.getParameter( <span class="code-quote">"value2"</span> ) );
value1 = <span class="code-object">Integer</span>.parseInt( request.getParameter(
<span class="code-quote">"value1"</span> ) );
value2 = <span class="code-object">Integer</span>.parseInt( request.getParameter(
<span class="code-quote">"value2"</span> ) );
URL url = <span class="code-keyword">new</span> URL("http:<span class="code-comment">//localhost:8080/jaxws-calculator-
</span>1.0/calculator?wsdl");
QName qname = <span class="code-keyword">new</span>
QName(<span class="code-quote">"http:<span class="code-comment">//jws.samples.geronimo.apache.org"</span>,
<span class="code-quote">"Calculator"</span>);
</span>Service service = Service.create(url, qname);
Calculator calc =
(Calculator)service.getPort(Calculator.class);
sum = calc.add(value1, value2);
} <span class="code-keyword">catch</span> ( Exception e ) {
e.printStackTrace();
}
%&gt;
&lt;body&gt;
The result is: &lt;%=value1%&gt;+&lt;%=value2%&gt;=&lt;%=sum%&gt;
&lt;br&gt;
&lt;a href=<span class="code-quote">"index.jsp"</span>&gt;Back&lt;/a&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
</div></div>
<p>This finishes the development of Web client.</p></li>
</ol>


<h1><a name="DevelopingasimpleCalculatorWebservice-SettinguptheDeploymentDescriptorandDeploymentPlan"></a>Setting
up the Deployment Descriptor and Deployment Plan</h1>
<ol>
	<li>Double click <b>WEB-INF/web.xml</b> and add the following code:
<div class="code panel" style="border-style: solid;border-width: 1px;"><div class="codeHeader
panelHeader" style="border-bottom-width: 1px;border-bottom-style: solid;"><b>web.xml</b></div><div
class="codeContent panelContent">
<pre class="code-java">
&lt;?xml version=<span class="code-quote">"1.0"</span> encoding=<span class="code-quote">"UTF-8"</span>?&gt;
&lt;web-app xmlns:calc=<span class="code-quote">"urn:geronimo-samples-jws"</span>
xmlns=<span class="code-quote">"http:<span class="code-comment">//java.sun.com/xml/ns/javaee"</span>
</span>version=<span class="code-quote">"2.5"</span>&gt;
&lt;servlet&gt;
&lt;display-name&gt;CalculatorService&lt;/display-name&gt;
&lt;servlet-name&gt;CalculatorService&lt;/servlet-name&gt;
&lt;servlet-class&gt;
org.apache.geronimo.samples.jws.CalculatorService
&lt;/servlet-class&gt;
&lt;/servlet&gt;
&lt;servlet-mapping&gt;
&lt;servlet-name&gt;CalculatorService&lt;/servlet-name&gt;
&lt;url-pattern&gt;/calculator&lt;/url-pattern&gt;
&lt;/servlet-mapping&gt;
&lt;service-ref&gt;
            &lt;service-ref-name&gt;services/Calculator&lt;/service-ref-name&gt;
            &lt;service-<span class="code-keyword">interface</span>&gt;javax.xml.ws.Service&lt;/service-<span
class="code-keyword">interface</span>&gt;
            &lt;wsdl-file&gt;WEB-INF/CalculatorService.wsdl&lt;/wsdl-file&gt;
        &lt;/service-ref&gt;
&lt;/web-app&gt;
</pre>
</div></div></li>
	<li>Similarly double click <b>geronimo-web.xml</b> and add the following
code:
<div class="code panel" style="border-style: solid;border-width: 1px;"><div class="codeHeader
panelHeader" style="border-bottom-width: 1px;border-bottom-style: solid;"><b>geronimo-web.xml</b></div><div
class="codeContent panelContent">
<pre class="code-java">
&lt;?xml version=<span class="code-quote">"1.0"</span> encoding=<span class="code-quote">"UTF-8"</span>?&gt;
&lt;web:web-app xmlns:dep=<span class="code-quote">"http:<span class="code-comment">//geronimo.apache.org/xml/ns/deployment-1.2"</span>

</span>             xmlns:conn=<span class="code-quote">"http:<span class="code-comment">//geronimo.apache.org/xml/ns/j2ee/connector-1.2"</span>

</span>             xmlns:name=<span class="code-quote">"http:<span class="code-comment">//geronimo.apache.org/xml/ns/naming-1.2"</span>

</span>             xmlns:ejb=<span class="code-quote">"http:<span class="code-comment">//openejb.apache.org/xml/ns/openejb-jar-2.2"</span>

</span>             xmlns:pkgen=<span class="code-quote">"http:<span class="code-comment">//openejb.apache.org/xml/ns/pkgen-2.1"</span>

</span>             xmlns:app=<span class="code-quote">"http:<span class="code-comment">//geronimo.apache.org/xml/ns/j2ee/application-2.0"</span>

</span>             xmlns:sec=<span class="code-quote">"http:<span class="code-comment">//geronimo.apache.org/xml/ns/security-2.0"</span>

</span>             xmlns:web=<span class="code-quote">"http:<span class="code-comment">//geronimo.apache.org/xml/ns/j2ee/web-2.0.1"</span>

</span>             xmlns:pers=<span class="code-quote">"http:<span class="code-comment">//java.sun.com/xml/ns/persistence"</span>

</span>             xmlns:client=<span class="code-quote">"http:<span class="code-comment">//geronimo.apache.org/xml/ns/j2ee/application-client-2.0"</span>&gt;
</span>
    &lt;dep:environment&gt;
        &lt;dep:moduleId&gt;
            &lt;dep:groupId&gt;org.apache.geronimo.samples.jws&lt;/dep:groupId&gt;
            &lt;dep:artifactId&gt;Calculator&lt;/dep:artifactId&gt;
            &lt;dep:version&gt;1.0&lt;/dep:version&gt;
            &lt;dep:type&gt;car&lt;/dep:type&gt;
        &lt;/dep:moduleId&gt;
        &lt;dep:dependencies&gt;
        &lt;/dep:dependencies&gt;
    &lt;/dep:environment&gt;

    &lt;context-root&gt;/jaxws-calculator-1.0&lt;/context-root&gt;

    &lt;service-ref&gt;
        &lt;service-ref-name&gt;services/Calculator&lt;/service-ref-name&gt;
        &lt;port&gt;
            &lt;port-name&gt;CalculatorPort&lt;/port-name&gt;
            &lt;protocol&gt;http&lt;/protocol&gt;
            &lt;host&gt;localhost&lt;/host&gt;
            &lt;port&gt;8080&lt;/port&gt;
            &lt;uri&gt;/jaxws-calculator/calculator&lt;/uri&gt;
        &lt;/port&gt;
    &lt;/service-ref&gt;
&lt;/web:web-app&gt;
</pre>
</div></div></li>
</ol>


<h1><a name="DevelopingasimpleCalculatorWebservice-DeployandRun"></a>Deploy
and Run</h1>
<ol>
	<li>Right click on <b>jaxws-calculator</b> project. Select <b>Run
As -&gt; Run On Server</b>.<br/>
<img src="/confluence/download/attachments/93417/Run.png" align="absmiddle" border="0"
/><br clear="all" /> <br clear="all" /> <br clear="all" /></li>
	<li>On the next window select Apache Geronimo V2.2 and Select <b>Finish.</b><br/>
<img src="/confluence/download/attachments/93417/Run2.png" align="absmiddle" border="0"
/><br clear="all" /> <br clear="all" /> <br clear="all" /></li>
	<li>Once the application is deployed on the server launch a browser and run the following
URL <a href="http://localhost:8080/jaxws-calculator-1.0/index.jsp" rel="nofollow">http://localhost:8080/jaxws-calculator-1.0/index.jsp</a>.<br
clear="all" /> <br clear="all" />
<img src="/confluence/download/attachments/93417/Run3.png" align="absmiddle" border="0"
/><br clear="all" /> <br clear="all" /> <br clear="all" /></li>
	<li>Give the values as <b>5</b> and <b>7</b> and then select
the <b>=</b> button:<br clear="all" /> <br clear="all" />
<img src="/confluence/download/attachments/93417/Run4.png" align="absmiddle" border="0"
/><br clear="all" /> <br clear="all" /> <br clear="all" /></li>
	<li>The result is <b>12</b> as shown in the figure:<br clear="all" />
<br clear="all" />
<img src="/confluence/download/attachments/93417/Run5.png" align="absmiddle" border="0"
/><br clear="all" /> <br clear="all" /></li>
</ol>

     </div>
     <div id="commentsSection" class="wiki-content pageSection">
       <div style="float: right;">
            <a href="http://cwiki.apache.org/confluence/users/viewnotifications.action"
class="grey">Change Notification Preferences</a>
       </div>

       <a href="http://cwiki.apache.org/confluence/display/GMOxDOC22/Developing+a+simple+Calculator+Web+service">View
Online</a>
       |
       <a href="http://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=93417&revisedVersion=28&originalVersion=27">View
Change</a>
              |
       <a href="http://cwiki.apache.org/confluence/display/GMOxDOC22/Developing+a+simple+Calculator+Web+service?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message