JAVA Web service (jax_rpc)开发1

这里较详细的介绍java 开发web service 的技术规范。更多的只是为了供开发人员参考,少走弯路。

web service 开发涉及的内容很多。包括:xml方面,这里有一块,wsdl,xml shceme,soap等要了解。

在Java技术规范方面有,jax_rpc,saaj,jaxm,jaxr等,下面说说他们用途,因为这些可能用到较少,大多用来开发web service 的可能是axis,因为方便点,速度也会快点。

jax_rpc:是基本的功能,开发起来比较简单.但没有更多的功能,如附件,异步通信。基于j2ee1.4下面有个例子。

以下的内容都是引用自Java Web Services in a Nutshell.chm

可以通过我的资源中得到,不过是E文。

这个例子很完整,在编译ant时会出现配置错误,可自己的目录修改。部署文件提供参考,也可通过ant生成。

接口: /**  * A class that holds information relating  * to a book known to the book web service.  */ public class BookInfo {         /**      * The title of the book.      */     private String title;         /**      * The book's author (or authors)      */     private String author;         /**      * The book's editor      */     private String editor;         /**      * The list price of the book.      */     private double price;         /**      * Constructs an uninitialized <code>BookInfo</code> object.      */     public BookInfo() {     }         /**      * Constructs a <code>BookInfo</code> object initialized      * with given attributes.      * @param title the book's title      * @param author the name of the book's author      * @param editor the name of the book's editor      * @param price the price of the book.      */     public BookInfo(String title, String author, String editor, double price) {         this.title = title;         this.author = author;         this.editor = editor;         this.price = price;     }         /**      * Gets the title of the book      * @return the book's title.      */     public String getTitle() {         return title;     }         /**      * Gets the author of the book      * @return the book's author.      */     public String getAuthor() {         return author;     }         /**      * Gets the name of the editor the book      * @return the book's editor.      */     public String getEditor() {         return editor;     }         /**      * Gets the price of the book in USD      * @return the book's price.      */     public double getPrice() {         return price;     }             /**      * Sets the title of the book      * @param title the book's title.      */     public void setTitle(String title) {         this.title = title;     }         /**      * Sets the author of the book      * @param author the book's author.      */     public void setAuthor(String author) {         this.author = author;     }         /**      * Sets the name of the editor the book      * @param editor the book's editor.      */     public void setEditor(String editor) {         this.editor = editor;     }         /**      * Sets the price of the book in USD      * @param price the book's price.      */     public void setPrice(double price) {         this.price = price;     }    }

 /**  * The interface definition for the book  * web service.  */ public interface BookQuery extends Remote {         /**      * Gets the number of books known to the service      * @return the number of books known to the service.      */     public abstract int getBookCount() throws RemoteException;         /**      * Get the author for a book with a given name.      * @param name the name of the book.      * @return the author of the book, or <code>null</code>      * if no matching book can be found.      */     public abstract String getAuthor(String name) throws RemoteException;         /**      * Gets the name of the editor for a book.      * @param name the name of the book.      * @return the editor of the book, or <code>null</code>      * if no matching book can be found.      */     public abstract String getEditor(String name) throws RemoteException;         /**      * Gets the price of a book with a given name. If the given      * name does not match with a known book, a <code>BookServiceException</code>      * is thrown.      * @param name the name of the book.      * @return the price of the book.      */     public abstract double getPrice(String name) throws BookServiceException,                                                         RemoteException;         /**      * Gets information for all known books, in the form of an      * array.      * @return an array of <code>BookInfo</code> objects with one      * entry for each book.      */     public abstract BookInfo[] getBookInfo() throws RemoteException;         /**      * Returns all of the books known to the book      * service in the form of a <code>HashMap</code> where the      * key to each entry is the book title in upper case      * and the value is a <code>BookInfo</code> object.      */     public abstract HashMap getBookMap() throws RemoteException; }

