October 30, 2014
Hot Topics:
RSS RSS feed Download our iPhone app

Creating Web Services from J2EE Components

  • September 20, 2004
  • By Nandhini Arumugam and Sujata De
  • Send Email »
  • More Articles »

Creating a Web Service from a Java class file

Follow the steps given below to create a Web service from a Java class. Copy myWebService.java into your directory and compile it.

public class myWebService
{
   public String sayHello(String name)
   {
      if(name==null)
         return "Hello Guest";
      else
         return "Hello " + name;
   }
}

myWebService.java

The servicegen Ant task will create a myWebService.ear file that can be deployed into Weblogic. Run the following Ant task using the command "ant" from the command prompt.

<project name="buildWebservice" default="build-ear">
   <target name="build-ear">
      <servicegen
         destEar="myWebService.ear"
         warName="myWAR.war" 
         contextURI="web_services">
         <service
         javaClassComponents="myWebService"
         targetNamespace="http://www.bea.com/examples"
            serviceName="TraderService"
            serviceURI="/TraderService"
            generateTypes="True"
            expandMethods="True"
               style="RPC">
         </service>
      </servicegen>
   </target>
</project>

build.xml

Once myWebservice.ear is created, deploy it in Weblogic under Deployments->Applications. The URL for accessing this Web service will be http://hostname:portname/servicename. For example, http://localhost:7001/myWebservice/myWebservice.

Note: The style="rpc" attribute specifies that the operations in the Web Service are all RPC-oriented. If the operations in your Web Service are document-oriented, specify style="document" and run the Antbuild.

Conclusion

The real value of Web services lies in the composition of a set of Web services, or what is commonly known as creating a 'flow'. To create a truly versatile business flow suited to every purpose of the target user, Web services have to be developed from various kinds of software components on various technologies, languages, and platforms. The present work addresses the creation of a simple Web service from a variety of J2EE components.

About the Authors

Nandhini Arumugam holds a Masters degree in Computer Applications from PSG College of Technology, Coimbatore. She has worked as a Software Engineer in the Telecom and Mobile Solutions Lab, Hewlett-Packard, Bangalore for more than one year. The domain of her experience includes Web services and J2EE-related technologies. She can be reached at nandhini.arumugam@hp.com.

Sujata De is a Senior Software Engineer for Telecom and Mobile Solutions Lab, Hewlett-Packard, Bangalore. She holdsa Bachelor's degree in Civil Engineering from the Indian Institute of Technology, Kharagpur, followed by Master's degree in Mechanical Engineering from the Indian Institute of Science, Bangalore. She has around three years of industry experience involving quality, Web services, LDAP, UDDI, and J2EE technologies and is currently involved in developing access controllers for Web services. She can be reached at sujata.de@hp.com.





Page 3 of 3



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Sitemap | Contact Us

Rocket Fuel