Skip to content
Snippets Groups Projects
Commit 8f571707 authored by Terry D. Norbraten's avatar Terry D. Norbraten
Browse files

[Terry N.] restore McGregor's XML RPC servlet demo

parent 162a370a
No related branches found
No related tags found
No related merge requests found
Showing
with 1934 additions and 7 deletions
......@@ -40,18 +40,30 @@
</target>
<target name="-deploy-ant" if="deploy.ant.enabled" depends="-init,-check-credentials">
<echo message="Deploying ${deploy.ant.archive} to ${Context(path)}"/>
<taskdef name="deploy" classname="org.apache.catalina.ant.DeployTask"
classpath="${tomcat.home}/server/lib/catalina-ant.jar"/>
<deploy url="${tomcat.url}/manager" username="${tomcat.username}"
<taskdef name="deploy" classname="org.apache.catalina.ant.DeployTask">
<classpath>
<pathelement path="${tomcat.home}/lib/catalina-ant.jar"/>
<pathelement path="${tomcat.home}/lib/tomcat-coyote.jar"/>
<pathelement path="${tomcat.home}/lib/tomcat-util.jar"/>
<pathelement path="${tomcat.home}/bin/tomcat-juli.jar"/>
</classpath>
</taskdef>
<deploy url="${tomcat.url}/manager/text" username="${tomcat.username}"
password="${tomcat.password}" path="${Context(path)}"
war="${deploy.ant.archive}"/>
<property name="deploy.ant.client.url" value="${tomcat.url}${Context(path)}"/>
</target>
<target name="-undeploy-ant" if="deploy.ant.enabled" depends="-init,-check-credentials">
<echo message="Undeploying ${Context(path)}"/>
<taskdef name="undeploy" classname="org.apache.catalina.ant.UndeployTask"
classpath="${tomcat.home}/server/lib/catalina-ant.jar"/>
<undeploy url="${tomcat.url}/manager" username="${tomcat.username}"
<taskdef name="undeploy" classname="org.apache.catalina.ant.UndeployTask">
<classpath>
<pathelement path="${tomcat.home}/lib/catalina-ant.jar"/>
<pathelement path="${tomcat.home}/lib/tomcat-coyote.jar"/>
<pathelement path="${tomcat.home}/lib/tomcat-util.jar"/>
<pathelement path="${tomcat.home}/bin/tomcat-juli.jar"/>
</classpath>
</taskdef>
<undeploy url="${tomcat.url}/manager/text" username="${tomcat.username}"
password="${tomcat.password}" path="${Context(path)}"/>
</target>
</project>
This diff is collapsed.
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
nbproject/build-impl.xml.data.CRC32=cae571ac
nbproject/build-impl.xml.script.CRC32=110e0988
nbproject/build-impl.xml.stylesheet.CRC32=334708a0@1.98.0.1
......@@ -33,7 +33,7 @@ j2ee.compile.on.save=true
j2ee.copy.static.files.on.save=true
j2ee.deploy.on.save=true
j2ee.platform=1.7-web
j2ee.platform.classpath=${j2ee.server.home}/lib/annotations-api.jar:${j2ee.server.home}/lib/catalina-ant.jar:${j2ee.server.home}/lib/catalina-ha.jar:${j2ee.server.home}/lib/catalina-ssi.jar:${j2ee.server.home}/lib/catalina-storeconfig.jar:${j2ee.server.home}/lib/catalina-tribes.jar:${j2ee.server.home}/lib/catalina.jar:${j2ee.server.home}/lib/ecj-4.20.jar:${j2ee.server.home}/lib/el-api.jar:${j2ee.server.home}/lib/jasper-el.jar:${j2ee.server.home}/lib/jasper.jar:${j2ee.server.home}/lib/jaspic-api.jar:${j2ee.server.home}/lib/jsp-api.jar:${j2ee.server.home}/lib/servlet-api.jar:${j2ee.server.home}/lib/tomcat-api.jar:${j2ee.server.home}/lib/tomcat-coyote.jar:${j2ee.server.home}/lib/tomcat-dbcp.jar:${j2ee.server.home}/lib/tomcat-i18n-cs.jar:${j2ee.server.home}/lib/tomcat-i18n-de.jar:${j2ee.server.home}/lib/tomcat-i18n-es.jar:${j2ee.server.home}/lib/tomcat-i18n-fr.jar:${j2ee.server.home}/lib/tomcat-i18n-ja.jar:${j2ee.server.home}/lib/tomcat-i18n-ko.jar:${j2ee.server.home}/lib/tomcat-i18n-pt-BR.jar:${j2ee.server.home}/lib/tomcat-i18n-ru.jar:${j2ee.server.home}/lib/tomcat-i18n-zh-CN.jar:${j2ee.server.home}/lib/tomcat-jdbc.jar:${j2ee.server.home}/lib/tomcat-jni.jar:${j2ee.server.home}/lib/tomcat-util-scan.jar:${j2ee.server.home}/lib/tomcat-util.jar:${j2ee.server.home}/lib/tomcat-websocket.jar:${j2ee.server.home}/lib/websocket-api.jar
j2ee.platform.classpath=${j2ee.server.home}/bin/tomcat-juli.jar:${j2ee.server.home}/lib/annotations-api.jar:${j2ee.server.home}/lib/catalina-ant.jar:${j2ee.server.home}/lib/catalina-ha.jar:${j2ee.server.home}/lib/catalina-ssi.jar:${j2ee.server.home}/lib/catalina-storeconfig.jar:${j2ee.server.home}/lib/catalina-tribes.jar:${j2ee.server.home}/lib/catalina.jar:${j2ee.server.home}/lib/ecj-4.20.jar:${j2ee.server.home}/lib/el-api.jar:${j2ee.server.home}/lib/jasper-el.jar:${j2ee.server.home}/lib/jasper.jar:${j2ee.server.home}/lib/jaspic-api.jar:${j2ee.server.home}/lib/jsp-api.jar:${j2ee.server.home}/lib/servlet-api.jar:${j2ee.server.home}/lib/tomcat-api.jar:${j2ee.server.home}/lib/tomcat-coyote-ffm.jar:${j2ee.server.home}/lib/tomcat-coyote.jar:${j2ee.server.home}/lib/tomcat-dbcp.jar:${j2ee.server.home}/lib/tomcat-i18n-cs.jar:${j2ee.server.home}/lib/tomcat-i18n-de.jar:${j2ee.server.home}/lib/tomcat-i18n-es.jar:${j2ee.server.home}/lib/tomcat-i18n-fr.jar:${j2ee.server.home}/lib/tomcat-i18n-ja.jar:${j2ee.server.home}/lib/tomcat-i18n-ko.jar:${j2ee.server.home}/lib/tomcat-i18n-pt-BR.jar:${j2ee.server.home}/lib/tomcat-i18n-ru.jar:${j2ee.server.home}/lib/tomcat-i18n-zh-CN.jar:${j2ee.server.home}/lib/tomcat-jdbc.jar:${j2ee.server.home}/lib/tomcat-jni.jar:${j2ee.server.home}/lib/tomcat-util-scan.jar:${j2ee.server.home}/lib/tomcat-util.jar:${j2ee.server.home}/lib/tomcat-websocket.jar:${j2ee.server.home}/lib/websocket-api.jar
j2ee.server.type=Tomcat
jar.compress=false
javac.classpath=
......
## Apache XML-RPC demo of performing a URL lookup
With the ant target "runLocallDemo" a Servlet will start and listen for a\
search query from a client. The handler for the search query is the\
SavageSearch class with a single mock look up method "search." This handler is\
registered via the "org.apache.xmlrpc.webserver.XmlRpcServlet.proerties" file\
with a single entry "SavageSearch=SavageSearch" key/value pair.
The client then launches making a connection to\
URL: http://localhost:8080/SavageSearch. A search query of (Savage, Harrier)\
is made with the Servlet which tasks the handler to perform the lookup with\
results:
Result 1 is [Ljava.lang.String; https://savage.nps.edu/Savage/AircraftFixedWing/AV8B-Harrier-UnitedStates/AV8bHarrier.x3d\
Result 2 is [Ljava.lang.String; https://savage.nps.edu/Savage/AircraftFixedWing/AV8B-Harrier-UnitedStates/TranslatedAv8bHarrier.x3d
Before launching the "runLocallDemo" ant target, open up wireshark and\
configure for packet capture on the loopback adapter.
Now launch and look for two packet captures of protocol: HTTP/XML where you can\
then select and expand the entries to view the actual XML methodCall contents.
Since the local RPC Server is still listening for requests, it will have to be\
forced to stop. You may see a benign output such as the following:
BUILD STOPPED (total time: 19 seconds)\
Java Result: 2147483647
# Deploying to a local Tomcat Server
This demo expects apache-tomcat-9.0.95. Point to that directory in the\
build.properties file for the "catalina.base" property
Manager roles need to be defined in ${catalina.base}/config/tomcat-users.xml so\
that the Catalina deploy/undeploy ant tasks work smoothly. Define as\
follows:
&lt;role rolename="manager-gui"/&gt;\
&lt;user username="tomcat" password="tomcat" roles="manager-script"/&gt;
Then, run the ant target "deployRunDemo"
Server log outputs can be viewed at ${catalina.base}/logs/catalina.out and in\
the /logs directory. Look for "xmlrcp.log.0" to see similar logging output.
To undeploy the web app and stop the local Tomcat server, run "undeployRpcDemo"
# Tomcat Manager properties
# replace catalina.base with a path to your local Tomcat directory
catalina.base=${user.home}/javaapis/Apache Software Foundation (ASF)/apache-tomcat-9.0.95
catalina.home=${catalina.base}
startup=startup.sh
shutdown=shutdown.sh
# WIN users will rename the above extentions to "bat"
tomcat.server=localhost
tomcat.port=8080
# Since Tomcat 7, note that the URL for the text interface has changed from "/manager" to "/manager/text".
mgr=http://${tomcat.server}:${tomcat.port}/manager/text
username=tomcat
password=tomcat
proj.name=${app.name}
context=/${proj.name}
dist.war=${dist}/${app.name}.war
<?xml version="1.0" encoding="UTF-8"?>
<project name="xmlrpc-demo" default="dist" basedir=".">
<property environment="env"/>
<property name="app.name" value="SavageSearch"/>
<property name="build" value="build"/>
<property name="dist" value="dist"/>
<property name="lib" value="lib"/>
<property name="src" value="src"/>
<property name="web" value="web"/>
<property name="logs" value="logs"/>
<property name="debug" value="yes"/>
<property name="deprecations" value="yes"/>
<property file="build.properties"/>
<import file="nbproject/ide-file-targets.xml"/>
<!--
========
TASKDEFs
========
-->
<import file="${catalina.base}/bin/catalina-tasks.xml"/>
<path id="compile.classpath">
<fileset dir="${lib}">
<include name="*.jar"/>
</fileset>
</path>
<path id="run.classpath">
<fileset id="cp" dir="${lib}">
<include name="*.jar"/>
</fileset>
<pathelement location="${build}/WEB-INF/classes"/>
</path>
<target name="env">
<echo message="catalina.home=${catalina.home}"/>
</target>
<target name="prepare" depends="env">
<mkdir dir="${build}"/>
<mkdir dir="${build}/WEB-INF"/>
<mkdir dir="${build}/WEB-INF/classes"/>
<!-- Copy static content of this web application -->
<copy todir="${build}" overwrite="yes">
<fileset dir="${web}">
<include name="*.css"/>
<include name="*.html"/>
<include name="*.jsp"/>
</fileset>
</copy>
<copy todir="${build}/WEB-INF" overwrite="yes">
<fileset dir="${web}/WEB-INF">
<include name="classes/**"/>
<include name="web.xml"/>
</fileset>
</copy>
<!-- supporting jars -->
<copy todir="${build}/WEB-INF/lib" overwrite="yes">
<fileset refid="cp"/>
</copy>
<mkdir dir="${dist}"/>
</target>
<target name="compile" depends="prepare" description="Compile Java sources">
<javac release="11"
srcdir="${src}"
destdir="${build}/WEB-INF/classes"
listfiles="yes"
debug="${debug}"
deprecation="${deprecations}"
includeantruntime="false"
classpathref="compile.classpath">
<compilerarg value="-Xlint:-options"/>
</javac>
<!-- Copy application resources -->
<copy todir="${build}/WEB-INF/classes">
<fileset dir="${src}">
<exclude name="*.java"/>
</fileset>
</copy>
</target>
<target name="dist" depends="compile" description="Create binary distribution">
<war destfile="${dist.war}" basedir="${build}"/>
</target>
<target name="runLocalDemo"
depends="clean,compile"
description="Run both the Server and Client locally">
<parallel>
<sequential>
<antcall target="runServer"/>
</sequential>
<sequential>
<sleep seconds="5"/>
<antcall target="runClient"/>
</sequential>
</parallel>
</target>
<target name="runServer">
<java classname="RpcServer" classpathref="run.classpath"/>
</target>
<target name="runClient">
<java classname="RpcClient" classpathref="run.classpath"/>
</target>
<target name="deployRunDemo"
depends="undeployRpcDemo,clean,dist"
description="Builds the web application starts a local Tomcat server and runs XML RPC demo">
<sequential>
<antcall target="start.tomcat"/>
<!-- Allow Tomcat to startup -->
<sleep seconds="2"/>
<deploy url="${mgr}"
username="${username}"
password="${password}"
path="${context}"
war="${basedir}/${dist.war}"/>
<!-- Allow deployment -->
<sleep seconds="2"/>
<antcall target="runClient"/>
</sequential>
</target>
<target name="start.tomcat">
<exec executable="${catalina.home}/bin/${startup}">
<env key="CATALINA_HOME" value="${catalina.home}"/>
</exec>
</target>
<target name="undeployRpcDemo"
description="Removes the web application and stops the local Tomcat server">
<sequential>
<undeploy url="${mgr}"
username="${username}"
password="${password}"
path="${context}"/>
<antcall target="stop.tomcat"/>
</sequential>
</target>
<target name="stop.tomcat">
<exec executable="${catalina.home}/bin/${shutdown}">
<env key="CATALINA_HOME" value="${catalina.home}"/>
</exec>
</target>
<target name="clean" description="Delete old build and dist directories">
<delete dir="${build}"/>
<delete dir="${dist}"/>
<delete dir="${logs}"/>
</target>
</project>
\ No newline at end of file
File added
File added
File added
File added
File added
File added
File added
File added
File added
<?xml version="1.0" encoding="UTF-8"?>
<project basedir=".." name="xmlrpc-demo-IDE">
<!-- TODO: edit the following target according to your needs -->
<!-- (more info: http://www.netbeans.org/kb/articles/freeform-config.html#runsingle) -->
<path id="cp">
<fileset dir="lib">
<include name="*.jar"/>
</fileset>
<pathelement location="build/WEB-INF/classes"/>
</path>
<target name="run-selected-file-in-src">
<ant antfile="build.xml" target="compile"/>
<fail unless="run.class">Must set property 'run.class'</fail>
<java classname="${run.class}"
classpathref="cp"
failonerror="true"
fork="true"/>
</target>
<!-- TODO: edit the following target according to your needs -->
<!-- (more info: http://www.netbeans.org/kb/articles/freeform-config.html#runsingle) -->
<target name="debug-selected-file-in-src">
<fail unless="debug.class">Must set property 'debug.class'</fail>
<ant antfile="build.xml" target="compile"/>
<nbjpdastart addressproperty="jpda.address" name="xmlrpc" transport="dt_socket">
<classpath refid="cp"/>
</nbjpdastart>
<java classname="${debug.class}"
classpathref="cp"
failonerror="true"
fork="true">
<jvmarg value="-agentlib:jdwp=transport=dt_socket,address=${jpda.address}"/>
</java>
</target>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<!-- netBeans attempts to force extra namespace declaration in each element.
Only parent elements <project>, <general-data>, <java-data> and <web-data>
elements need a namespace declaration. Had to manually erase unnecessary
entries (tdn 03 DEC 06) -->
<project xmlns="http://www.netbeans.org/ns/project/1">
<type>org.netbeans.modules.ant.freeform</type>
<configuration>
<general-data xmlns="http://www.netbeans.org/ns/freeform-project/1">
<!-- Do not use Project Properties customizer when editing this file manually. -->
<name>xmlrpc-demo</name>
<properties/>
<folders>
<source-folder>
<label>web</label>
<type>doc_root</type>
<location>web</location>
</source-folder>
<source-folder>
<label>WEB-INF</label>
<type>web_inf</type>
<location>web/WEB-INF</location>
</source-folder>
<source-folder>
<label>src</label>
<type>java</type>
<location>src</location>
</source-folder>
</folders>
<ide-actions>
<action name="build">
<target>compile</target>
</action>
<action name="clean">
<target>clean</target>
</action>
<action name="run">
<target>deployRunDemo</target>
</action>
<action name="rebuild">
<target>clean</target>
<target>compile</target>
</action>
<action name="run.single">
<script>nbproject/ide-file-targets.xml</script>
<target>run-selected-file-in-src</target>
<context>
<property>run.class</property>
<folder>src</folder>
<pattern>\.java$</pattern>
<format>java-name</format>
<arity>
<one-file-only/>
</arity>
</context>
</action>
<action name="debug.single">
<script>nbproject/ide-file-targets.xml</script>
<target>debug-selected-file-in-src</target>
<context>
<property>debug.class</property>
<folder>src</folder>
<pattern>\.java$</pattern>
<format>java-name</format>
<arity>
<one-file-only/>
</arity>
</context>
</action>
<action name="redeploy">
<target>deployRunDemo</target>
</action>
</ide-actions>
<export>
<type>folder</type>
<location>build</location>
<build-target>compile</build-target>
</export>
<view>
<items>
<source-folder style="tree">
<label>Web Pages</label>
<location>web</location>
</source-folder>
<source-folder style="tree">
<label>WEB-INF Content</label>
<location>web/WEB-INF</location>
</source-folder>
<source-folder style="packages">
<label>src</label>
<location>src</location>
</source-folder>
<source-file>
<location>build.xml</location>
</source-file>
</items>
<context-menu>
<ide-action name="build"/>
<ide-action name="rebuild"/>
<ide-action name="clean"/>
<ide-action name="run"/>
<ide-action name="redeploy"/>
</context-menu>
</view>
<subprojects/>
</general-data>
<java-data xmlns="http://www.netbeans.org/ns/freeform-project-java/5">
<compilation-unit>
<package-root>src</package-root>
<classpath mode="compile">lib/log4j-api-2.23.1.jar:lib/servlet-api.jar:lib/xmlrpc-client-3.1.3.jar:lib/xmlrpc-common-3.1.3.jar:lib/xmlrpc-server-3.1.3.jar</classpath>
<built-to>build</built-to>
<javadoc-built-to>docs</javadoc-built-to>
<source-level>11</source-level>
</compilation-unit>
</java-data>
<web-data xmlns="http://www.netbeans.org/ns/freeform-project-web/1">
<web-module>
<doc-root>web</doc-root>
<classpath/>
<context-path>/SavageSearch</context-path>
<j2ee-spec-level>1.4</j2ee-spec-level>
</web-module>
</web-data>
</configuration>
</project>
import java.net.*;
import org.apache.xmlrpc.client.XmlRpcClient;
import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
import org.apache.xmlrpc.XmlRpcException;
/**
* Simple example of an XML-RPC client that uses Apache XML-RPC 3.x to
* contact a server and call a method on it.
*
* Based on the Apache XML RPC client example: https://ws.apache.org/xmlrpc/client.html
*
* @author DMcG
*/
public class RpcClient {
public static void main(String args[]) {
Object[] results, params;
String[] names;
XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
XmlRpcClient client = new XmlRpcClient();
try {
// Set the configuration to talk to localhost. The servlet should be listening
// on localhost, with the url of "xmlrpc". This uses the default transport
// mechanism of java.net.HttpURLConnection. You can also configure other
// http transport mechanisms, such as XmlRpcCommonsTransportFactory, which
// is another HTTP transport with a different API but smaller memory footprint.
config.setServerURL(new URI("http://localhost:8080/SavageSearch").toURL());
System.out.println("created URL: http://localhost:8080/SavageSearch");
config.setEnabledForExtensions(true);
config.setContentLengthOptional(false);
config.setConnectionTimeout(60 * 1000);
config.setReplyTimeout(60 * 1000);
client.setConfig(config);
// Call the method by putting together an array of parameters and calling
// the client object. The client object automatically translates the
// array information and other data into the correct XML format.
// Parameters to the search() method call; the first argument is
// the database to be searched, the second is the term to be
// searched for in that database
params = new Object[] {"Savage", "Harrier"};
System.out.println("preparing search for: (Savage, Harrier)");
results = (Object[]) client.execute("SavageSearch.search", params);
names = new String[results.length];
for(int idx = 0; idx < results.length; idx++) {
names[idx] = (String) results[idx];
System.out.println("Result " + (idx+1) + " is " + names.getClass().getName() + " " + names[idx]);
}
} catch(XmlRpcException | MalformedURLException | URISyntaxException e) {
System.err.println(e);
} finally {
System.exit(0);
}
} // End main
}
import java.io.IOException;
import java.util.Date;
import javax.servlet.ServletException;
import org.apache.xmlrpc.XmlRpcException;
import org.apache.xmlrpc.server.PropertyHandlerMapping;
import org.apache.xmlrpc.server.XmlRpcServer;
import org.apache.xmlrpc.server.XmlRpcServerConfigImpl;
import org.apache.xmlrpc.webserver.ServletWebServer;
import org.apache.xmlrpc.webserver.WebServer;
import org.apache.xmlrpc.webserver.XmlRpcServlet;
/** Based on the Apache XML RPC server example: https://ws.apache.org/xmlrpc/server.html
*
* @author <a href="mailto:tdnorbra@nps.edu?subject=.RpcServer">Terry Norbraten, NPS MOVES</a>
*/
public class RpcServer {
static WebServer ws = null;
public static void main(String[] args) {
XmlRpcServer xmlRpcServer;
XmlRpcServerConfigImpl config;
XmlRpcServlet servlet = new XmlRpcServlet();
PropertyHandlerMapping mapping = new PropertyHandlerMapping();
try {
ws = new ServletWebServer(servlet, 8080);
xmlRpcServer = ws.getXmlRpcServer();
mapping.addHandler("SavageSearch", SavageSearch.class);
xmlRpcServer.setHandlerMapping(mapping);
config = (XmlRpcServerConfigImpl) xmlRpcServer.getConfig();
config.setEnabledForExtensions(true);
config.setContentLengthOptional(false);
config.setKeepAliveEnabled(false);
ws.start();
System.out.println(RpcServer.class.getName() + " started: " + new Date().toString());
} catch (XmlRpcException | IOException | ServletException ex) {
if (ws != null) {
ws.log(ex);
ws.shutdown();
} else
System.err.println(ex);
}
}
} // end class RpcServer
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment