You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2022/06/15 09:34:42 UTC
[tomcat-native] branch main updated: Remove the examples since they depend on removed JNI API
This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat-native.git
The following commit(s) were added to refs/heads/main by this push:
new e8334bd46 Remove the examples since they depend on removed JNI API
e8334bd46 is described below
commit e8334bd46b160b471b4b86f1d57e909ddfc44d4a
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Wed Jun 15 10:34:37 2022 +0100
Remove the examples since they depend on removed JNI API
---
README.txt | 18 --
TODO.txt | 21 +-
build.xml | 81 ------
examples/mkcerts | 216 ---------------
examples/org/apache/tomcat/jni/Echo.java | 347 ------------------------
examples/org/apache/tomcat/jni/Echo.properties | 17 --
examples/org/apache/tomcat/jni/Local.properties | 23 --
examples/org/apache/tomcat/jni/LocalServer.java | 190 -------------
examples/org/apache/tomcat/jni/SSL.properties | 22 --
examples/org/apache/tomcat/jni/SSLServer.java | 245 -----------------
10 files changed, 1 insertion(+), 1179 deletions(-)
diff --git a/README.txt b/README.txt
index 8ba008fc5..e004aadb8 100644
--- a/README.txt
+++ b/README.txt
@@ -55,24 +55,6 @@ or overwrite it in a new file build.properties.
Now run "ant test".
-Running the examples
---------------------
-
-Before running the examples you may have to set LD_LIBRARY_PATH, something like
-LD_LIBRARY_PATH=/opt/SMAWoIS/openssl/lib; export LD_LIBRARY_PATH
-
-1) echo example:
- - Choose some free port in
- dist/classes/examples/org/apache/tomcat/jni/Echo.properties
- - run: ant run-echo
-
-2) ssl server example:
- - Change parameters in dist/classes/examples/org/apache/tomcat/jni/SSL.properties
- according to your needs. The certificate and key should be in
- dist/classes/examples.
- - run: ant run-ssl-server
-
-
Cryptographic Software Notice
-----------------------------
diff --git a/TODO.txt b/TODO.txt
index 36660a190..eb762c693 100644
--- a/TODO.txt
+++ b/TODO.txt
@@ -35,29 +35,10 @@ known attacks will not work even with old OpenSSL?
Should we add a remark about this topic to the docs?
-Java Tests and Examples
------------------------
-
-- "ant run-echo": what is the expected behaviour of this example.
- I couldn't get it to do something understandable.
- Document the example in the README.txt.
-
-- "ant run-ssl-server": Could't we include a test certificate in the
- distribution?
-
-- "ant run-ssl-server": What should the test produce, if run successfully?
- Document the example in the README.txt.
-
-- "ant run-local-server": Creates a unix socket "\\.\PIPE\test" in the
- examples directory, then waits. How is the test expected to work?
- And the file name doesn't seem to be appropriate for Unix.
- Document the example in the README.txt.
-
-
Java Classes Source Distribution
--------------------------------
-Check on how to handle the test and examples classes.
+Check on how to handle the test classes.
I think they have no other home.
diff --git a/build.xml b/build.xml
index 19da1f138..a055ef21a 100644
--- a/build.xml
+++ b/build.xml
@@ -51,7 +51,6 @@
<property name="docs.dest" value="${dist.root}/doc"/>
<property name="docs.dest.print" value="${dist.root}/doc/printable"/>
<property name="test.dir" value="${build.dest}/test"/>
- <property name="examples.dir" value="${build.dest}/examples"/>
<property name="tc.library.path" value="${basedir}/native/.libs"/>
@@ -74,12 +73,6 @@
<pathelement location="${hamcrest.jar}"/>
</path>
- <!-- Examples classpath -->
- <path id="examples.classpath">
- <pathelement location="${build.dest}/java"/>
- <pathelement location="${build.dest}/examples"/>
- </path>
-
<!-- =================================================================== -->
<!-- prints the environment -->
<!-- =================================================================== -->
@@ -330,78 +323,4 @@ limitations under the License.-->">
</junit>
</target>
- <!-- =================================================================== -->
- <!-- Compiles the examples directory -->
- <!-- =================================================================== -->
- <target name="compile-examples" depends="compile" description="Compile example Java classes">
- <mkdir dir="${build.dest}"/>
- <mkdir dir="${build.dest}/examples"/>
- <mkdir dir="${build.src}"/>
- <mkdir dir="${build.src}/examples"/>
- <tstamp>
- <format property="TODAY" pattern="MMM d yyyy" locale="en"/>
- <format property="TSTAMP" pattern="hh:mm:ss"/>
- </tstamp>
- <!-- Copy static resource files -->
- <filter token="VERSION" value="${version}"/>
- <filter token="VERSION_NUMBER" value="${version.number}"/>
- <filter token="VERSION_BUILT" value="${TODAY} ${TSTAMP}"/>
- <copy todir="${build.src}/examples" filtering="yes" encoding="ISO-8859-1">
- <fileset dir="${src.dir}/examples">
- <include name="**/*.java"/>
- <include name="**/*.xml"/>
- <include name="**/*.properties"/>
- </fileset>
- </copy>
- <javac srcdir="${build.src}/examples"
- destdir="${build.dest}/examples"
- source="${compile.source}"
- target="${compile.target}"
- debug="${compile.debug}"
- deprecation="${compile.deprecation}"
- optimize="${compile.optimize}"
- encoding="ISO-8859-1">
- <classpath refid="examples.classpath"/>
- </javac>
- <copy todir="${build.dest}/examples" filtering="yes" encoding="ISO-8859-1">
- <fileset dir="${build.src}/examples">
- <include name="**/*.xml"/>
- <include name="**/*.properties"/>
- </fileset>
- </copy>
- </target>
-
- <!-- =================================================================== -->
- <!-- executes the examples -->
- <!-- =================================================================== -->
- <target name="run-echo" depends="compile-examples" description="Run the Echo example">
- <echo message="Running Tomcat Native Echo example ..."/>
- <java dir="${examples.dir}" classname="org.apache.tomcat.jni.Echo"
- fork="yes" failonerror="${test.failonerror}">
- <classpath refid="examples.classpath"/>
- <env key="PATH" path="${tc.library.path}:${java.library.path}"/>
- <env key="Path" path="${tc.library.path}:${java.library.path}"/>
- <jvmarg value="-Djava.library.path=${tc.library.path}"/>
- </java>
- </target>
- <target name="run-ssl-server" depends="compile-examples" description="Run the SSL Server example">
- <echo message="Running Tomcat Native SSL Server example ..."/>
- <java dir="${examples.dir}" classname="org.apache.tomcat.jni.SSLServer"
- fork="yes" failonerror="${test.failonerror}">
- <env key="PATH" path="${tc.library.path}:${java.library.path}"/>
- <env key="Path" path="${tc.library.path}:${java.library.path}"/>
- <classpath refid="examples.classpath"/>
- <jvmarg value="-Djava.library.path=${tc.library.path}"/>
- </java>
- </target>
- <target name="run-local-server" depends="compile-examples" description="Run the Local Server example">
- <echo message="Running Tomcat Native Local Server example ..."/>
- <java dir="${examples.dir}" classname="org.apache.tomcat.jni.LocalServer"
- fork="yes" failonerror="${test.failonerror}">
- <classpath refid="examples.classpath"/>
- <env key="PATH" path="${tc.library.path}:${java.library.path}"/>
- <env key="Path" path="${tc.library.path}:${java.library.path}"/>
- <jvmarg value="-Djava.library.path=${tc.library.path}"/>
- </java>
- </target>
</project>
diff --git a/examples/mkcerts b/examples/mkcerts
deleted file mode 100644
index a611ca966..000000000
--- a/examples/mkcerts
+++ /dev/null
@@ -1,216 +0,0 @@
-#!/bin/sh
-#
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements. See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-#
-# This is the configuration file to treate the CA certificate of the
-# _DEMONSTRATION ONLY_ 'Coyote' Certificate Authority.
-# This CA is used to sign the localhost.crt and user.crt
-# because self-signed server certificates are not accepted by all browsers.
-# NEVER USE THIS CA YOURSELF FOR REAL LIFE! INSTEAD EITHER USE A PUBLICALLY
-# KNOWN CA OR CREATE YOUR OWN CA!
-
-if [ -z "$OPENSSL" ]; then OPENSSL=openssl; fi
-
-PASSPHRASE="pass:secret"
-# Encrypt all keys
-GENRSA="$OPENSSL genrsa -des3"
-# Uncomment for no key encryption
-# GENRSA="$OPENSSL genrsa"
-REQ="$OPENSSL req -new"
-CA="$OPENSSL ca"
-X509="$OPENSSL x509"
-
-$OPENSSL rand -out .rnd 8192
-$GENRSA -passout $PASSPHRASE -out ca.key -rand .rnd 1024
-
-cat >ca.cfg <<EOT
-[ ca ]
-default_ca = default_db
-[ default_db ]
-dir = .
-certs = .
-new_certs_dir = ca.certs
-database = ca.index
-serial = ca.serial
-RANDFILE = .rnd
-certificate = ca.crt
-private_key = ca.key
-default_days = 365
-default_crl_days = 30
-default_md = md5
-preserve = no
-name_opt = ca_default
-cert_opt = ca_default
-unique_subject = no
-[ server_policy ]
-countryName = supplied
-stateOrProvinceName = supplied
-localityName = supplied
-organizationName = supplied
-organizationalUnitName = supplied
-commonName = supplied
-emailAddress = supplied
-[ server_cert ]
-subjectKeyIdentifier = hash
-authorityKeyIdentifier = keyid:always
-extendedKeyUsage = serverAuth,clientAuth,msSGC,nsSGC
-basicConstraints = critical,CA:false
-[ user_policy ]
-commonName = supplied
-emailAddress = supplied
-[ user_cert ]
-subjectAltName = email:copy
-basicConstraints = critical,CA:false
-authorityKeyIdentifier = keyid:always
-extendedKeyUsage = clientAuth,emailProtection
-
-[ req ]
-default_bits = 1024
-default_keyfile = ca.key
-distinguished_name = default_ca
-x509_extensions = extensions
-string_mask = nombstr
-req_extensions = req_extensions
-input_password = secret
-output_password = secret
-[ default_ca ]
-countryName = Country Code
-countryName_value = US
-countryName_min = 2
-countryName_max = 2
-stateOrProvinceName = State Name
-stateOrProvinceName_value = Delaware
-localityName = Locality Name
-localityName_value = Wilmington
-organizationName = Organization Name
-organizationName_value = Apache Software Foundation
-organizationalUnitName = Organizational Unit Name
-organizationalUnitName_value = Apache Tomcat
-commonName = Common Name
-commonName_value = Apache Tomcat demo root CA
-commonName_max = 64
-emailAddress = Email Address
-emailAddress_value = coyote@tomcat.apache.org
-emailAddress_max = 40
-[ extensions ]
-subjectKeyIdentifier = hash
-authorityKeyIdentifier = keyid:always
-basicConstraints = critical,CA:true
-[ req_extensions ]
-nsCertType = objsign,email,server
-EOT
-
-$REQ -x509 -days 3650 -batch -config ca.cfg -key ca.key -out ca.crt
-
-# Create cabundle.crt that can be used for CAfile
-cat >cabundle.crt <<EOT
-Tomcat Demo Root CA
-=========================================
-`$X509 -noout -fingerprint -in ca.crt`
-PEM Data:
-`$X509 -in ca.crt`
-`$X509 -noout -text -in ca.crt`
-EOT
-
-$GENRSA -passout $PASSPHRASE -out localhost.key -rand .rnd 1024
-
-cat >localhost.cfg <<EOT
-[ req ]
-default_bits = 1024
-distinguished_name = localhost
-string_mask = nombstr
-req_extensions = extensions
-input_password = secret
-output_password = secret
-[ localhost ]
-countryName = Country Code
-countryName_value = US
-countryName_min = 2
-countryName_max = 2
-stateOrProvinceName = State Name
-stateOrProvinceName_value = Delaware
-localityName = Locality Name
-localityName_value = Wilmington
-organizationName = Organization Name
-organizationName_value = Apache Software Foundation
-organizationalUnitName = Organizational Unit Name
-organizationalUnitName_value = Apache Tomcat
-commonName = Common Name
-commonName_value = Apache Tomcat localhost secure demo server
-commonName_max = 64
-emailAddress = Email Address
-emailAddress_value = tomcat@localhost.edu
-emailAddress_max = 40
-[ extensions ]
-nsCertType = server
-basicConstraints = critical,CA:false
-EOT
-
-$REQ -passin $PASSPHRASE -batch -config localhost.cfg -key localhost.key -out localhost.csr
-rm -f localhost.cfg
-
-# make sure environment exists
-if [ ! -d ca.certs ]; then
- mkdir ca.certs
- echo '01' >ca.serial
- cp /dev/null ca.index
-fi
-
-$CA -passin $PASSPHRASE -batch -config ca.cfg -extensions server_cert -policy server_policy -out x.crt -infiles localhost.csr
-$X509 -in x.crt -out localhost.crt
-rm -f x.crt
-# Create PKCS12 localhost certificate
-$OPENSSL pkcs12 -export -passout $PASSPHRASE -passin $PASSPHRASE -in localhost.crt -inkey localhost.key -certfile ca.crt -out localhost.p12
-
-$GENRSA -passout $PASSPHRASE -out user.key -rand .rnd 1024
-
-cat >user.cfg <<EOT
-[ req ]
-default_bits = 1024
-distinguished_name = admin
-string_mask = nombstr
-req_extensions = extensions
-input_password = secret
-output_password = secret
-[ admin ]
-commonName = User Name
-commonName_value = Localhost Administrator
-commonName_max = 64
-emailAddress = Email Address
-emailAddress_value = admin@localhost.edu
-emailAddress_max = 40
-[ extensions ]
-nsCertType = client,email
-basicConstraints = critical,CA:false
-EOT
-
-$REQ -passin $PASSPHRASE -batch -config user.cfg -key user.key -out user.csr
-rm -f user.cfg
-$CA -passin $PASSPHRASE -batch -config ca.cfg -extensions user_cert -policy user_policy -out x.crt -infiles user.csr
-$X509 -in x.crt -out user.crt
-rm -f x.crt
-
-# $OPENSSL verify -CAfile ca.crt localhost.crt
-# $OPENSSL verify -CAfile ca.crt user.crt
-
-# Create PKCS12 user certificate
-$OPENSSL pkcs12 -export -passout $PASSPHRASE -passin $PASSPHRASE -in user.crt -inkey user.key -certfile ca.crt -out user.p12
-
-rm -f ca.cfg
-rm -f *.old
-rm -f ca.index.attr
-rm -f .rnd
diff --git a/examples/org/apache/tomcat/jni/Echo.java b/examples/org/apache/tomcat/jni/Echo.java
deleted file mode 100644
index 0a49608d8..000000000
--- a/examples/org/apache/tomcat/jni/Echo.java
+++ /dev/null
@@ -1,347 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.tomcat.jni;
-
-import java.io.InputStream;
-import java.util.Properties;
-
-/**
- * Echo server example
- *
- * @deprecated The scope of the APR/Native Library will be reduced in Tomcat
- * 10.1.x / Tomcat Native 2.x onwards to only include those
- * components required to provide OpenSSL integration with the NIO
- * and NIO2 connectors.
- */
-@Deprecated
-public class Echo {
-
- public static String echoEcho = null;
- public static String echoAddr = null;
- public static int echoPort = 0;
- public static int echoNmax = 0;
- public static int echoNrun = 0;
- public static long echoPool = 0;
-
- private static Poller echoPoller = null;
- private static Acceptor echoAcceptor = null;
-
- private static Object threadLock = new Object();
-
- static {
-
- try {
- InputStream is = Echo.class.getResourceAsStream
- ("/org/apache/tomcat/jni/Echo.properties");
- Properties props = new Properties();
- props.load(is);
- is.close();
- echoAddr = props.getProperty("echo.ip", "127.0.0.1");
- echoPort = Integer.decode(props.getProperty("echo.port", "8023")).intValue();
- echoNmax = Integer.decode(props.getProperty("echo.max", "1")).intValue();
- }
- catch (Throwable t) {
- // NO-OP
- }
- }
-
- /* Acceptor thread. Listens for new connections */
- private class Acceptor extends java.lang.Thread {
- private long serverSock = 0;
- private long inetAddress = 0;
- private long pool = 0;
- public Acceptor() throws Exception {
- try {
-
- pool = Pool.create(Echo.echoPool);
- System.out.println("Accepting: " + Echo.echoAddr + ":" +
- Echo.echoPort);
- inetAddress = Address.info(Echo.echoAddr, Socket.APR_INET,
- Echo.echoPort, 0,
- pool);
- serverSock = Socket.create(Socket.APR_INET, Socket.SOCK_STREAM,
- Socket.APR_PROTO_TCP, pool);
- long sa = Address.get(Socket.APR_LOCAL, serverSock);
- Sockaddr addr = new Sockaddr();
- if (Address.fill(addr, sa)) {
- System.out.println("Host: " + addr.hostname);
- System.out.println("Server: " + addr.servname);
- System.out.println("IP: " + Address.getip(sa) +
- ":" + addr.port);
- }
- int rc = Socket.bind(serverSock, inetAddress);
- if (rc != 0) {
- throw(new Exception("Can't create Acceptor: bind: " + Error.strerror(rc)));
- }
- Socket.listen(serverSock, 5);
- }
- catch( Exception ex ) {
- ex.printStackTrace();
- throw(new Exception("Can't create Acceptor"));
- }
- }
-
- @Override
- public void run() {
- int i = 0;
- try {
- while (true) {
- long clientSock = Socket.accept(serverSock);
- System.out.println("Accepted id: " + i);
-
- try {
- long sa = Address.get(Socket.APR_REMOTE, clientSock);
- Sockaddr raddr = new Sockaddr();
- if (Address.fill(raddr, sa)) {
- System.out.println("Remote Host: " + Address.getnameinfo(sa, 0));
- System.out.println("Remote IP: " + Address.getip(sa) +
- ":" + raddr.port);
- }
- sa = Address.get(Socket.APR_LOCAL, clientSock);
- Sockaddr laddr = new Sockaddr();
- if (Address.fill(laddr, sa)) {
- System.out.println("Local Host: " + laddr.hostname);
- System.out.println("Local Server: " + Address.getnameinfo(sa, 0));
- System.out.println("Local IP: " + Address.getip(sa) +
- ":" + laddr.port);
- }
-
- } catch (Exception e) {
- // Ignore
- e.printStackTrace();
- }
-
- Socket.timeoutSet(clientSock, 10000000);
- Worker worker = new Worker(clientSock, i++,
- this.getClass().getName());
- Echo.incThreads();
- worker.start();
- }
- }
- catch( Exception ex ) {
- ex.printStackTrace();
- }
- }
- }
-
- /* Poller thread. Listens for new recycled connections */
- private class Poller extends java.lang.Thread {
- private long serverPollset = 0;
- private long pool = 0;
- private int nsocks = 0;
- public Poller() {
- try {
-
- pool = Pool.create(Echo.echoPool);
- serverPollset = Poll.create(16, pool, 0, 10000000);
- }
- catch( Exception ex ) {
- ex.printStackTrace();
- }
- }
-
- public void add(long socket) {
- int rv = Poll.add(serverPollset, socket,
- Poll.APR_POLLIN);
- if (rv == Status.APR_SUCCESS) {
- System.out.println("Added worker to pollset");
- nsocks++;
- }
- }
-
- public void remove(long socket) {
- int rv = Poll.remove(serverPollset, socket);
- if (rv == Status.APR_SUCCESS) {
- nsocks--;
- System.out.println("Removed worker from pollset");
- }
- else {
- System.out.println("Failed removing worker from pollset");
- }
- }
-
- @Override
- public void run() {
- while (true) {
- try {
- if (nsocks < 1) {
- java.lang.Thread.sleep(1);
- continue;
- }
- /* Two times size then created pollset */
- long [] desc = new long[64];
- /* USe 1 second poll timeout */
- int rv = Poll.poll(serverPollset, 1000000, desc, false);
- if (rv > 0) {
- for (int n = 0; n < rv; n++) {
- long clientSock = desc[n*2+1];
- System.out.println("Poll flags " + desc[n*2]);
- remove(clientSock);
- Worker worker = new Worker(clientSock, n,
- this.getClass().getName());
- Echo.incThreads();
- worker.start();
- }
- }
- else {
- if (Status.APR_STATUS_IS_TIMEUP(-rv))
- System.out.println("Timeup");
- else {
- System.out.println("Error " + (-rv));
- }
- }
- }
- /* XXX: JFC quick hack
- catch(Error err ) {
- if (Status.APR_STATUS_IS_TIMEUP(err.getError())) {
- /0 TODO: deal with timeout 0/
- }
- else {
- err.printStackTrace();
- break;
- }
- }
- */
- catch( Exception ex ) {
- ex.printStackTrace();
- break;
- }
- }
- }
- }
-
- private class Worker extends java.lang.Thread {
- private int workerId = 0;
- private long clientSock = 0;
- private byte [] wellcomeMsg = null;
- public Worker(long clientSocket, int workerId, String from) {
- this.clientSock = clientSocket;
- this.workerId = workerId;
- wellcomeMsg = ("Echo server id: " + this.workerId + " from " +
- from + "\r\n").getBytes();
- }
-
- @Override
- public void run() {
- boolean doClose = false;
- try {
- Socket.send(clientSock, wellcomeMsg, 0, wellcomeMsg.length);
- /* Do a blocking read byte at a time */
- byte [] buf = new byte[1];
- while (Socket.recv(clientSock, buf, 0, 1) == 1) {
- if (buf[0] == '\n')
- break;
- else if (buf[0] == '!') {
- doClose = true;
- break;
- }
- }
- if (doClose) {
- try {
- byte [] msg = ("Bye from worker: " + workerId + "\r\n").getBytes();
- Socket.send(clientSock, msg, 0, msg.length);
- } catch(Exception e) { }
-
- Socket.close(clientSock);
- }
- else {
- try {
- byte [] msg = ("Recycling worker: " + workerId + "\r\n").getBytes();
- Socket.send(clientSock, msg, 0, msg.length);
- } catch(Exception e) { }
- /* Put the socket to the keep-alive poll */
- Echo.echoPoller.add(clientSock);
- }
- } catch (Exception e) {
- Socket.close(clientSock);
- e.printStackTrace();
- }
- Echo.decThreads();
- System.out.println("Worker: " + workerId + " finished");
- }
- }
-
- public Echo()
- {
- echoPool = Pool.create(0);
- try {
- echoAcceptor = new Acceptor();
- echoAcceptor.start();
- echoPoller = new Poller();
- echoPoller.start();
- } catch (Exception e) {
- e.printStackTrace();
- }
-
- }
-
- public static void incThreads() {
- synchronized(threadLock) {
- echoNrun++;
- }
- }
-
- public static void decThreads() {
- synchronized(threadLock) {
- echoNrun--;
- }
- }
-
- public static void main(String [] args) {
- try {
- Library.initialize(null);
- long [] inf = new long[16];
- System.out.println("Info ...");
- System.out.println(" Native " + Library.versionString());
- System.out.println(" APR " + Library.aprVersionString());
- OS.info(inf);
- System.out.println("OS Info ...");
- System.out.println(" Physical " + inf[0]);
- System.out.println(" Avail " + inf[1]);
- System.out.println(" Swap " + inf[2]);
- System.out.println(" Swap free " + inf[3]);
- System.out.println(" Shared " + inf[4]);
- System.out.println(" Buffers size " + inf[5]);
- System.out.println(" Load " + inf[6]);
-
- System.out.println(" Idle " + inf[7]);
- System.out.println(" Kernel " + inf[8]);
- System.out.println(" User " + inf[9]);
-
- System.out.println(" Proc creation " + inf[10]);
- System.out.println(" Proc kernel " + inf[11]);
- System.out.println(" Proc user " + inf[12]);
- System.out.println(" Curr working " + inf[13]);
- System.out.println(" Peak working " + inf[14]);
- System.out.println(" Page faults " + inf[15]);
-
- SSL.initialize(null);
- System.out.println("OpenSSL ...");
- System.out.println(" version " + SSL.versionString());
- System.out.println(" number " + SSL.version());
-
- System.out.println("Starting Native Echo server example on port " +
- echoAddr + ":" + echoPort);
- @SuppressWarnings("unused")
- Echo echo = new Echo();
- } catch (Exception e) {
- e.printStackTrace();
- }
-
- }
-}
diff --git a/examples/org/apache/tomcat/jni/Echo.properties b/examples/org/apache/tomcat/jni/Echo.properties
deleted file mode 100644
index 34d77279a..000000000
--- a/examples/org/apache/tomcat/jni/Echo.properties
+++ /dev/null
@@ -1,17 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements. See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-# Test port used for echo server
-echo.port=8023
diff --git a/examples/org/apache/tomcat/jni/Local.properties b/examples/org/apache/tomcat/jni/Local.properties
deleted file mode 100644
index 0551f982e..000000000
--- a/examples/org/apache/tomcat/jni/Local.properties
+++ /dev/null
@@ -1,23 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements. See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-# Local properties
-local.max=10
-
-# For NT Pipes use something like
-local.path=\\\\.\\PIPE\\test
-
-# For Unix Sockets use
-# local.path=/tmp/testsock
diff --git a/examples/org/apache/tomcat/jni/LocalServer.java b/examples/org/apache/tomcat/jni/LocalServer.java
deleted file mode 100644
index eb2bf4edb..000000000
--- a/examples/org/apache/tomcat/jni/LocalServer.java
+++ /dev/null
@@ -1,190 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.tomcat.jni;
-
-import java.io.InputStream;
-import java.util.Properties;
-
-/**
- * Local Socket server example
- *
- * @deprecated The scope of the APR/Native Library will be reduced in Tomcat
- * 10.1.x / Tomcat Native 2.x onwards to only include those
- * components required to provide OpenSSL integration with the NIO
- * and NIO2 connectors.
- */
-@Deprecated
-public class LocalServer {
-
- public static String serverAddr = null;
- public static int serverNmax = 0;
- public static int serverNrun = 0;
- public static long serverPool = 0;
-
- private static Acceptor serverAcceptor = null;
-
- private static Object threadLock = new Object();
-
- static {
-
- try {
- InputStream is = LocalServer.class.getResourceAsStream
- ("/org/apache/tomcat/jni/Local.properties");
- Properties props = new Properties();
- props.load(is);
- is.close();
- serverAddr = props.getProperty("local.path", null);
- serverNmax = Integer.decode(props.getProperty("local.max", "0")).intValue();
- }
- catch (Throwable t) {
- // NO-OP
- }
- }
-
- public LocalServer()
- {
- serverPool = Pool.create(0);
- try {
- serverAcceptor = new Acceptor();
- serverAcceptor.start();
-
- } catch (Exception e) {
- e.printStackTrace();
- }
-
- }
- public static void incThreads() {
- synchronized(threadLock) {
- serverNrun++;
- }
- }
-
- public static void decThreads() {
- synchronized(threadLock) {
- serverNrun--;
- }
- }
-
- /* Acceptor thread. Listens for new connections */
- private class Acceptor extends java.lang.Thread {
- private long serverSock = 0;
- private long inetAddress = 0;
- private long pool = 0;
- public Acceptor() throws Exception {
- try {
-
- pool = Pool.create(LocalServer.serverPool);
- System.out.println("Accepting: " + LocalServer.serverAddr);
- serverSock = Local.create(LocalServer.serverAddr, pool);
- int rc = Local.bind(serverSock, inetAddress);
- if (rc != 0) {
- throw(new Exception("Can't create Acceptor: bind: " + Error.strerror(rc)));
- }
- Local.listen(serverSock, LocalServer.serverNmax);
- }
- catch( Exception ex ) {
- ex.printStackTrace();
- throw(new Exception("Can't create Acceptor"));
- }
- }
-
- @Override
- public void run() {
- int i = 0;
- try {
- while (true) {
- long clientSock = Local.accept(serverSock);
- System.out.println("Accepted id: " + i);
-
- Socket.timeoutSet(clientSock, 10000000);
- Worker worker = new Worker(clientSock, i++,
- this.getClass().getName());
- LocalServer.incThreads();
- worker.start();
- }
- }
- catch( Exception ex ) {
- ex.printStackTrace();
- }
- }
- }
-
- private class Worker extends java.lang.Thread {
- private int workerId = 0;
- private long clientSock = 0;
- private byte [] wellcomeMsg = null;
-
- public Worker(long clientSocket, int workerId, String from) {
- this.clientSock = clientSocket;
- this.workerId = workerId;
- wellcomeMsg = ("LocalServer server id: " + this.workerId + " from " +
- from).getBytes();
- }
-
- @Override
- public void run() {
- boolean doClose = false;
- try {
- Socket.send(clientSock, wellcomeMsg, 0, wellcomeMsg.length);
- while (!doClose) {
- /* Do a blocking read byte at a time */
- byte [] buf = new byte[1];
- byte [] msg = new byte[256];
- int p = 0;
- while (Socket.recv(clientSock, buf, 0, 1) == 1) {
- if (buf[0] == '\n')
- break;
- else if (buf[0] == '!') {
- doClose = true;
- break;
- }
- if (p > 250)
- break;
- msg[p++] = buf[0];
- }
- if (doClose) {
- try {
- byte [] snd = ("Bye from worker: " + workerId).getBytes();
- Socket.send(clientSock, snd, 0, snd.length);
- } catch(Exception e) { }
-
- Socket.close(clientSock);
- }
- else
- Socket.send(clientSock, msg, 0, p);
- }
- } catch (Exception e) {
- Socket.destroy(clientSock);
- e.printStackTrace();
- }
- LocalServer.decThreads();
- System.out.println("Worker: " + workerId + " finished");
- }
- }
-
-
- public static void main(String [] args) {
- try {
- Library.initialize(null);
-
- @SuppressWarnings("unused")
- LocalServer server = new LocalServer();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
diff --git a/examples/org/apache/tomcat/jni/SSL.properties b/examples/org/apache/tomcat/jni/SSL.properties
deleted file mode 100644
index 1ecf411b6..000000000
--- a/examples/org/apache/tomcat/jni/SSL.properties
+++ /dev/null
@@ -1,22 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements. See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-# SSL Server and client properties
-server.port=4443
-server.cert=localhost.crt
-server.key=localhost.key
-server.password=secret
-server.ciphers=ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
-server.verify=none
\ No newline at end of file
diff --git a/examples/org/apache/tomcat/jni/SSLServer.java b/examples/org/apache/tomcat/jni/SSLServer.java
deleted file mode 100644
index 677a74414..000000000
--- a/examples/org/apache/tomcat/jni/SSLServer.java
+++ /dev/null
@@ -1,245 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.tomcat.jni;
-
-import java.io.InputStream;
-import java.util.Properties;
-
-/**
- * SSL Server server example
- *
- * @deprecated The scope of the APR/Native Library will be reduced in Tomcat
- * 10.1.x / Tomcat Native 2.x onwards to only include those
- * components required to provide OpenSSL integration with the NIO
- * and NIO2 connectors.
- */
-@Deprecated
-public class SSLServer {
-
- public static String serverAddr = null;
- public static int serverPort = 0;
- public static int serverNmax = 0;
- public static int serverNrun = 0;
- public static long serverCtx = 0;
- public static long serverPool = 0;
- public static String serverCert = null;
- public static String serverKey = null;
- public static String serverCiphers = null;
- public static String serverPassword = null;
- public static String serverCAFile = null;
-
- private static Acceptor serverAcceptor = null;
-
- private static Object threadLock = new Object();
-
- static {
-
- try {
- InputStream is = SSLServer.class.getResourceAsStream
- ("/org/apache/tomcat/jni/SSL.properties");
- Properties props = new Properties();
- props.load(is);
- is.close();
- serverAddr = props.getProperty("server.ip", "127.0.0.1");
- serverPort = Integer.decode(props.getProperty("server.port", "4443")).intValue();
- serverNmax = Integer.decode(props.getProperty("server.max", "1")).intValue();
- serverCert = props.getProperty("server.cert", "server.pem");
- serverKey = props.getProperty("server.key", null);
- serverCAFile = props.getProperty("server.cacertificate", null);
- serverCiphers = props.getProperty("server.ciphers", "ALL");
- serverPassword = props.getProperty("server.password", null);
- }
- catch (Throwable t) {
- // NO-OP
- }
- }
-
- public SSLServer()
- {
- serverPool = Pool.create(0);
- try {
- /* Create SSL Context, one for each Virtual Host */
- serverCtx = SSLContext.make(serverPool, SSL.SSL_PROTOCOL_SSLV2 | SSL.SSL_PROTOCOL_SSLV3, SSL.SSL_MODE_SERVER);
- /* List the ciphers that the client is permitted to negotiate. */
- SSLContext.setCipherSuite(serverCtx, serverCiphers);
- /* Load Server key and certificate */
- SSLContext.setCertificate(serverCtx, serverCert, serverKey, serverPassword, SSL.SSL_AIDX_RSA);
- SSLContext.setVerify(serverCtx, SSL.SSL_CVERIFY_NONE, 10);
- serverAcceptor = new Acceptor();
- serverAcceptor.start();
-
- } catch (Exception e) {
- e.printStackTrace();
- }
-
- }
- public static void incThreads() {
- synchronized(threadLock) {
- serverNrun++;
- }
- }
-
- public static void decThreads() {
- synchronized(threadLock) {
- serverNrun--;
- }
- }
-
- /* Acceptor thread. Listens for new connections */
- private class Acceptor extends java.lang.Thread {
- private long serverSock = 0;
- private long inetAddress = 0;
- private long pool = 0;
- public Acceptor() throws Exception {
- try {
-
- pool = Pool.create(SSLServer.serverPool);
- System.out.println("Accepting: " + SSLServer.serverAddr + ":" +
- SSLServer.serverPort);
- inetAddress = Address.info(SSLServer.serverAddr, Socket.APR_INET,
- SSLServer.serverPort, 0,
- pool);
- serverSock = Socket.create(Socket.APR_INET, Socket.SOCK_STREAM,
- Socket.APR_PROTO_TCP, pool);
- int rc = Socket.bind(serverSock, inetAddress);
- if (rc != 0) {
- throw(new Exception("Can't create Acceptor: bind: " + Error.strerror(rc)));
- }
- Socket.listen(serverSock, 5);
- }
- catch( Exception ex ) {
- ex.printStackTrace();
- throw(new Exception("Can't create Acceptor"));
- }
- }
-
- @Override
- public void run() {
- int i = 0;
- try {
- while (true) {
- long clientSock = Socket.accept(serverSock);
- System.out.println("Accepted id: " + i);
-
- try {
- long sa = Address.get(Socket.APR_REMOTE, clientSock);
- Sockaddr raddr = new Sockaddr();
- if (Address.fill(raddr, sa)) {
- System.out.println("Remote Host: " + Address.getnameinfo(sa, 0));
- System.out.println("Remote IP: " + Address.getip(sa) +
- ":" + raddr.port);
- }
- sa = Address.get(Socket.APR_LOCAL, clientSock);
- Sockaddr laddr = new Sockaddr();
- if (Address.fill(laddr, sa)) {
- System.out.println("Local Host: " + laddr.hostname);
- System.out.println("Local Server: " + Address.getnameinfo(sa, 0));
- System.out.println("Local IP: " + Address.getip(sa) +
- ":" + laddr.port);
- }
-
- } catch (Exception e) {
- // Ignore
- e.printStackTrace();
- }
-
- Socket.timeoutSet(clientSock, 10000000);
- SSLSocket.attach(SSLServer.serverCtx, clientSock);
- i = SSLSocket.handshake(clientSock);
- if (i == 0) {
-
- Worker worker = new Worker(clientSock, i++,
- this.getClass().getName());
- SSLServer.incThreads();
- worker.start();
-
- }
- else {
- System.out.println("Handshake error: " + SSL.getLastError());
- Socket.destroy(clientSock);
- }
- }
- }
- catch( Exception ex ) {
- ex.printStackTrace();
- }
- }
- }
-
- private class Worker extends java.lang.Thread {
- private int workerId = 0;
- private long clientSock = 0;
- private byte [] wellcomeMsg = null;
-
- public Worker(long clientSocket, int workerId, String from) {
- this.clientSock = clientSocket;
- this.workerId = workerId;
- wellcomeMsg = ("SSLServer server id: " + this.workerId + " from " +
- from + "\r\n").getBytes();
- }
-
- @Override
- public void run() {
- boolean doClose = false;
- try {
- Socket.send(clientSock, wellcomeMsg, 0, wellcomeMsg.length);
- while (!doClose) {
- /* Do a blocking read byte at a time */
- byte [] buf = new byte[1];
- int ret;
- ret = Socket.recv(clientSock, buf, 0, 1);
- if (ret != 1)
- throw(new Exception("Socket.recv failed"));
-
- if (buf[0] == '\n')
- continue;
- else if (buf[0] == '!') {
- doClose = true;
- }
- Socket.send(clientSock, buf, 0, 1);
-
- if (doClose) {
- try {
- byte [] msg = ("Bye from worker: " + workerId + "\r\n").getBytes();
- Socket.send(clientSock, msg, 0, msg.length);
- } catch(Exception e) { }
-
- Socket.close(clientSock);
- }
- }
- } catch (Exception e) {
- Socket.destroy(clientSock);
- e.printStackTrace();
- }
- Echo.decThreads();
- System.out.println("Worker: " + workerId + " finished");
- }
- }
-
-
- public static void main(String [] args) {
- try {
- Library.initialize(null);
- SSL.initialize(null);
-
- @SuppressWarnings("unused")
- SSLServer server = new SSLServer();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org