J2SE Web Services

J2SE Web Services

To create a web service you don't need to have an Application server (or Web server) installed. This is an illustration how the simple web service can be created in Netbeans5.5 Java Project. I was inspired by a Robert Eckstein and Rajiv Mordani's article about JAX-WS 2.0 With the Java SE 6 Platform and Petr Blaha's blog: Developing Web services for Mustang in Netbeans.

Now in Netbeans5.5 there is a JAX-WS 2.0 technology integrated, which enables you to create and consume web services in Netbeans projects. What is actually supported is : 

  1. Web Service creation in Web application and EJB Project 
  2. Web Service consumption (WS Client) in Web Application, EJB Project, Enterprise Client Application and raw Java Application.

What's is not supported yet is Web Service Creation in raw Java Application (J2SE Project). 
This is a simple workaround how simply this feature can be achieved in Netbeans5.5.

Steps to create RPC/literal Web Service in Java Application.

  1. Start Netbeans5.5, create a new Java Application project and name it GeometricalWS
  2. In Project Customizer add JAX-WS2.0 Library (this step is necessary only if you run Netbeans IDE on JDK1.5 platform) :
    Adding JAX-WS2.0 library
  3. Create a simple Java class and name it CircleFunctions. Also specify the Package Name for the class: geometricalws
  4. Using the @WebService annotation we'll convert this java class to a simple web service. Copy the following code into the editor window:
    package geometricalws;

    import javax.jws.WebMethod;
    import javax.jws.WebParam;
    import javax.jws.WebService;
    import javax.jws.soap.SOAPBinding;

    @WebService(name="Circle", serviceName="CircleService", portName="CirclePort")
    @SOAPBinding(style=SOAPBinding.Style.RPC)
    public class CircleFunctions {

    @WebMethod(operationName="area")
    public double getArea(@WebParam(name="r")double r) {
    return java.lang.Math.PI \* (r \* r);
    }

    @WebMethod(operationName="circumference")
    public double getCircumference(@WebParam(name="r")double r) {
    return 2 \* java.lang.Math.PI \* r;
    }
    }
    (Notice that except of @WebService annotation, @WebMethod and @WebParam annotations are used to annotate web service operations and their parameters.
    These annotations influence the way how WSDL file is created from this class)
  5. Using the javax.xml.ws.Endpoint:publish method the web service can be deployed to a simple web server provided by jax-ws runtime. Modify the Main class in the following way:
    package geometricalws;

    import javax.xml.ws.Endpoint;

    public class Main {

    public static void main(String[] args) {
    String wsAddress = "http://localhost:8765/GeometricalWS/CircleFunctions";
    Endpoint.publish(
    wsAddress,
    new CircleFunctions());
    System.out.println("Web service was published successfuly.\\n"+
    "WSDL URL: "+wsAddress+"?WSDL");

    // this is the way to make the local web server running until the process is killed
    while (true) {
    try {
    Thread.sleep(2000);
    } catch (InterruptedException ex) {}
    }
    }
    }
    (see that the URL address for web service and an instance of CircleFunction class should be specified in publish method)
  6. Run the application (using Run Project action on the project node). The message in output window notifies you that web service was published successfuly:

    Web service was published successfuly.
    WSDL URL: http://localhost:8765/GeometricalWS/CircleFunctions?WSDL

  7. To ensure the web service was really published open your browser and type the URL of web service description file (wsdl file) to the url text field: http://localhost:8765/GeometricalWS/CircleFunctions?WSDL The wsdl file should appear in browser window.
Notice, that web service operation use the RPC/literal binding style. An Advantage of this style is that operation name(area) appears in a soap message. The main disadvantage of this style is inability to validate the soap messages as, in this case, there is no schema generated for the input/output parts in wsdl file.

This is the example how the SOAP communication for this web service look like on the wire:

SOAP Request:
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soapenv:Body>
<ans:area xmlns:ans="http://x/">
<r>10.0</r>
</ans:area>
</soapenv:Body>
</soapenv:Envelope>
SOAP Response:
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soapenv:Body>
<ans:areaResponse xmlns:ans="http://x/">
<return>314.1592653589793</return>
</ans:areaResponse>
</soapenv:Body>
</soapenv:Envelope>
This is the excelent article comparing various (SOAP) binding styles: http://www-128.ibm.com/developerworks/webservices/library/ws-whichwsdl/

