Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migration of unmigrated content due to installation of a new plugin

...

  1. Right click on JavaRsources:src and select New->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





  4. Name the interface as Converter and click Finish





  5. Add the following code to the Converter class
    Code Block
    borderStylesolid
    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;
    
    }
    
    
  1. Right click on the new package and select New->Class





  2. Name the class as ConverterImpl and click Finish





  3. Add the following code to the ConverterImpl class
    Code Block
    borderStylesolid
    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);
    	}
    }
    
    

...

  • Expand WEB-INF directory and add the following code to web.xml
    Code Block
    borderStylesolid
    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





    • 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
borderStylesolid
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"  namespace="http://org.apache.geronimo.samples.jaxrpc/"/>
			</wsdl:input>
			<wsdl:output name="dollarToRupeesResponse">
				<soap:body use="literal"  namespace="http://org.apache.geronimo.samples.jaxrpc/"/>
			</wsdl:output>
		</wsdl:operation>

		<wsdl:operation name="rupeesToEuro">
			<soap:operation soapAction="" style="rpc" />
			<wsdl:input name="rupeesToEuroRequest">
				<soap:body use="literal"  namespace="http://org.apache.geronimo.samples.jaxrpc/"/>
			</wsdl:input>
			<wsdl:output name="rupeesToEuroResponse">
				<soap:body use="literal"  namespace="http://org.apache.geronimo.samples.jaxrpc/"/>
			</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





    • 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
borderStyle
borderStylesolid
titlejaxrpcmapping.xmlsolid

<?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





    • 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
borderStyle
borderStylesolid
titlewebservices.xmlsolid

<?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>

...

  • jaxrpcmapping.xml - Actually this file specifies the mapping between the java methods and WSDL messages. Here it is not required as we are mapping all the methods to WSDL. For Further reference here is a sample that how a method will be mapped from Java to WSDL.
Code Block
borderStylesolid
titlejaxrpcmapping.xmlborderStylesolid

<?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"
	xmlns:Converter="http://org.apache.geronimo.samples.jaxrpc/"
	version="1.1">
	<package-mapping>
		<package-type>org.apache.geronimo.samples.jaxrpc</package-type>
		<namespaceURI>urn:geronimo-samples</namespaceURI>
	</package-mapping>
	<service-interface-mapping>
		<service-interface>
			org.apache.geronimo.samples.jaxrpc.Converter;
		</service-interface>
		<wsdl-service-name>
			Converter:ConverterService
		</wsdl-service-name>
		<port-mapping>
			<port-name>ConverterPort</port-name>
			<java-port-name>ConverterPort</java-port-name>
		</port-mapping>
	</service-interface-mapping>
	<service-endpoint-interface-mapping>
		<service-endpoint-interface>
			org.apache.geronimo.samples.jaxrpc.Converter
		</service-endpoint-interface>
		<wsdl-port-type>Converter:Converter</wsdl-port-type>
		<wsdl-binding>Converter:ConverterSOAPBinding</wsdl-binding>
		<service-endpoint-method-mapping>
			<java-method-name>dollarToRupees</java-method-name>
			<wsdl-operation>dollarToRupees</wsdl-operation>
			<method-param-parts-mapping>
				<param-position>0</param-position>
				<param-type>java.math.BigDecimal</param-type>
				<wsdl-message-mapping>
					<wsdl-message>
						Converter:dollarToRupeesRequest
					</wsdl-message>
					<wsdl-message-part-name>in</wsdl-message-part-name>
					<parameter-mode>IN</parameter-mode>
				</wsdl-message-mapping>
			</method-param-parts-mapping>
			<wsdl-return-value-mapping>
				<method-return-value>
					java.math.BigDecimal
				</method-return-value>
				<wsdl-message>
					Converter:dollarToRupeesResponse
				</wsdl-message>
				<wsdl-message-part-name>out</wsdl-message-part-name>
			</wsdl-return-value-mapping>
		</service-endpoint-method-mapping>
	</service-endpoint-interface-mapping>
</java-wsdl-mapping>

...

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

Code Block
borderStylesolid
titleConverterClient.jspborderStylesolid

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);

...

  • Also in ejb-jar.xml, one has to specify which class are you using as Home, Remote, SEI, Bean. A sample ejb-jar.xml may look like this:
Code Block
borderStylesolid
titleejb-jar.jspborderStylesolid

<ejb-jar xmlns="http://java.sun.com/xml/ns/j2ee" version="2.1">
  <enterprise-beans>
    <session>
      <ejb-name>Converter</ejb-name>
      <home>org.apache.geronimo.samples.jaxrpc.ConverterHome</home>
      <remote>org.apache.geronimo.samples.jaxrpc.ConverterRemote</remote>
      <service-endpoint>org.apache.geronimo.samples.jaxrpc.Converter</service-endpoint>
      <ejb-class>org.apache.geronimo.samples.jaxrpc.ConverterBean</ejb-class>
      <session-type>Stateless</session-type>
      <transaction-type>Container</transaction-type>
    </session>
  </enterprise-beans>
</ejb-jar>

...