Tutorials:NetbeansWSServer
From Adapt
---++Creating a web service using Netbeans
- Create new project, 'File->New Project'. Select 'Category' Web and 'Web Application'. Click next. Enter a new name for your project.
- Load all necessary libraries into the 'Tools->Library Manager'. You will need to load the javax.mail, javax.activation, org.apache.axis, org.apache.log4j packages. These are located in subversion under external-lib. To use these locally, you will need to svn co http://narasvn.umiacs.umd.edu/repository/external-lib/javax.mail/1.3.2/ javax.mail In the library manager, click 'New Library', type the name of the package (ie, javax.mail) and under 'Classpath' add all jar files in the package you download. Optionally if there are zip'd javadoc files those can be added as well. Now, you have to add them to your project, right click the project and select properties. Under 'Build->Compiling Sources', click 'Add Library' and add the new library. Repeat for the other three. Library jar list: * javax.mail: * mail.jar * javax.activation: * activation.jar * org.apache.axis * org.apache.axis/axis-ant.jar * axis.jar * commons-logging.jar * jaxrpc.jar * wsdl4j.jar * axis-src.jar * saaj.jar * commons-discovery.jar
- Modify the built-in tomcat to run on port 8080. Under 'Runtime->Server Registry->Tomcat 5 Servers', right click 'Bundled tomcat' and select properties. Change the server port to 8080.
- Under WEB-INF, modify the web.xml file to look as follows: <verbatim> <?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"> <web-app> <display-name>Sample Servlet</display-name> <listener> <listener-class>org.apache.axis.transport.http.AxisHTTPSessionListener</listener-class> </listener> <servlet> <servlet-name>AxisServlet</servlet-name> <display-name>Apache-Axis Servlet</display-name> <servlet-class> org.apache.axis.transport.http.AxisServlet </servlet-class> </servlet> <servlet> <servlet-name>AdminServlet</servlet-name> <display-name>Axis Admin Servlet</display-name> <servlet-class> org.apache.axis.transport.http.AdminServlet </servlet-class> <load-on-startup>100</load-on-startup> </servlet> <servlet> <servlet-name>SOAPMonitorService</servlet-name> <display-name>SOAPMonitorService</display-name> <servlet-class> org.apache.axis.monitor.SOAPMonitorService </servlet-class> <init-param> <param-name>SOAPMonitorPort</param-name> <param-value>5001</param-value> </init-param> <load-on-startup>100</load-on-startup> </servlet> <servlet-mapping> <servlet-name>AxisServlet</servlet-name> <url-pattern>/servlet/AxisServlet</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>AxisServlet</servlet-name> <url-pattern>*.jws</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>AxisServlet</servlet-name> <url-pattern>/services/*</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>SOAPMonitorService</servlet-name> <url-pattern>/SOAPMonitor</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>AdminServlet</servlet-name> <url-pattern>/servlet/AdminServlet</url-pattern> </servlet-mapping> <session-config> <session-timeout>5</session-timeout> </session-config> <mime-mapping> <extension>wsdl</extension> <mime-type>text/xml</mime-type> </mime-mapping> <mime-mapping> <extension>xsd</extension> <mime-type>text/xml</mime-type> </mime-mapping> <welcome-file-list id="WelcomeFileList"> <welcome-file>index.html</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file>index.jws</welcome-file> </welcome-file-list> </web-app> </verbatim>
- Test your install. Copy the happyaxis.jsp from the producer or example web services to 'Web Pages' and run your project. You should be able to go to a url such as http://localhost:8080/project/happyaxis.jsp and see that everything is setup.
--- Now it's time to create a web service.
- Create a class that you will use as your entry point:: <verbatim> package edu.umiacs.sample; public class WSStuff { public WSStuff() {} public String helloWorld() { return new String("Hello World"); } } </verbatim>
- Create Service Descriptors. The prefix of these files should match the service/class that you are deploying, in this case it's WSStuff. The location of these files are specified in the build.xml shown a little later. The deploy wsdd describes which class will handle service requests, This file is 'WEB-INF/WSStuff.deploy.wsdd' :: <verbatim> <deployment xmlns="http://xml.apache.org/axis/wsdd/" xmlns:java="http://xml.apache.org/axis/wsdd/providers/java"> <globalConfiguration> <parameter name="sendMultiRefs" value="false"/> </globalConfiguration> <service name="WSStuff" provider="java:RPC"> <parameter name="className" value="edu.umiacs.sample.WSStuff"/> <parameter name="allowedMethods" value="*"/> <namespace>urn:sample.umiacs.edu</namespace> </service> </deployment> </verbatim> The undeploy wsdd should contain tell which services to remove 'WEB-INF/WSStuff.undeploy.wsdd' <verbatim> <undeployment xmlns="http://xml.apache.org/axis/wsdd/"> <service name="WSStuff"/> </undeployment> </verbatim>
- Now, you will need to modify the build.xml of your new project. In the 'Files' view, open up the 'build.xml' under your project. Edit the service.name, service.namespace, service.java.namespace, and service.url properties. You can view the umiacs-ca and pawn-producer packages for examples. service.name should match the class you are using as your gateway, and namespace/path should reflect your package layout. Service.url should match the name of web service you are deploying Add the following after the <import file=...../>:: <verbatim> <property name="service.name" value="WSStuff"/> <property name="service.namespace" value="pawn:sample.umiacs.edu"/> <property name="service.java.namespace" value="edu.umiacs.sample"/> <property name="service.java.path" value="edu/umiacs/sample"/> <property name="service.url" value="http://localhost:8080/test"/> <property name="service.java" value="${basedir}/src/${service.java.path}/${service.name}.java"/> <property name="service.class" value="${service.java.namespace}.${service.name}"/> <property name="service.wsdl" value="${basedir}/web/WEB-INF/${service.name}.wsdl"/> <property name="service.deploy.wsdd" value="${basedir}/web/WEB-INF/${service.name}.deploy.wsdd"/> <property name="service.undeploy.wsdd" value="${basedir}/web/WEB-INF/${service.name}.undeploy.wsdd"/> <property name="build.classes" value="${basedir}/build/web/WEB-INF/classes"/> <property name="axis.admin-service" value="${service.url}/services/AdminService"/> <property name="service.default.url" value="${service.url}/services/${service.name}"/> <target name="-pre-compile" depends="-check-wsdl-uptodate"/> <target name="-post-compile" depends="-generate-wsdl"/> <target name="run" depends="run-deploy,-ws-register,run-display-browser"/> <target name="-check-wsdl-uptodate"> </target> <target name="-generate-wsdl" unless="wsdl.uptodate"> <echo message="Generating WSDL document"/> <taskdef resource="axis-tasks.properties" classpathref="axis.classpath"/> <path id="axis.classpath"> <pathelement path="${javac.classpath}"/> <pathelement path="${build.classes}"/> </path> <axis-java2wsdl classname="${service.class}" location="${service.default.url}" namespace="${service.namespace}" useinheritedmethods="true" stopclasses="java.lang.Exception" output="${service.wsdl}"/> </target> <target name="-ws-register"> <taskdef resource="axis-tasks.properties" classpathref="axis.classpath"/> <path id="axis.classpath"> <pathelement path="${javac.classpath}"/> <pathelement path="${build.classes}"/> </path> <axis-admin url="${axis.admin-service}" failonerror="true" debug="true" xmlfile="${service.undeploy.wsdd}"/> <axis-admin url="${axis.admin-service}" failonerror="true" debug="true" xmlfile="${service.deploy.wsdd}"/> </target> </verbatim>
- Test your new services, build, and redeploy. You should be able to go to http://localhost:8080/project/services::http://localhost:8080/project/services and download the wsdl for your new service.
-- Main.MikeSmorul - 02 May 2005