/**  * A service-specific exception that reports  * problems while executing methods of the book  * web service.  */ public class BookServiceException extends Exception {         /**      * Constructs a <code>BookServiceException</code> with      * an associated message.      * @param message a message describing the reason for      * the exception.      */     public BookServiceException(String message) {         super(message);     }         /**      * Gets the message associated with this exception.      * @return the message describing the reason for      * the exception.      */     public String getMessage() {         return super.getMessage();     }

}

服务器实现:

booklist.txt

Java in a Nutshell!David Flanagan!Paula Ferguson, Robert Eckstein!39.95 Java Foundation Classes in a Nutshell!David Flanagan!Paula Ferguson!29.95 J2ME in a Nutshell!Kim Topley!Robert Eckstein!29.95 Java Swing!Robert Eckstein et al!Mike Loukides!44.95 Java Servlet Programming!Jason Hunter, William Crawford!Paula Ferguson!32.95 Enterprise JavaBeans!Richard Monson-Haefel!Mike Loukides!34.95 JavaServer Pages!Hans Bergsten!Robert Eckstein, Paula Ferguson!39.95 Java I/O!Elliotte Rusty Harold!Mike Loukides!32.95 Java 2D Graphics!Jonathan Knudsen!Mike Loukides!29.95 Creating Effective JavaHelp!Kevin Lewis!John Posner, Mike Loukides!29.95 Java Performance Tuning!Jack Shirazi!Mike Loukides!34.95 Java Internationalization!Andrew Deitsch, David Czarnecki!Mike Loukides!39.95

import java.util.HashMap;

