Personal tools

Tutorials:NetbeansWSServer: Difference between revisions

From Adapt

Jump to: navigation, search
No edit summary
 
No edit summary
Line 36: Line 36:


<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:
<verbatim>
<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>
</verbatim>
</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 144: Line 144:
<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::
<verbatim>
<pre>
   package edu.umiacs.sample;
   package edu.umiacs.sample;


Line 154: Line 154:
     }
     }
   }
   }
</verbatim>
</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.
Line 160: Line 160:
  The deploy wsdd describes which class will handle service requests, This file is 'WEB-INF/WSStuff.deploy.wsdd' ::
  The deploy wsdd describes which class will handle service requests, This file is 'WEB-INF/WSStuff.deploy.wsdd' ::


<verbatim>
<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 178:


   </deployment>
   </deployment>
</verbatim>
</pre>


  The undeploy wsdd should contain tell which services to remove 'WEB-INF/WSStuff.undeploy.wsdd'
  The undeploy wsdd should contain tell which services to remove 'WEB-INF/WSStuff.undeploy.wsdd'


<verbatim>
<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>
</verbatim>
</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  
Line 200: Line 200:
  Add the following after the &lt;import file=...../&gt;::
  Add the following after the &lt;import file=...../&gt;::


<verbatim>
<pre>
     <property  
     <property  
         name="service.name"  
         name="service.name"  
Line 309: Line 309:


     </target>
     </target>
</verbatim>
</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.

Revision as of 22:44, 11 September 2008

---++Creating a web service using Netbeans

  1. Create new project, 'File->New Project'. Select 'Category' Web and 'Web Application'. Click next. Enter a new name for your project.
  2. 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
  3. 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.
  4. 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>
    
  5. 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.

  1. 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");
        }
      }
    
  2. 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>
    
  3. 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>
    
  4. 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