Versions Compared

Key

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

...

  1. Create a Stateless Session EJB Project
    • Select File ->New->Project-> New --> Project




    • In the popup window, select EJB ->EJB -> EJB Project and then click Next




    • Type jaxws-converterejb as the Project Name and click Next..




    • The default option should work for Geronimo, so click Next




    • Here also default options will work, but the service and wsdl file will be located at the URL specified by the annotations




      Tip
      titleChanging Service Location

      If you want to change the service location to any custom URL you want, make sure that the check box Generate Deployment Descriptor is selected.



    • Modify the Group Id to org.apache.geronimo.samples.jaxws and the artifact id to jaxws-converterejb.




    • Click Finish

...

  1. Right click on ejbModule and select New ->Package-> Package




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




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




  4. Name the interface as Converter and use the org.apache.geronimo.samples.jaxws package, then click Finish




  5. Add the following code to the Converter class:
    Code Block
    titleConverter.java
    borderStylesolid
    
    package org.apache.geronimo.samples.jaxws;
    
    import java.math.BigDecimal;
    
    import javax.ejb.Remote;
    import javax.jws.WebService;
    
    @Remote
    @WebService(name = "ConverterPortType",
                targetNamespace = "http://jaxws.samples.geronimo.apache.org")
    public interface Converter {
    
    	public BigDecimal dollarToRupees(BigDecimal dollars);
    
    	public BigDecimal rupeesToEuro(BigDecimal rupees);
    }
    
    


  6. Right click on the new package and select New -->Class> Class




  7. Name the class as ConverterBean and use the org.apache.geronimo.samples.jaxws package, then click Finish




  8. Add the following code to the ConverterBean class:
    Code Block
    titleConverterBean.java
    borderStylesolid
    
    package org.apache.geronimo.samples.jaxws;
    
    import java.math.BigDecimal;
    import javax.ejb.*;
    import javax.jws.WebService;
    
    @Stateless
    @WebService(serviceName = "Converter",
                portName = "ConverterPort",
                endpointInterface = "org.apache.geronimo.samples.jaxws.Converter",
                targetNamespace = "http://jaxws.samples.geronimo.apache.org")
    public class ConverterBean implements Converter {
    	private BigDecimal rupeeRate = new BigDecimal("40.58");
    	private BigDecimal euroRate = new BigDecimal("0.018368");
    
    	public BigDecimal dollarToRupees(BigDecimal dollars) {
    		BigDecimal result = dollars.multiply(rupeeRate);
    		return result.setScale(2, BigDecimal.ROUND_UP);
    	}
    
    	public BigDecimal rupeesToEuro(BigDecimal rupees) {
    		BigDecimal result = rupees.multiply(euroRate);
    		return result.setScale(2, BigDecimal.ROUND_UP);
    	}
    }
    
    

...

Tip
titleGeronimo default location

If you are comfortable with the location that Geronimo deploys the EJB Web Service, you can skip this section and got go to the Deploy and Test Section below.

  1. Expand the META-INF directory present under ejbModule and add the following code to ejb-jar.xml Add the following code to
    Tip
    titleejb-jar.xml

    If ejb-jar.xml is not present, create a XML file and name it as

...

  1. ejb-jar.xml

    Code Block
    titleejb-jar.xml
    borderStylesolid
    
    <?xml version="1.0" encoding="UTF-8"?>
    <ejb-jar version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd">
    	<display-name>jaxws-converterejb</display-name>
    	<enterprise-beans>
    		<session>
    			<ejb-name>jaxws-converterejb</ejb-name>
    			<service-endpoint>org.apache.geronimo.samples.jaxws.Converter</service-endpoint>
    			<ejb-class>org.apache.geronimo.samples.jaxws.ConverterBean</ejb-class>
    			<session-type>Stateless</session-type>
    			<transaction-type>Container</transaction-type>
    		</session>
    	</enterprise-beans>
    </ejb-jar>
    
    

  2. Also add the following code to the openejb-jar.xml present at the same location.
    Code Block
    titleopenejb-jar.xml
    borderStylesolid
    
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <ns4:openejb-jar xmlns="http://geronimo.apache.org/xml/ns/j2ee/connector-1.2"
    xmlns:ns2="http://geronimo.apache.org/xml/ns/deployment-1.2" 
    xmlns:ns3="http://geronimo.apache.org/xml/ns/naming-1.2" 
    xmlns:ns4="http://openejb.apache.org/xml/ns/openejb-jar-2.2" 
    xmlns:ns5="http://openejb.apache.org/xml/ns/pkgen-2.1" 
    xmlns:ns6="http://geronimo.apache.org/xml/ns/j2ee/application-2.0" 
    xmlns:ns7="http://geronimo.apache.org/xml/ns/security-2.0" 
    xmlns:ns8="http://geronimo.apache.org/xml/ns/j2ee/web-2.0.1" 
    xmlns:ns9="http://java.sun.com/xml/ns/persistence" 
    xmlns:ns10="http://geronimo.apache.org/xml/ns/j2ee/application-client-2.0">
        <ns2:environment>
            <ns2:moduleId>
                <ns2:groupId>org.apache.geronimo.samples.jaxws</ns2:groupId>
                <ns2:artifactId>jaxws-converterejb</ns2:artifactId>
                <ns2:version>1.0</ns2:version>
                <ns2:type>car</ns2:type>
            </ns2:moduleId>
        </ns2:environment>
        <ns4:enterprise-beans>
        	<ns4:session>
    			<ns4:ejb-name>jaxws-converterejb</ns4:ejb-name>
    			<ns4:web-service-address>ADD_CUSTOM_URL</ns4:web-service-address>
    		</ns4:session>
    	</ns4:enterprise-beans> 
    </ns4:openejb-jar>
    
    

...

  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 jaxws-converterejb project and click Add




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




  4. Wait for some time till the server status is changed to synchronized.
    Info
    titleErrors at Deploy time

    If you see any errors at deploy time like Unable to read WSDL file null, simply ignore them.



...

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

    http://localhost:8080/Converter/ConverterPortType

    Tip
    titleCustom location

    If you have followed the steps to deploy the service onto custom location, go to the url http://localhost:8080/CUSTOM_URLImage Modified



  2. Now you should see the screen telling that service is located at the following URL:



    Tip
    titleUsing Web Service Explorer in Eclipse

    You can also use Web Services Explorer present in Eclipse to rapidly test your web service without developing a client.
    To know how to use Web Services Explorer in Eclipse, one can refer to the Developing a JAX-WS POJO Web Service#Using Web Services Explorer in Eclipse