Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. Create a Dynamic Web Project

    • Select File ->New->Project-> New --> Project




    • In the popup window, Select Web ->Dynamic -> Dynamic Web Project category and click Next




    • Type jaxrpc-converter as the Project Name and click Next two times.




    • Modify the Group Id to org.apache.geronimo.samples.jaxrpc and the artifact id to jaxrpc-converter.




    • Click Finish

...

Creating the Web Services Implementation code

  1. Right-click on JavaRsources:src and select New -->Package> Package




  2. Name the package to org.apache.geronimo.samples.jaxrpc and click Finish




  3. Right-click on the new package and select New ->Interface-> Interface




  4. Name the interface as Converter and click Finish




  5. Add the following code to the Converter interface class:
    Code Block
    titleConverter.java
    borderStylesolid
    
    package org.apache.geronimo.samples.jaxrpc;
    
    import java.math.BigDecimal;
    import java.rmi.Remote;
    import java.rmi.RemoteException;
    
    
    public interface Converter extends Remote{
    	
    	public BigDecimal dollarToRupees(BigDecimal dollars) throws RemoteException;
    	public BigDecimal rupeesToEuro(BigDecimal rupees) throws RemoteException;
    
    }
    
    
  6. Right click on the new package and select New ->Class-> Class




  7. Name the class as ConverterImpl and click Finish




  8. Add the following code to the ConverterImpl class:
    Code Block
    titleConverterImpl.java
    borderStylesolid
    
    package org.apache.geronimo.samples.jaxrpc;
    
    import java.math.BigDecimal;
    import java.rmi.RemoteException;
    
    
    public class ConverterImpl implements Converter{
    	private BigDecimal rupeeRate = new BigDecimal("40.58");
    	private BigDecimal euroRate = new BigDecimal("0.018368");
    
    	public BigDecimal dollarToRupees(BigDecimal dollars) throws RemoteException {
    		BigDecimal result = dollars.multiply(rupeeRate);
    		return result.setScale(2, BigDecimal.ROUND_UP);
    	}
    
    	public BigDecimal rupeesToEuro(BigDecimal rupees) throws RemoteException {
    		BigDecimal result = rupees.multiply(euroRate);
    		return result.setScale(2, BigDecimal.ROUND_UP);
    	}
    }
    
    

...

Setting Up the Deployment Descriptor and Deployment Plan

Note
titleWSDL file

As for For JAX-WS services, the WSDL file is automatically created by Geronimo at deploy time. There However, there is no such facility for RPC services.

  • Expand WEB-INF directory and add the following code to web.xml:
    Code Block
    titleweb.xml
    borderStylesolid
    
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xmlns="http://java.sun.com/xml/ns/javaee"
    	xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    	id="WebApp_ID" version="2.5">
    	<display-name>jaxrpc-converter</display-name>
    	<servlet>
    		<display-name>JAX-RPC Converter Service</display-name>
    		<servlet-name>JAXRPCConverterService</servlet-name>
    		<servlet-class>
    			org.apache.geronimo.samples.jaxrpc.ConverterImpl
    		</servlet-class>
    	</servlet>
    	<servlet-mapping>
    		<servlet-name>JAXRPCConverterService</servlet-name>
    		<url-pattern>/converter</url-pattern>
    	</servlet-mapping>
    </web-app>
    
    

...

  • Creating the WSDL file
    • Right-click the WEB-INF directory and select New -->Other> Other




    • Select WSDL from the Web Services category in the popup box.




    • Name the file as Converter.wsdl and click Finish.




    • Add the following code to Converter.wsdl;
