Developing Web services for Mustang in Netbeans

I read a very good blog about developing web services in Mustang a few weeks ago. However, described web service is very simple, you didn't need to generate WS artifacts for it. In real cases you might use Exceptions in you web method and then you should run wsgen before publishing web service. I would like to use how to develop this web service in last NetBeans 5.5 builds. For instance, my web service method throws some application exception like this:
     @WebMethod(name="getCountEmails")
     public int getTotalCount(@WebParam(name="email")String eMail) throws MailReportException {
            return reportServ.getMailBySender(eMail).size();
    }
  
Of course, project's target JVM should be jdk 1.6.0. Then, add JAX-WS 2.0 library on project's classpath and add these lines in project's build.xml script:
  <target name="-post-compile" depends="init">
        <echo message="Generate WS artifacts"/>
        <taskdef name="wsgen" classname="com.sun.tools.ws.ant.WsGen">
            <classpath path="${javac.classpath}"/>
        </taskdef>
        <wsgen
            debug="true"
            keep="true"
            destdir="build/classes"
            resourcedestdir="build/classes"
            sei="your.package.WSImplementation">
            <classpath>
                <pathelement path="${javac.classpath}"/>
                <pathelement location="${java.home}/../lib/tools.jar"/>
                <pathelement location="build/classes"/>
            </classpath>
        </wsgen>
    </target>
This task invokes wsgen and generate requested beans for exception. Now, you can publish web service:
  Endpoint.publish("http://localhost:8080/MyWebService", new MailReportWS());
run your project and test WSDL in browser.
Comments:

Post a Comment:
Comments are closed for this entry.
About

pblaha

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
Bookmarks