Tutorials:NetbeansWSServer: Difference between revisions
From Adapt
No edit summary |
No edit summary |
||
(One intermediate revision by the same user not shown) | |||
Line 1: | Line 1: | ||
==Creating a web service using Netbeans== | |||
<OL> | <OL> | ||
Line 8: | Line 8: | ||
packages. These are located in subversion under external-lib. | 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 | 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: | 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 | |||
<LI>Modify the built-in tomcat to run on port 8080. | <LI>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. | |||
<LI>Under WEB-INF, modify the web.xml file to look as follows: | <LI>Under WEB-INF, modify the web.xml file to look as follows: | ||
< | <pre> | ||
<?xml version="1.0" encoding="ISO-8859-1"?> | <?xml version="1.0" encoding="ISO-8859-1"?> | ||
Line 133: | Line 133: | ||
</web-app> | </web-app> | ||
</ | </pre> | ||
<LI>Test your install. Copy the happyaxis.jsp from the producer or example web services | <LI>Test your install. Copy the happyaxis.jsp from the producer or example web services | ||
Line 139: | Line 139: | ||
http://localhost:8080/project/happyaxis.jsp and see that everything is setup. | http://localhost:8080/project/happyaxis.jsp and see that everything is setup. | ||
</ol> | </ol> | ||
--- | |||
---- | |||
Now it's time to create a web service. | Now it's time to create a web service. | ||
<OL> | <OL> | ||
<LI>Create a class that you will use as your entry point:: | <LI>Create a class that you will use as your entry point:: | ||
< | <pre> | ||
package edu.umiacs.sample; | package edu.umiacs.sample; | ||
Line 154: | Line 155: | ||
} | } | ||
} | } | ||
</ | </pre> | ||
<LI>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. | <LI>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' :: | |||
< | <pre> | ||
<deployment xmlns="http://xml.apache.org/axis/wsdd/" | <deployment xmlns="http://xml.apache.org/axis/wsdd/" | ||
xmlns:java="http://xml.apache.org/axis/wsdd/providers/java"> | xmlns:java="http://xml.apache.org/axis/wsdd/providers/java"> | ||
Line 178: | Line 179: | ||
</deployment> | </deployment> | ||
</ | </pre> | ||
The undeploy wsdd should contain tell which services to remove 'WEB-INF/WSStuff.undeploy.wsdd' | |||
< | <pre> | ||
<undeployment | <undeployment | ||
xmlns="http://xml.apache.org/axis/wsdd/"> | xmlns="http://xml.apache.org/axis/wsdd/"> | ||
<service name="WSStuff"/> | <service name="WSStuff"/> | ||
</undeployment> | </undeployment> | ||
</ | </pre> | ||
<LI>Now, you will need to modify the build.xml of your new project. In the | <LI>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. | '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 | should reflect your package layout. Service.url should match the name of web service you | ||
are deploying | are deploying | ||
Add the following after the <import file=...../>:: | |||
< | <pre> | ||
<property | <property | ||
name="service.name" | name="service.name" | ||
Line 309: | Line 310: | ||
</target> | </target> | ||
</ | </pre> | ||
<LI>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. | <LI>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. | ||
</ol> | </ol> | ||
Latest revision as of 22:46, 11 September 2008
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
- javax.mail:
- 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:
<?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> <!-- uncomment this if you want the admin servlet --> <servlet-mapping> <servlet-name>AdminServlet</servlet-name> <url-pattern>/servlet/AdminServlet</url-pattern> </servlet-mapping> <session-config> <!-- Default to 5 minute session timeouts --> <session-timeout>5</session-timeout> </session-config> <!-- currently the W3C havent settled on a media type for WSDL; http://www.w3.org/TR/2003/WD-wsdl12-20030303/#ietf-draft for now we go with the basic 'it's XML' response --> <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>
- 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::
package edu.umiacs.sample; public class WSStuff { public WSStuff() {} public String helloWorld() { return new String("Hello World"); } }
- 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' ::
<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> <!-- advertise everythins "*" in WSStuff --> <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>
The undeploy wsdd should contain tell which services to remove 'WEB-INF/WSStuff.undeploy.wsdd'
<undeployment xmlns="http://xml.apache.org/axis/wsdd/"> <service name="WSStuff"/> </undeployment>
- 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=...../>::
<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"/> <!-- Don't edit these --> <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"> <!-- <uptodate property="wsdl.uptodate" value="true" srcfile="${service.java}" targetfile="${service.wsdl}"/> --> </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>
- 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.