Code Block
titleConverter.wsdl
borderStylesolid

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns="http://schemas.xmlsoap.org/wsdl/"
	xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
	xmlns:tns="http://org.apache.geronimo.samples.jaxrpc/"
	xmlns:x1="http://org.apache.geronimo.samples.jaxrpc/types"
	xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
	xmlns:xsd="http://www.w3.org/2001/XMLSchema"
	targetNamespace="http://org.apache.geronimo.samples.jaxrpc/"
	name="Converter">

	<wsdl:message name="dollarToRupeesRequest">
		<wsdl:part name="in" type="xsd:decimal" />
	</wsdl:message>
	<wsdl:message name="dollarToRupeesResponse">
		<wsdl:part name="out" type="xsd:decimal" />
	</wsdl:message>

	<wsdl:message name="rupeesToEuroRequest">
		<wsdl:part name="in" type="xsd:decimal" />
	</wsdl:message>
	<wsdl:message name="rupeesToEuroResponse">
		<wsdl:part name="out" type="xsd:decimal" />
	</wsdl:message>

	<wsdl:portType name="Converter">
		<wsdl:operation name="dollarToRupees">
			<wsdl:input message="tns:dollarToRupeesRequest"
				name="dollarToRupeesRequest" />
			<wsdl:output message="tns:dollarToRupeesResponse"
				name="dollarToRupeesResponse" />
		</wsdl:operation>
		<wsdl:operation name="rupeesToEuro">
			<wsdl:input message="tns:rupeesToEuroRequest"
				name="rupeesToEuroRequest" />
			<wsdl:output message="tns:rupeesToEuroResponse"
				name="rupeesToEuroResponse" />
		</wsdl:operation>
	</wsdl:portType>

	<wsdl:binding name="ConverterSOAPBinding" type="tns:Converter">
		<soap:binding style="rpc"
			transport="http://schemas.xmlsoap.org/soap/http" />

		<wsdl:operation name="dollarToRupees">
			<soap:operation soapAction="" style="rpc" />
			<wsdl:input name="dollarToRupeesRequest">
				<soap:body use="literal" />
			</wsdl:input>
			<wsdl:output name="dollarToRupeesResponse">
				<soap:body use="literal" />
			</wsdl:output>
		</wsdl:operation>

		<wsdl:operation name="rupeesToEuro">
			<soap:operation soapAction="" style="rpc" />
			<wsdl:input name="rupeesToEuroRequest">
				<soap:body use="literal" />
			</wsdl:input>
			<wsdl:output name="rupeesToEuroResponse">
				<soap:body use="literal" />
			</wsdl:output>
		</wsdl:operation>

	</wsdl:binding>

	<wsdl:service name="ConverterService">
		<wsdl:port binding="tns:ConverterSOAPBinding"
			name="ConverterPort">
			<soap:address
				location="http://localhost:8080/jaxrpc-converter/ConverterPort" />
		</wsdl:port>
	</wsdl:service>

</wsdl:definitions>

  • Creating the jaxrpcmapping.xml
    • Right-click the WEB-INF directory and select New -->Other> Other




    • Select XML from the XML category in the popup box.




    • Name the file as jaxrpcmapping.xml and click Finish.




    • Add the following code to jaxrpcmapping.xml:
Code Block
titlejaxrpcmapping.xml
borderStylesolid

<?xml version="1.0" encoding="UTF-8"?>
<java-wsdl-mapping
	xmlns="http://java.sun.com/xml/ns/j2ee"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	version="1.1">
</java-wsdl-mapping>

  • Creating the webservices.xml
    • Right-click the WEB-INF directory and select New ->Other-> Other




    • Select XML from the XML category in the popup box.




    • Name the file as webservices.xml and click Finish.




    • Add the following code to webservices.xml:
Code Block
titlewebservices.xml
borderStylesolid

<?xml version="1.0" encoding="UTF-8"?>
<webservices xmlns="http://java.sun.com/xml/ns/j2ee"
             version="1.1">
    <webservice-description>
        <webservice-description-name>JAX-RPC Converter Service</webservice-description-name>
        <wsdl-file>WEB-INF/Converter.wsdl</wsdl-file>
        <jaxrpc-mapping-file>WEB-INF/jaxrpcmapping.xml</jaxrpc-mapping-file>
        <port-component>
            <port-component-name>ConverterPort</port-component-name>
            <wsdl-port>ConverterPort</wsdl-port>
            <service-endpoint-interface>org.apache.geronimo.samples.jaxrpc.Converter</service-endpoint-interface>
            <service-impl-bean>
                <servlet-link>JAXRPCConverterService</servlet-link>
            </service-impl-bean>
        </port-component>
    </webservice-description>
 
</webservices>

...

  • webservices.xml - This is the file necessary for deploying any web services (JAX-RPC or JAX-WS). But starting from JavaEE5 Java EE 5 webservices.xml is no longer necessary.
    This file contains all the necessary components to describe web service and where to find them.

...

Now, we will look into the steps involved in deploying and testing our web service without any clients.

Deploy

  1. Right-click on the Apache Geronimo Server Runtime present in the servers view and select Add or Remove Projects

  2. In the popup dialog, select the jaxrpc-converter project and click Add




  3. Make sure that jaxrpc-converter is in the configured projects list and then click Finish




  4. Wait for some time till the server status is changed to synchronized.

...

  1. Once the application is deployed on to the server, Launch a browser and go to the following url.:

    http://localhost:8080/jaxrpc-converter/converter

  2. Now you should see the screen telling that this is Converter Web Service




    Info
    titleWSDL File

    You can also view the WSDL file generated by Geronimo based on the annotations specified by going to the following url:

    http://localhost:8080/jaxrpc-converter/converter?wsdl

...

The change you are required to do in the client jspJSP's are:

Code Block
titleConverterClient.jsp
borderStylesolid

URL url = new URL("http://localhost:8080/jaxrpc-converter/converter?wsdl");
QName qname = new QName("http://org.apache.geronimo.samples.jaxrpc/","ConverterService");
ServiceFactory factory = null;
Service service = null;
try {
      factory = ServiceFactory.newInstance();
      service = factory.createService(url, qname);
} catch (ServiceException e) {
	e.printStackTrace();
}
Converter conv = (Converter) service.getPort(Converter.class);

...