/**  * Implementation class for the books web service.  */ public class BookServiceServant implements BookQuery {         /**      * Gets the number of books known to the service      * @return the number of books known to the service.      */     public int getBookCount() {         return BookServiceServantData.getBookInfo().length;     }         /**      * Get the author for a book with a given name.      * @param name the name of the book.      * @return the author of the book, or <code>null</code>      * if no matching book can be found.      */     public String getAuthor(String name) {         BookInfo book = findBook(name);         return book == null ? null : book.getAuthor();     }         /**      * Gets the name of the editor for a book.      * @param name the name of the book.      * @return the editor of the book, or <code>null</code>      * if no matching book can be found.      */     public String getEditor(String name) {         BookInfo book = findBook(name);         return book == null ? null : book.getEditor();     }         /**      * Gets the price of a book with a given name. If the given      * name does not match with a known book, a BookServiceException      * is thrown.      * @param name the name of the book.      * @return the price of the book.      */     public double getPrice(String name) throws BookServiceException {         BookInfo book = findBook(name);         if (book == null) {             // No such book - throw an exception             throw new BookServiceException("No matching book for '" + name + "'");         }         return book.getPrice();     }         /**      * Gets information for all known books, in the form of an array.      * @return an array of <code>BookInfo</code> objects with one      * entry for each book.      */     public BookInfo[] getBookInfo() {         return BookServiceServantData.getBookInfo();     }         /**      * Returns all of the books known to the book      * service in the form of a <code>HashMap</code> where the      * key to each entry is the book title in upper case      * and the value is a <code>BookInfo</code> object.      */     public HashMap getBookMap() {         return BookServiceServantData.getBookInfoHashMap();     }         /* -- Implementation details -- */     /**      * Looks for a book whose title matches a given string.      * The comparison is case-insensitive.      * @param name the string to match against the book name      * @return the <code>BookInfo</code> object for the first      * matching book, or <code>null</code> if no match exists.      */     private BookInfo findBook(String name) {         BookInfo[] books = BookServiceServantData.getBookInfo();         for (int i = 0; i < books.length; i++) {             if (books[i].getTitle().equalsIgnoreCase(name)) {                 // Found a match                 return books[i];             }         }         return null;        // No match     } }

import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; import java.util.ArrayList; import java.util.HashMap; import java.util.StringTokenizer;

/**  * A class that loads the data for the book service  * and provides access to it in the form of an array  * of BookInfo objects.  */ class BookServiceServantData {         /**      * The loaded data, created when it is first requested      */     private static BookInfo[] bookInfo;         /**      * The data in the form of a HashMap, created when it is      * first requested.      */     private static HashMap bookMap;         /**      * Gets the book info, creating it if necessary.      * @return an array of BookInfo objects with one entry      * for each book.      */     static BookInfo[] getBookInfo() {         if (bookInfo == null) {             // First request - create the data             ArrayList list = new ArrayList();             try {                 InputStream is =                     BookServiceServantData.class.getResourceAsStream("booklist.txt");                 BufferedReader reader = new BufferedReader(new InputStreamReader(is));                 String line;                 while ((line = reader.readLine()) != null) {                     StringTokenizer st = new StringTokenizer(line, "!");                     if (st.countTokens() == 4) {                         list.add(new BookInfo(st.nextToken(), st.nextToken(),                                 st.nextToken(), Double.parseDouble(st.nextToken())));                     }                 }             } catch (Exception ex) {                 // Just return an empty or partial list                                ex.printStackTrace();             }                         // Convert the list to an array             bookInfo = new BookInfo[list.size()];             list.toArray(bookInfo);         }         return bookInfo;     }               /**      * Returns all of the books known to the book      * service in the form of a <code>HashMap</code> where the      * key to each entry is the book title in upper case      * and the value is a <code>BookInfo</code> object.      */     static HashMap getBookInfoHashMap() {         if (bookMap == null) {             BookInfo[] info = getBookInfo();             bookMap = new HashMap();             for (int i = 0; i < info.length; i++) {                 BookInfo book = info[i];                 bookMap.put(book.getTitle().toUpperCase(), book);             }         }         return bookMap;     } }

客服端: import java.util.HashMap; import java.util.Iterator; import java.util.Map;

// JAX-RPC imports import javax.xml.rpc.Service; import javax.xml.rpc.Stub;

// Service imports import ora.jwsnut.chapter2.bookservice.BookInfo; import ora.jwsnut.chapter2.bookservice.BookQuery;

// Import for service import ora.jwsnut.chapter2.bookservice.BookService_Impl;

public class BookMapBookServiceClient {         public static void main(String[] args) {                 try {             if (args.length != 1) {                 usage();             }                         // Get a reference to the stub and set the service address             BookService_Impl service = new BookService_Impl();             BookQuery bookQuery = (BookQuery)service.getBookQueryPort();             ((Stub)bookQuery )._setProperty(Stub.ENDPOINT_ADDRESS_PROPERTY, args[0]);                         // Perform the RPC and print the results                      HashMap map = bookQuery.getBookMap();             Iterator iter = map.entrySet().iterator();             while (iter.hasNext()) {                 Map.Entry entry = (Map.Entry)iter.next();                 BookInfo info = (BookInfo)entry.getValue();                 System.out.println("KEY: [" + entry.getKey() + "], value = "+                                 info.getTitle() + " by " +                                 info.getAuthor() + ", edited by " +                                 info.getEditor() + ", price USD " +                                 info.getPrice());             }             System.exit(0);         } catch (Throwable t) {             System.out.println("CLASS: " + t.getClass().getName() + "/n/n");             System.out.println(t.getMessage());             t.printStackTrace(System.out);         }     }          private static void usage() {         System.err.println("Usage: BookMapBookServiceClient address");         System.exit(1);     } }

配置文件:

config.xml

<?xml version="1.0" encoding="UTF-8" ?>   <configuration          xmlns="http://java.sun.com/xml/ns/jax-rpc/ri/config">       <service name="BookService"               targetNamespace="urn:jwsnut.chapter2.bookservice/wsdl/BookQuery"               typeNamespace="urn:jwsnut.chapter2.bookservice/types/BookQuery"             packageName="ora.jwsnut.chapter2.bookservice">

        <interface name="ora.jwsnut.chapter2.bookservice.BookQuery"/>     </service> </configuration>

ant文件:

buildsetup.xml

<!-- File containing common setup for all builds -->

<!-- Import the user properties --> <property name="USER_PROPERTIES" value="${user.home}/jwsnutExamples.properties"/> <property name="USER_JAXR_PROPERTIES" value="${user.home}/jwsnutJaxrExamples.properties"/>

<!-- Import properties from the environment --> <property environment="env"/> <property name="JAXRPC_HOME" value="${env.JAXRPC_HOME}"/> <property name="JAXR_HOME" value="${env.JAXR_HOME}"/>

<property name="EXAMPLES_ROOT" value="D:/Downloads/examples_websevice_in_nutshell"/> <property name="J2EEROOT" value="C:/Documents and Settings/Administrator/glassfish"/>

<!-- Import the user settings for all examples --> <property file="${USER_PROPERTIES}"/>

<!-- Name of directory used for temporary deployment file --> <property name="TEMP_DEPLOY_DIR" value="${basedir}/temp_deploy"/>

<!-- These targets ensure that EXAMPLES_ROOT is set in jwsnutExamples.properties" --> <target name="sense" unless="config.done">     <available file="${EXAMPLES_ROOT}/application-skel.xml" property="config.done"/> </target> <target name="check" depends="sense, platform-check" unless="config.done">     <fail message="EXAMPLES_ROOT not set in jwsnutExamples.properties"/> </target>

<!-- Init tasks for JWSDP with Tomcat --> <target name="jwsdp-tomcat-prepare" depends="check" if="USING_JWSDP">     <echo>Target platform is JWSDP with Tomcat</echo>         <!-- Define the ant tasks for deployment to Tomcat -->     <taskdef name="deploy" classname="org.apache.catalina.ant.DeployTask" />     <taskdef name="undeploy" classname="org.apache.catalina.ant.UndeployTask" />

    <!-- Import properties for the Tomcat environment -->     <property file="../../common/tomcat_properties.properties"/>

    <!-- Import definitions for this project -->     <property file="example.properties"/>         <!-- Classpath uses JAR files from JWSDP install -->     <path id="basic.classpath">         <fileset dir="${WSROOT}" includes="**/*.jar"/>     </path>         <!-- Deployment source files for JAX-RPC examples -->     <property name="DEPLOYMENT_FILES" value="${basedir}/deploy"/> </target>

<!-- Init tasks for J2EE 1.4 --> <target name="j2ee14-prepare" depends="check" if="USING_J2EE14">     <echo>Target platform is J2EE 1.4 RI</echo>             <!-- Import properties for the J2EE 1.4 environment -->     <property file="../../common/j2ee14_properties.properties"/>

    <!-- Import definitions for this project -->     <property file="example.properties"/>         <!-- Classpath uses the J2EE runtime -->     <path id="basic.classpath">         <fileset dir="${J2EEROOT}/lib" includes="j2ee.jar"/>         <fileset dir="${J2EEROOT}/lib/endorsed" includes="**/*.jar"/>     </path>         <!-- Deployment source files for JAX-RPC examples -->     <property name="DEPLOYMENT_FILES" value="${basedir}/deploy-j2ee14"/>         </target>

<!-- Global setup task: switches to correct platform prepare task  --> <target name="prepare" depends="jwsdp-tomcat-prepare, j2ee14-prepare">     <available file="${basedir}/j2ee-ri" property="GOT_J2EERI"/> </target>

<!-- Clean up targets --> <!-- Cleans all .nbattrs files used by Forte as well as intermediates --> <target name="pub-clean" depends="clean">     <delete>         <fileset dir="${basedir}" includes="**/.nbattrs"/>         <fileset dir="${basedir}" includes="**/*~" defaultexcludes="no"/>     </delete> </target> 

<!-- Common cleanup --> <target name="clean-common">    <property file="${basedir}/example.properties"/>    <delete>         <fileset dir="${basedir}" includes="**/*.class"/>     </delete> </target>

deploy.xml

<!-- Defines the deployment targets, switching according to platform --> <!-- Note that projects that include this file are obliged to      provide a "portable-web-package" target that builds the deployable object -->     

<!-- Deploys the web application to the Tomcat web server --> <target name="tomcat-deploy" depends="web-package" if="USING_JWSDP">     <deploy url="${WEBMANAGER_URL}"             path="/${CONTEXT_PATH}"             war="file:${EXAMPLES_ROOT}/${THIS_EXAMPLE}/${WEB_ARCHIVE_NAME}"             username="${USERNAME}"             password="${PASSWORD}"/> </target>

<!-- Undeploys the web application from the Tomcat web server --> <target name="tomcat-undeploy" depends="prepare" if="USING_JWSDP">     <undeploy url="${WEBMANAGER_URL}"             path="/${CONTEXT_PATH}"             username="${USERNAME}"             password="${PASSWORD}"/> </target>

<!-- Helper target that copies and edits the sun-j2ee-ri.xml file --> <target name="handle-j2ee-ri" depends="prepare" if="GOT_J2EERI">     <mkdir dir="${TEMP_DEPLOY_DIR}"/>     <filter token="USER_NAME" value="${USERNAME}"/>     <copy todir="${TEMP_DEPLOY_DIR}" filtering="true">         <fileset dir="${basedir}/j2ee-ri">             <include name="sun-j2ee-ri.xml.template"/>         </fileset>         <mapper type="glob" from="*.template" to="*"/>     </copy> </target>

<!-- Deploys the web application in a J2EE 1.4 server --> <target name="j2ee14-deploy" depends="handle-j2ee-ri, web-package" if="USING_J2EE14">     <!-- Build the EAR file in a temporary directory -->     <mkdir dir="${TEMP_DEPLOY_DIR}"/>     <copy file="${EXAMPLES_ROOT}/application-skel.xml" tofile="${TEMP_DEPLOY_DIR}/application.xml"/>     <replace file="${TEMP_DEPLOY_DIR}/application.xml">         <replacefilter token="@SERVICE@" value="${CONTEXT_PATH}"/>     </replace>

    <!-- Build the EAR -->     <ear earfile="${TEMP_DEPLOY_DIR}/${CONTEXT_PATH}.ear"                 appxml="${TEMP_DEPLOY_DIR}/application.xml">         <fileset dir="." includes="${WEB_ARCHIVE_NAME}"/>         <metainf dir="${TEMP_DEPLOY_DIR}">             <include name="sun-j2ee-ri.xml"/>         </metainf>     </ear>

    <!-- Deploy the EAR -->     <exec executable="${J2EE_DEPLOYTOOL}" vmlauncher="no">         <arg line="-server ${TARGET_HOST} -deployModule -id ${CONTEXT_PATH} ${TEMP_DEPLOY_DIR}/${CONTEXT_PATH}.ear"/>     </exec>   

    <!-- Clean up -->     <delete dir="${TEMP_DEPLOY_DIR}"/> </target>

<!-- Undeploys the web application from a J2EE 1.4 server --> <target name="j2ee14-undeploy" depends="prepare" if="USING_J2EE14">     <exec executable="${J2EE_DEPLOYTOOL}" vmlauncher="no">         <arg line="-undeployModule ${CONTEXT_PATH} ${TARGET_HOST}"/>     </exec>    </target> 

<!-- Packaging a JAX-RPC service for deployment with Tomcat --> <target name="jaxrpc-tomcat-web-package" depends="portable-web-package" if="USING_JWSDP">     <exec executable="${WSDEPLOY}" vmlauncher="no">         <arg line="-o ${WEB_ARCHIVE_NAME} ${PORTABLE_WEB_ARCHIVE_NAME}"/>     </exec>  </target>

<!-- Packaging a JAX-RPC service for deployment with J2EE 1.4 --> <target name="jaxrpc-j2ee14-web-package" depends="portable-web-package" if="USING_J2EE14">     <!-- Nothing to do: deploytool does all the work. Just copy the file -->      <copy file="${PORTABLE_WEB_ARCHIVE_NAME}" tofile="${WEB_ARCHIVE_NAME}"/> </target>

<!-- Builds a deployable WAR for a JAX-RPC service --> <target name="jaxrpc-web-package" depends="jaxrpc-tomcat-web-package, jaxrpc-j2ee14-web-package"/>

<!-- These are the actual targets that the user sees --> <target name="deploy" description="Deploys a web service" depends="tomcat-deploy, j2ee14-deploy"/> <target name="undeploy" description="Undeploys a web service" depends="tomcat-undeploy, j2ee14-undeploy"/> <target name="redeploy" description="Redeploys a web service" depends="undeploy, deploy"/>

build.xml

<!DOCTYPE project [   <!ENTITY buildsetup SYSTEM "../../common/buildsetup.xml">   <!ENTITY deploy SYSTEM "../../common/deploy.xml"> ]>

<project name="BookService" basedir="." default="web-package">     <!-- Import common definitions and load properties -->     &buildsetup;     &deploy;

    <!-- LOCAL PROPERTIES -->

    <!-- Source directories -->     <property name="INTERFACE_SRC_DIR" value="${basedir}/interface"/>     <property name="SERVER_SRC_DIR" value="${basedir}/server"/>     <property name="CLIENT_SRC_DIR" value="${basedir}/client"/>  <property name="DEPLOYMENT_FILES" value="${basedir}/deploy"/>

    <!-- Output directories -->     <property name="OUTPUT_DIR" value="${basedir}/output"/>     <property name="INTERFACE_OUTPUT_DIR" value="${OUTPUT_DIR}/interface"/>     <property name="SERVER_OUTPUT_DIR" value="${OUTPUT_DIR}/server"/>     <property name="CLIENT_OUTPUT_DIR" value="${OUTPUT_DIR}/client"/>

    <!-- Directories for the generated code files -->     <property name="GENERATED_DIR" value="${basedir}/generated"/>     <property name="CLIENT_GENERATED_DIR" value="${GENERATED_DIR}/client"/>     <property name="SERVER_GENERATED_DIR" value="${GENERATED_DIR}/server"/>    <property file="example.properties"/>     <!-- Check that this example is appropriate for the current platform -->     <target name="platform-check">         <!-- Nothing to check -->     </target>

    <target name="init" depends="prepare">         <!-- Create the output directories -->         <mkdir dir="${INTERFACE_OUTPUT_DIR}"/>         <mkdir dir="${SERVER_OUTPUT_DIR}"/>         <mkdir dir="${CLIENT_OUTPUT_DIR}"/>

       <!-- Create the generated code directories -->        <mkdir dir="${CLIENT_GENERATED_DIR}"/>        <mkdir dir="${SERVER_GENERATED_DIR}"/>               <!-- Create the temporary deployment directory -->        <mkdir dir="${TEMP_DEPLOY_DIR}"/>

        <!-- Compilation class path -->         <path id="compile.path">             <!-- Required for access to JAX-RPC classes -->             <path refid="basic.classpath"/>             <fileset dir="${J2EEROOT}" includes="**/*.jar"/>             <!-- Required for access to interface definitions -->             <pathelement location="${INTERFACE_OUTPUT_DIR}"/>         </path>

        <!-- Client execution class path -->         <path id="run.path">             <!-- Required for access to JAX-RPC classes -->             <path refid="basic.classpath"/>

            <!-- Access to interface definition -->             <pathelement location="${INTERFACE_OUTPUT_DIR}"/>

            <!-- Access to stub files and client code -->             <pathelement location="${CLIENT_OUTPUT_DIR}"/>         </path>     </target>

    <!-- Compilation of the interface parts -->     <target name="compile-interface" depends="init">         <javac srcdir="${INTERFACE_SRC_DIR}" destdir="${INTERFACE_OUTPUT_DIR}" debug="true">             <classpath refid="compile.path"/>         </javac>     </target>

    <!-- Generate JAX-RPC classes for the client side -->     <target name="generate-client" depends="compile-interface">         <exec executable="wscompile.bat" vmlauncher="no">             <arg line="-gen:client -classpath ${INTERFACE_OUTPUT_DIR}"/>             <arg line="-keep -s ${CLIENT_GENERATED_DIR}"/>             <arg line="-d ${CLIENT_OUTPUT_DIR} ${CONFIG_FILE}"/>         </exec>        </target>         <!-- Compilation of the server part -->     <target name="compile-server" depends="compile-interface">         <javac srcdir="${SERVER_SRC_DIR}" destdir="${SERVER_OUTPUT_DIR}" debug="true">             <classpath refid="compile.path"/>         </javac>

        <!-- Include resource files from the server source tree -->         <copy todir="${SERVER_OUTPUT_DIR}">             <fileset dir="${SERVER_SRC_DIR}">                 <exclude name="**/*.java"/>             </fileset>         </copy>                 <!-- Generate the WSDL file -->         <exec  executable="wscompile.bat" vmlauncher="no">             <arg line="-define -classpath ${INTERFACE_OUTPUT_DIR}"/>             <arg line="-model ${SERVER_OUTPUT_DIR}/model"/>             <arg line="-d ${SERVER_OUTPUT_DIR} ${CONFIG_FILE}"/>         </exec>     </target>

    <!-- Compilation of the client part -->     <target name="compile-client" description="Compiles the client" depends="generate-client">         <javac srcdir="${CLIENT_SRC_DIR}" destdir="${CLIENT_OUTPUT_DIR}" debug="true">             <classpath refid="compile.path"/>         </javac>     </target>

    <!-- Target that generates and compiles everything -->     <target name="compile" depends="compile-server, compile-client"/>

    <!-- Target that builds the portable WAR file -->     <target name="portable-web-package" depends="compile-server">         <!-- Copy deployment files -->         <copy todir="${TEMP_DEPLOY_DIR}">             <fileset dir="${DEPLOYMENT_FILES}"/>         </copy>                 <!-- Build the WAR file -->         <war warfile="${PORTABLE_WEB_ARCHIVE_NAME}" webxml="${TEMP_DEPLOY_DIR}/web.xml">

            <!-- Put the other required files into WEB-INF -->             <webinf dir="${TEMP_DEPLOY_DIR}">                 <exclude name="web.xml"/>             </webinf>             <webinf dir="${SERVER_OUTPUT_DIR}">                 <include name="model"/>             </webinf>

            <!-- The remaining files appear under "classes" -->             <!-- Include the compiled interface files -->             <classes dir="${INTERFACE_OUTPUT_DIR}"/>

            <!-- Include the server output files -->             <classes dir="${SERVER_OUTPUT_DIR}">                 <!-- WSDL and model files should not be copied into classes -->                 <exclude name="*.wsdl"/>                 <exclude name="model"/>             </classes>                         <!-- Copy the WSDL file to the root, but only for J2EE 1.4 -->             <fileset dir="${SERVER_OUTPUT_DIR}">                 <include name="*.wsdl" if="USING_J2EE14"/>             </fileset>         </war>                 <!-- Clean up the deployment directory -->         <delete>             <fileset dir="${TEMP_DEPLOY_DIR}" includes="**/*"/>         </delete>     </target>         <!-- Target that builds the deployable file -->     <target name="web-package" description="Builds the deployable object" depends="jaxrpc-web-package"/>

    <!-- Executes the client test -->     <target name="run-client" description="Runs the client" depends="init">         <java classname="${CLIENT_CLASS_NAME}" fork="yes">             <sysproperty key="http.proxyHost" value="${HTTP_PROXY_SERVER}"/>             <sysproperty key="http.proxyPort" value="${HTTP_PROXY_PORT}"/>             <sysproperty key="https.proxyHost" value="${HTTPS_PROXY_SERVER}"/>             <sysproperty key="https.proxyPort" value="${HTTPS_PROXY_PORT}"/>             <arg line="${CLIENT_ARGS}"/>             <classpath refid="run.path"/>         </java>     </target>          <!-- Executes the bookmap client test -->     <target name="run-client-bookmap" description="Runs the book map client" depends="init">         <java classname="${BOOKMAP_CLIENT_CLASS_NAME}" fork="yes">             <sysproperty key="http.proxyHost" value="${HTTP_PROXY_SERVER}"/>             <sysproperty key="http.proxyPort" value="${HTTP_PROXY_PORT}"/>             <sysproperty key="https.proxyHost" value="${HTTPS_PROXY_SERVER}"/>             <sysproperty key="https.proxyPort" value="${HTTPS_PROXY_PORT}"/>             <arg line="${CLIENT_ARGS}"/>             <classpath refid="run.path"/>         </java>     </target>

    <!-- Cleans up by removing all intermediate files and outputs -->     <target name="clean" description="Deletes all build objects" depends="clean-common">         <delete dir="${OUTPUT_DIR}"/>         <delete dir="${GENERATED_DIR}"/>         <delete dir="${TEMP_DEPLOY_DIR}"/>         <delete file="${WEB_ARCHIVE_NAME}"/>         <delete file="${PORTABLE_WEB_ARCHIVE_NAME}"/>     </target> </project>

部署文件:

mapping.xml

<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE java-wsdl-mapping PUBLIC     "-//IBM Corporation, Inc.//DTD J2EE JAX-RPC mapping 1.0//EN"     "http://www.ibm.com/standards/xml/webservices/j2ee/j2ee_jaxrpc_mapping_1_0.dtd"> <java-wsdl-mapping>     <package-mapping>         <package-type>ora.jwsnut.chapter2.bookservice</package-type>         <namespaceURI>urn:jwsnut.chapter2.bookservice/wsdl/BookQuery</namespaceURI>     </package-mapping>     <package-mapping>         <package-type>ora.jwsnut.chapter2.bookservice</package-type>         <namespaceURI>urn:jwsnut.chapter2.bookservice/types/BookQuery</namespaceURI>     </package-mapping>    </java-wsdl-mapping>

web.xml

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE web-app     PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"     "http://java.sun.com/j2ee/dtds/web-app_2_3.dtd">

<web-app>   <display-name>JAX-RPC Book Service</display-name>   <description>JAX-RPC Book Service</description>   <servlet>     <servlet-name>BookQueryServlet</servlet-name>     <servlet-class>ora.jwsnut.chapter2.bookservice.BookServiceServant</servlet-class>     <load-on-startup>0</load-on-startup>   </servlet>   <servlet-mapping>     <servlet-name>BookQueryServlet</servlet-name>     <url-pattern>/BookQuery</url-pattern>   </servlet-mapping>   <session-config>     <session-timeout>60</session-timeout>   </session-config> </web-app>

webservices.xml

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE webservices PUBLIC "-//IBM Corporation, Inc.//DTD J2EE Web services 1.0//EN"          "http://www.ibm.com/standards/xml/webservices/j2ee/j2ee_web_services_1_0.dtd">          <webservices>   <webservice-description>     <webservice-description-name>JAX-RPC Book Service</webservice-description-name>     <wsdl-file>BookService.wsdl</wsdl-file>     <!-- Use a model file for mapping as a J2EE 1.4 beta workaround -->     <jaxrpc-mapping-file>WEB-INF/model</jaxrpc-mapping-file>     <port-component>       <port-component-name>BookQueryPort</port-component-name>       <wsdl-port>         <namespaceURI>urn:jwsnut.chapter2.bookservice/wsdl/BookQuery</namespaceURI>         <localpart>BookQueryPort</localpart>       </wsdl-port>       <service-endpoint-interface>ora.jwsnut.chapter2.bookservice.BookQuery</service-endpoint-interface>       <service-impl-bean>         <servlet-link>BookQueryServlet</servlet-link>       </service-impl-bean>     </port-component>   </webservice-description> </webservices>

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值