Steps to create a Client:

Creating a web service client is very simple using Netbeans5.5:
  1. Create another Java Application project and name it ClientProject
  2. Create new Web Service client ant type the url of wsdl file to WSDL URL text field, set the package name for the client artifacts (java classes that will be generated from the wsdl):
    Client Wizard 
    Press <Finish> button. The Web Service Reference node: CircleFunctions should be created.
  3. Open Main.java in editor and Drag&Drop the "area" operation node from the ProjectsView to editor. A piece of code should be generated inside the main method.
    Then, set the value for WS operation argument (r). See the picture:
    Circle Client

  4. Run the Project. The following message should apear in Output Window :
    Result = 314.1592653589793
Comments:

Welcome!

Posted by Geertjan on October 10, 2006 at 01:49 PM CEST #

thx

Posted by online radyo on April 02, 2008 at 01:08 PM CEST #

thx

Posted by bedava radyo on April 02, 2008 at 01:08 PM CEST #

thx

Posted by canli radyo dinle on April 02, 2008 at 01:09 PM CEST #

thanks ;)

Posted by canli tv izle on April 02, 2008 at 01:09 PM CEST #

thanks

Posted by powerfm on April 02, 2008 at 01:09 PM CEST #

Thanks for this

Posted by youtube on June 16, 2008 at 10:23 AM CEST #

thnx

Posted by Driver indir on September 26, 2008 at 02:27 PM CEST #

Thank you very much for this information. I like this site

Posted by evden eve nakliyat on October 09, 2008 at 04:39 AM CEST #

Thank you very much for this information. I like this site

Posted by ankara evden eve on October 09, 2008 at 04:40 AM CEST #

Thank you very much for this information. I like this site

Posted by ankara nakliyat on October 09, 2008 at 04:40 AM CEST #

Thank you very much for this information. I like this site

Posted by evden eve on October 09, 2008 at 04:40 AM CEST #

Thank you very much for this information. I like this site

Posted by nakliye on October 09, 2008 at 04:41 AM CEST #

Thank you very much for this information. I like this site

Posted by ankara evden eve nakliyat on October 09, 2008 at 04:41 AM CEST #

Thank you very much for this information. I like this site

Posted by nakliyat on October 09, 2008 at 04:42 AM CEST #

thanks you site admins wery good

Posted by seks shop on October 17, 2008 at 02:15 PM CEST #

Great Job!

Posted by Electronic Cigarette on November 23, 2008 at 11:59 PM CET #

A laser system <a href="http://www.dali-cnc.com/laser-machine.asp">laser machine</a> can be used as a stand-alone machine guidance display or as a component of a complete automatic grade control system. When a laser beam strikes the receiver <a href="http://www.dali-cnc.com/vinyl-cutter.asp">vinyl cutter</a> vinyl cutter, the operator then puts the machine in automatic mode to conduct machine control. If the contractor uses the system <a href="http://www.dali-cnc.com/china-cnc-router.asp">china CNC router</a> china CNC router for visual guidance, then the operator would compensate with manual adjustments called for by the system <a href="http://www.dali-cnc.com/engraving-machine.asp">engraving machine</a> engraving machine. Projects conducive to using lasers without machine <a href="http://www.dali-cnc.com/cnc-machines.asp">CNC machines</a> CNC machines automation include placing pads, performing formwork, setting foundations or footings, achieving depth control for sub-base excavation and conducting finish grade work. Laser systems can control as many pieces of equipment as needed, provided there is line of sight to the laser and the same grade or elevation is required.

Posted by Tamper evident labels on December 10, 2008 at 02:32 AM CET #

Rings, anklets, neck laces, pendants, bracelets etc are some of the black pearl jewelry http://www.worldchen.com/fashion-jewelry-suppliers.html fashion jewelry suppliers available for buying. Black pearl jewelry http://www.worldchen.com/stainless-steel-bangle.html stainless steel bangle is suitable for wearing in certain occasions. It really suits people who are really fair as black is in sharp contrast to their body color. Black pearl pendants http://www.worldchen.com/stainless-steel-pendant.html stainless steel pendant with diamond, silver supports are available. In certain watches black pearls are added in the chain to give aesthetic and charming look. These watches are more of a jewelry item. Black pearl jewelry http://www.worldchen.com/stainless-steel-necklace.html stainless steel necklace is suitable for weddings. There are black wedding or bridal jewelry collections targeting people who are marrying shortly.
Necklaces of black pearls http://www.worldchen.com/stainless-steel-earring.html stainless steel earring are made more attractive with usage of silver, carbon and some other ribbons. Jewel houses have good collection of black pearls. In olden ages pearls were very precious than some of other precious stones. In this 21st century the price may have changed but the charm of the pearls are still appealing. Black pearl jewelry http://www.worldchen.com/titanium-jewelry-wholesale.html titanium jewelry wholesale can make you look pleasant for any occasion.

