Commit a057298b authored by O'Reilly Media, Inc.'s avatar O'Reilly Media, Inc.
Browse files

Initial commit

parents
Loading
Loading
Loading
Loading

README.md

0 → 100644
+15 −0
Changes for README.md: 15 added lines, 0 removed lines.
Original line number Diff line number Diff line
## Example files for the title:  
  
# Tomcat: The Definitive Guide 2nd Edition, by Ian Darwin
  
[![Tomcat: The Definitive Guide 2nd Edition, by Ian Darwin](http://akamaicovers.oreilly.com/images/9780596101060/cat.gif)](https://www.safaribooksonline.com/library/view/title/9780596101060//)
  
The following applies to example files from material published by O’Reilly Media, Inc. Content from other publishers may include different rules of usage. Please refer to any additional usage rights explained in the actual example files or refer to the publisher’s website.
  
O'Reilly books are here to help you get your job done. In general, you may use the code in O'Reilly books in your programs and documentation. You do not need to contact us for permission unless you're reproducing a significant portion of the code. For example, writing a program that uses several chunks of code from our books does not require permission. Answering a question by citing our books and quoting example code does not require permission. On the other hand, selling or distributing a CD-ROM of examples from O'Reilly books does require permission. Incorporating a significant amount of example code from our books into your product's documentation does require permission.
  
We appreciate, but do not require, attribution. An attribution usually includes the title, author, publisher, and ISBN.
  
If you think your use of code examples falls outside fair use or the permission given here, feel free to contact us at <permissions@oreilly.com>.
  
Please note that the examples are not production code and have not been carefully testing. They are provided "as-is" and come with no warranty of any kind.

logo.png

0 → 100644
+3.58 KiB
Loading image diff...
+115 −0
Changes for tomcat-definitive-guide-2ed-examples/MulticastNode.java: 115 added lines, 0 removed lines.
Original line number Diff line number Diff line
import java.net.DatagramPacket;
import java.net.InetAddress;
import java.net.MulticastSocket;

/**
 * MulticastNode is a very simple program to test multicast.  It starts
 * up and joins the multicast group 228.0.0.4 on port 45564 (this is the
 * default address and port of Tomcat 6's Cluster group communications).
 * This program uses the first argument as a message to send into the
 * multicast group, and then spends the remainder of its time listening
 * for messages from other nodes and printing those messages to standard
 * output.
 */
public class MulticastNode {

    InetAddress group = null;
    MulticastSocket s = null;
    

    /**
     * Pass this program a string argument that it should send to the
     * multicast group.
     */
    public static void main(String[] args) {

        if (args.length > 0) {

            System.out.println("Sending message: " + args[0]);

            // Start up this MulticastNode
            MulticastNode node = new MulticastNode();

            // Send the message
            node.send(args[0]);

            // Listen in on the multicast group, and print all messages
            node.receive();

        } else {

            System.out.println("Need an argument string to send.");
            System.exit(1);

        }

    }


    /**
     * Construct a MulticastNode on group 228.0.0.4 and port 45564.
     */
    public MulticastNode() {

        try {

            group = InetAddress.getByName("228.0.0.4");
            s = new MulticastSocket(45564);
            s.joinGroup(group);

        } catch (Exception e) {

            e.printStackTrace();

        }
    }


    /**
     * Send a string message to the multicast group for all to see.
     *
     * @param msg the message string to send to the multicast group.
     */
    public void send(String msg) {

        try {

            DatagramPacket hi = new DatagramPacket(
                msg.getBytes(), msg.length(), group, 45564);
            s.send(hi);

        } catch (Exception e) {

            e.printStackTrace();

        }
    }


    /**
     * Loop forever, listening to the multicast group for messages sent
     * from other nodes as DatagramPackets.  When one comes in, print it
     * to standard output, then go back to listening again.
     */
    public void receive() {

        byte[] buf;

        // Loop forever
        while (true) {

            try {

                buf = new byte[1000];
                DatagramPacket recv = new DatagramPacket(buf, buf.length);
                s.receive(recv);
                System.out.println("Received: " + new String(buf));

            } catch (Exception e) {

                e.printStackTrace();

            }
        }
    }
}
 No newline at end of file
+3 −0
Changes for tomcat-definitive-guide-2ed-examples/ant-build-files/README.txt: 3 added lines, 0 removed lines.
Original line number Diff line number Diff line
This directory contains build files that are shown as examples in the book.
We can't name them all "build.xml", but when you're using them, you should
probably rename the build file "build.xml".
+89 −0
Changes for tomcat-definitive-guide-2ed-examples/ant-build-files/pre-compile-jsps.xml: 89 added lines, 0 removed lines.
Original line number Diff line number Diff line
<project name="pre-compile-jsps" default="compile-jsp-servlets">

  <!-- Private properties. -->
  <property name="webapp.dir" value="${basedir}/webapp-dir"/>
  <property name="tomcat.home" value="/opt/tomcat"/>
  <property name="jspc.pkg.prefix" value="com.mycompany"/>
  <property name="jspc.dir.prefix" value="com/mycompany"/>

  <!-- Compilation properties. -->
  <property name="debug" value="on"/>
  <property name="debuglevel" value="lines,vars,source"/>
  <property name="deprecation" value="on"/>
  <property name="encoding" value="ISO-8859-1"/>
  <property name="optimize" value="off"/>
  <property name="build.compiler" value="modern"/>
  <property name="source.version" value="1.5"/>

  <!-- Initialize Paths. -->
  <path id="jspc.classpath">
    <fileset dir="${tomcat.home}/bin"> 
      <include name="*.jar"/> 
    </fileset> 
    <fileset dir="${tomcat.home}/server/lib"> 
      <include name="*.jar"/> 
    </fileset> 
    <fileset dir="${tomcat.home}/common/i18n"> 
      <include name="*.jar"/> 
    </fileset> 
    <fileset dir="${tomcat.home}/common/lib"> 
      <include name="*.jar"/> 
    </fileset> 
    <fileset dir="${webapp.dir}/WEB-INF">
      <include name="lib/*.jar"/>
    </fileset>
    <pathelement location="${webapp.dir}/WEB-INF/classes"/>
    <pathelement location="${ant.home}/lib/ant.jar"/>
    <pathelement location="${java.home}/../lib/tools.jar"/>
  </path>
  <property name="jspc.classpath" refid="jspc.classpath"/>

  <!-- ========================================================== -->
  <!-- Generates Java source and a web.xml file from JSP files.   -->
  <!-- ========================================================== -->
  <target name="generate-jsp-java-src">
    <mkdir dir="${webapp.dir}/WEB-INF/jspc-src/${jspc.dir.prefix}"/>
    <taskdef classname="org.apache.jasper.JspC" name="jasper2">
      <classpath>
        <path refid="jspc.classpath"/>
      </classpath>
    </taskdef>
    <touch file="${webapp.dir}/WEB-INF/jspc-web.xml"/>
    <jasper2 uriroot="${webapp.dir}"
             package="${jspc.pkg.prefix}"
             webXmlFragment="${webapp.dir}/WEB-INF/jspc-web.xml"
             outputDir="${webapp.dir}/WEB-INF/jspc-src/${jspc.dir.prefix}"
             verbose="1"/>
  </target>

  <!-- ========================================================== -->
  <!-- Compiles (generates Java class files from) the JSP servlet -->
  <!-- source code that was generated by the JspC task.           -->
  <!-- ========================================================== -->
  <target name="compile-jsp-servlets" depends="generate-jsp-java-src">
    <mkdir dir="${webapp.dir}/WEB-INF/classes"/>
    <javac srcdir="${webapp.dir}/WEB-INF/jspc-src"
           destdir="${webapp.dir}/WEB-INF/classes"
           includes="**/*.java"
           debug="${debug}"
           debuglevel="${debuglevel}"
           deprecation="${deprecation}"
           encoding="${encoding}"
           optimize="${optimize}"
           source="${source.version}">
      <classpath>
        <path refid="jspc.classpath"/>
      </classpath>
    </javac>
  </target>

  <!-- ========================================================= -->
  <!-- Cleans any pre-compiled JSP source, classes, jspc-web.xml -->
  <!-- ========================================================= -->
  <target name="clean">
    <delete dir="${webapp.dir}/WEB-INF/jspc-src"/>
    <delete dir="${webapp.dir}/WEB-INF/classes/${jspc.dir.prefix}"/>
    <delete file="${webapp.dir}/WEB-INF/jspc-web.xml"/>
  </target>

</project>
Loading