You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by fh...@apache.org on 2020/10/05 18:54:36 UTC
[tomcat] branch 9.0.x updated: Improvements to native
(tomcat-embed-programmatic)
This is an automated email from the ASF dual-hosted git repository.
fhanik pushed a commit to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/9.0.x by this push:
new 6d04ef8 Improvements to native (tomcat-embed-programmatic)
6d04ef8 is described below
commit 6d04ef8952aad6ff07077c8497a7ecd89cf55759
Author: Filip Hanik <fh...@pivotal.io>
AuthorDate: Fri Oct 2 15:17:35 2020 -0700
Improvements to native (tomcat-embed-programmatic)
1. script to run the embedded-programmatic in JVM or native mode
2. enable one line logging in native image sample
3. add logging to sample native servlet
---
java/org/apache/catalina/startup/Tomcat.java | 7 ++-
res/graal/run-tomcat-native.sh | 63 ++++++++++++++++++++++
.../native-image/tomcat-reflection.json | 7 +++
.../apache/catalina/startup/EmbeddedTomcat.java | 10 +++-
4 files changed, 83 insertions(+), 4 deletions(-)
diff --git a/java/org/apache/catalina/startup/Tomcat.java b/java/org/apache/catalina/startup/Tomcat.java
index 88859e8..430a635 100644
--- a/java/org/apache/catalina/startup/Tomcat.java
+++ b/java/org/apache/catalina/startup/Tomcat.java
@@ -1162,8 +1162,11 @@ public class Tomcat {
if (event.getType().equals(Lifecycle.CONFIGURE_START_EVENT)) {
context.setConfigured(true);
- // Process annotations
- WebAnnotationSet.loadApplicationAnnotations(context);
+ // Process annotations when not running in a Graal image
+ // annotations require reflections and additional configuration
+ if (!JreCompat.isGraalAvailable()) {
+ WebAnnotationSet.loadApplicationAnnotations(context);
+ }
// LoginConfig is required to process @ServletSecurity
// annotations
diff --git a/res/graal/run-tomcat-native.sh b/res/graal/run-tomcat-native.sh
new file mode 100755
index 0000000..e136a01
--- /dev/null
+++ b/res/graal/run-tomcat-native.sh
@@ -0,0 +1,63 @@
+#!/bin/bash
+
+# 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.
+
+set -e
+
+CURDIR=`pwd`
+
+# resolve links - $0 may be a softlink
+PRG="$0"
+while [ -h "$PRG" ]; do
+ ls=`ls -ld "$PRG"`
+ link=`expr "$ls" : '.*-> \(.*\)$'`
+ if expr "$link" : '/.*' > /dev/null; then
+ PRG="$link"
+ else
+ PRG=`dirname "$PRG"`/"$link"
+ fi
+done
+
+# directory of this script
+PRGDIR=`dirname "$PRG"`
+PRGDIR=`cd "$PRGDIR" >/dev/null; pwd`
+
+if [ "$1" == "build" ]; then
+ $PRGDIR/build-tomcat-native-image.sh
+ shift
+fi
+
+echo "Script Directory: $PRGDIR"
+if [ "$1" == "jvm" ]; then
+ cd $PRGDIR/../..
+ if [ ! -f output/graal/tomcat-embedded-sample.jar ]; then
+ $PRGDIR/build-tomcat-native-image.sh
+ fi
+ cd $PRGDIR/../../output/graal
+ java -Dorg.graalvm.nativeimage.imagecode=true \
+ -cp ../embed/tomcat-embed-programmatic.jar:tomcat-embedded-sample.jar \
+ org.apache.catalina.startup.EmbeddedTomcat
+elif [ "$1" == "native" ]; then
+ if [ ! -f $PRGDIR/../../output/graal/tc-graal-image ]; then
+ $PRGDIR/build-tomcat-native-image.sh
+ fi
+ $PRGDIR/../../output/graal/tc-graal-image
+else
+ echo "Usage: run-tomcat-native.sh [build] jvm|native"
+ exit 1
+fi
+
+cd $CURDIR
\ No newline at end of file
diff --git a/res/graal/tomcat-embed-programmatic/native-image/tomcat-reflection.json b/res/graal/tomcat-embed-programmatic/native-image/tomcat-reflection.json
index 0d4f101..7eafd10 100644
--- a/res/graal/tomcat-embed-programmatic/native-image/tomcat-reflection.json
+++ b/res/graal/tomcat-embed-programmatic/native-image/tomcat-reflection.json
@@ -1,2 +1,9 @@
[
+ {
+ "name": "org.apache.juli.OneLineFormatter",
+ "allPublicMethods": true,
+ "allDeclaredFields":true,
+ "allDeclaredMethods":true,
+ "allDeclaredConstructors":true
+ }
]
diff --git a/test/org/apache/catalina/startup/EmbeddedTomcat.java b/test/org/apache/catalina/startup/EmbeddedTomcat.java
index 9338761..bf5820b 100644
--- a/test/org/apache/catalina/startup/EmbeddedTomcat.java
+++ b/test/org/apache/catalina/startup/EmbeddedTomcat.java
@@ -32,6 +32,7 @@ import org.junit.Ignore;
import org.apache.catalina.Context;
import org.apache.catalina.connector.Connector;
+import org.apache.juli.logging.Log;
import org.apache.juli.logging.LogFactory;
import org.apache.tomcat.util.scan.StandardJarScanFilter;
import org.apache.tomcat.util.scan.StandardJarScanner;
@@ -44,7 +45,8 @@ public class EmbeddedTomcat {
".handlers = java.util.logging.ConsoleHandler\n" +
"java.util.logging.ConsoleHandler.level = FINE\n" +
"java.util.logging.ConsoleHandler.formatter = org.apache.juli.OneLineFormatter\n" +
- "java.util.logging.ConsoleHandler.encoding = UTF-8\n";
+ "java.util.logging.ConsoleHandler.encoding = UTF-8\n" +
+ "org.apache.level = INFO";
try {
InputStream is = new ByteArrayInputStream(loggingConfig.getBytes(StandardCharsets.UTF_8));
LogManager.getLogManager().readConfiguration(is);
@@ -79,7 +81,7 @@ public class EmbeddedTomcat {
}
private static class CounterServlet extends HttpServlet {
-
+ Log log = LogFactory.getLog(CounterServlet.class);
private static final long serialVersionUID = 1L;
private AtomicInteger callCount = new AtomicInteger(0);
@@ -87,9 +89,13 @@ public class EmbeddedTomcat {
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
+ log.debug("Enter CounterServlet");
req.getSession(true);
resp.setContentType("text/plain");
resp.getWriter().print("OK: " + req.getRequestURL() + "[" + callCount.incrementAndGet()+ "]");
+ resp.flushBuffer();
+ log.debug("Exit CounterServlet");
+
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org