Posted by Electronic Cigarette Supplier on December 10, 2008 at 02:35 AM CET #

http://www.tiffanysjewelry.co.uk
http://www.idealtest.net

Posted by tiffanys jewelry on February 09, 2009 at 01:10 AM CET #

<p>You are right, I believe that there will be many readers like you</p>
<p><A href="http://www.bestlouisvuitton.com/chanel-bags-chanel-cambon-c-234_255.html">Chanel Cambon</A>?<A href="http://www.discount-christianlouboutin.com/christian-louboutin-c-13.html">Christian Louboutin</A>?<A href="http://www.bestlouisvuitton.com/chanel-bags-c-234.html">Chanel Bags</A> <A href="http://www.bestlouisvuitton.com/chanel-bags-chanel-clutches-c-234_244.html">Chanel Clutches</A> <A href="http://www.discount-christianlouboutin.com/jimmy-choo-c-14.html">Jimmy Choo</A>
</p>
<p><A href="http://www.bestlouisvuitton.com/chanel-bags-chanel-denim-handbags-c-234_245.html">Chanel Denim Handbags</A>?<A href="http://www.discount-christianlouboutin.com/manolo-blahnik-c-15.html">Manolo Blahnik</A> <A href="http://www.bestlouisvuitton.com/chanel-bags-chanel-nappa-handbags-c-234_249.html">Chanel nappa handbags</A></p>

<p><A href="http://www.discount-christianlouboutin.com/yves-saint-lauret-c-16.html">Yves Saint Lauret</A>?<A href="http://www.buylouboutin.com/christian-louboutin-boots-c-67.html">Christian Louboutin Boots</A> <A href="http://www.yitingbuy.com/gucci-handbags-c-138_140.html">Gucci Handbags</A></p>
<p><A href="http://www.discount-christianlouboutin.com/">discount christianlouboutin</A><A href="http://www.buylouboutin.com/manolo-blahnik-c-68.html">Manolo Blahnik</A> <A href="http://www.yitingbuy.com/gucci-bags-c-138.html">Gucci Bags</A>?<A href="http://www.yitingbuy.com/gucci-handbags-c-138_140.html"></A></p>
<p><A href="http://www.buylouboutin.com/jimmy-choo-c-72.html">Jimmy Choo</A>? <A href="http://www.yitingbuy.com/gucci-wallets-c-138_139.html">Gucci Wallets</A>?<A href="http://www.bestlouisvuitton.com/louis-vuitton-bags-c-200.html">Louis Vuitton Bags</A></p>

<p><A href="http://www.buylouboutin.com/yves-saint-lauret-c-73.html">Yves Saint Lauret</A>? <A href="http://www.buylouboutin.com/yves-saint-lauret-c-73.html">YSL</A>?<A href="http://www.buylouboutin.com/">Christian Louboutin</A>?</p>
<p><A href="http://www.bestlouisvuitton.com/">http://www.bestlouisvuitton.com/</A></p>
<p><A href="http://www.buylouboutin.com/">http://www.buylouboutin.com/</A></p>
<p><A href="http://www.yitingbuy.com/">http://www.yitingbuy.com/</A></p>
<p><A href="http://www.discount-christianlouboutin.com/">http://www.discount-christianlouboutin.com/</A></p>
<p>&nbsp;</p>

Posted by dfgdf on October 05, 2009 at 01:58 AM CEST #

I like the side of the article.

Posted by Christian Louboutin on November 18, 2009 at 05:20 AM CET #

Thank you. This is very good article.

Posted by laptop on December 31, 2009 at 12:16 PM CET #

thanks

Posted by oyun on February 02, 2010 at 07:39 AM CET #

wooooowwww

Posted by Şiirler on November 01, 2010 at 02:49 PM CET #

Post a Comment:
  • HTML Syntax: NOT allowed
About

mkuchtiak

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today