[Bug 69164] Exception "java.lang.IllegalArgumentException", due to: The Unicode character [木] outside the permitted range of 0 to 255
https://bz.apache.org/bugzilla/show_bug.cgi?id=69164 --- Comment #5 from timothyjmills --- (In reply to Mark Thomas from comment #3) > See bug 66196 https://amongusgame.io Bug reports dealing with IllegalArgumentException in Tomcat are all related to handling Unicode characters in HTTP response headers. -- You are receiving this mail because: You are the assignee for the bug. - To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org
(tomcat) branch main updated: Add JSON formatter to JULI
This is an automated email from the ASF dual-hosted git repository. remm pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/tomcat.git The following commit(s) were added to refs/heads/main by this push: new 3de275e7eb Add JSON formatter to JULI 3de275e7eb is described below commit 3de275e7ebd2ec2c2dc8b0ff3c5c0ff0fb0d20c5 Author: remm AuthorDate: Sat Feb 8 14:30:00 2025 +0100 Add JSON formatter to JULI Generates one line JSON, similar to access log. --- java/org/apache/juli/JsonFormatter.java | 208 java/org/apache/juli/OneLineFormatter.java | 5 +- test/org/apache/juli/TestJsonFormatter.java | 59 webapps/docs/changelog.xml | 4 + 4 files changed, 275 insertions(+), 1 deletion(-) diff --git a/java/org/apache/juli/JsonFormatter.java b/java/org/apache/juli/JsonFormatter.java new file mode 100644 index 00..1ea14a01de --- /dev/null +++ b/java/org/apache/juli/JsonFormatter.java @@ -0,0 +1,208 @@ +/* + * 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.juli; + +import java.util.logging.LogRecord; + +/** + * Provides the same information as the one line format but using JSON formatting. + * All the information of the LogRecord is included as a one line JSON document, + * including the full stack trace of the associated exception if any. + * + * The LogRecord is mapped as attributes: + * + * time: the log record timestamp + * level: the log level + * thread: the current on which the log occurred + * class: the class from which the log originated + * method: the method from which the log originated + * message: the log message + * error: the message from an exception, if present + * trace: the full stack trace from an exception, if present, represented as an array of string + * (the message first, then one string per stack trace element prefixed by a string, + * then moving on to the cause exception if any) + * + */ +public class JsonFormatter extends OneLineFormatter { + +@Override +public String format(LogRecord record) { +StringBuilder sb = new StringBuilder(); +sb.append('{'); + +// Timestamp +sb.append("\"time\": \""); +addTimestamp(sb, record.getMillis()); +sb.append("\", "); + +// Severity +sb.append("\"level\": \""); +sb.append(record.getLevel().getLocalizedName()); +sb.append("\", "); + +// Thread +sb.append("\"thread\": \""); +final String threadName = Thread.currentThread().getName(); +if (threadName != null && threadName.startsWith(AsyncFileHandler.THREAD_PREFIX)) { +// If using the async handler can't get the thread name from the +// current thread. +sb.append(getThreadName(record.getLongThreadID())); +} else { +sb.append(threadName); +} +sb.append("\", "); + +// Source +sb.append("\"class\": \""); +sb.append(record.getSourceClassName()); +sb.append("\", "); +sb.append("\"method\": \""); +sb.append(record.getSourceMethodName()); +sb.append("\", "); + +// Message +sb.append("\"message\": \""); +sb.append(JSONFilter.escape(formatMessage(record))); + +Throwable t = record.getThrown(); +if (t != null) { +sb.append("\", "); + +// Error +sb.append("\"error\": \""); +sb.append(JSONFilter.escape(t.toString())); +sb.append("\", "); + +// Stack trace +sb.append("\"trace\": ["); +boolean first = true; +do { +if (!first) { +sb.append(','); +} else { +first = false; +} + sb.append('\"').append(JSONFilter.escape(t.toString())).append('\"'); +for (StackTraceElement element : t.getStackTrace()) { +sb.append(',').append('\"').append(' ').append(JSONFilter.escape(element.toString())).append('\"'); +} +t = t.getCause(); +} while (t != null); +
(tomcat) branch 11.0.x updated: Add JSON formatter to JULI
This is an automated email from the ASF dual-hosted git repository. remm pushed a commit to branch 11.0.x in repository https://gitbox.apache.org/repos/asf/tomcat.git The following commit(s) were added to refs/heads/11.0.x by this push: new 803ece9764 Add JSON formatter to JULI 803ece9764 is described below commit 803ece976440ef1fc0fd9204750cae826a758763 Author: remm AuthorDate: Sat Feb 8 14:30:00 2025 +0100 Add JSON formatter to JULI Generates one line JSON, similar to access log. --- java/org/apache/juli/JsonFormatter.java | 208 java/org/apache/juli/OneLineFormatter.java | 5 +- test/org/apache/juli/TestJsonFormatter.java | 59 webapps/docs/changelog.xml | 8 ++ 4 files changed, 279 insertions(+), 1 deletion(-) diff --git a/java/org/apache/juli/JsonFormatter.java b/java/org/apache/juli/JsonFormatter.java new file mode 100644 index 00..1ea14a01de --- /dev/null +++ b/java/org/apache/juli/JsonFormatter.java @@ -0,0 +1,208 @@ +/* + * 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.juli; + +import java.util.logging.LogRecord; + +/** + * Provides the same information as the one line format but using JSON formatting. + * All the information of the LogRecord is included as a one line JSON document, + * including the full stack trace of the associated exception if any. + * + * The LogRecord is mapped as attributes: + * + * time: the log record timestamp + * level: the log level + * thread: the current on which the log occurred + * class: the class from which the log originated + * method: the method from which the log originated + * message: the log message + * error: the message from an exception, if present + * trace: the full stack trace from an exception, if present, represented as an array of string + * (the message first, then one string per stack trace element prefixed by a string, + * then moving on to the cause exception if any) + * + */ +public class JsonFormatter extends OneLineFormatter { + +@Override +public String format(LogRecord record) { +StringBuilder sb = new StringBuilder(); +sb.append('{'); + +// Timestamp +sb.append("\"time\": \""); +addTimestamp(sb, record.getMillis()); +sb.append("\", "); + +// Severity +sb.append("\"level\": \""); +sb.append(record.getLevel().getLocalizedName()); +sb.append("\", "); + +// Thread +sb.append("\"thread\": \""); +final String threadName = Thread.currentThread().getName(); +if (threadName != null && threadName.startsWith(AsyncFileHandler.THREAD_PREFIX)) { +// If using the async handler can't get the thread name from the +// current thread. +sb.append(getThreadName(record.getLongThreadID())); +} else { +sb.append(threadName); +} +sb.append("\", "); + +// Source +sb.append("\"class\": \""); +sb.append(record.getSourceClassName()); +sb.append("\", "); +sb.append("\"method\": \""); +sb.append(record.getSourceMethodName()); +sb.append("\", "); + +// Message +sb.append("\"message\": \""); +sb.append(JSONFilter.escape(formatMessage(record))); + +Throwable t = record.getThrown(); +if (t != null) { +sb.append("\", "); + +// Error +sb.append("\"error\": \""); +sb.append(JSONFilter.escape(t.toString())); +sb.append("\", "); + +// Stack trace +sb.append("\"trace\": ["); +boolean first = true; +do { +if (!first) { +sb.append(','); +} else { +first = false; +} + sb.append('\"').append(JSONFilter.escape(t.toString())).append('\"'); +for (StackTraceElement element : t.getStackTrace()) { +sb.append(',').append('\"').append(' ').append(JSONFilter.escape(element.toString())).append('\"'); +} +t = t.getCause(); +} while (t != null);
(tomcat) branch 10.1.x updated: Add JSON formatter to JULI
This is an automated email from the ASF dual-hosted git repository. remm pushed a commit to branch 10.1.x in repository https://gitbox.apache.org/repos/asf/tomcat.git The following commit(s) were added to refs/heads/10.1.x by this push: new 1bad7b6021 Add JSON formatter to JULI 1bad7b6021 is described below commit 1bad7b60214d84c6244a6694679156da892ee607 Author: remm AuthorDate: Sat Feb 8 14:30:00 2025 +0100 Add JSON formatter to JULI Generates one line JSON, similar to access log. --- java/org/apache/juli/JsonFormatter.java | 208 java/org/apache/juli/OneLineFormatter.java | 5 +- test/org/apache/juli/TestJsonFormatter.java | 59 webapps/docs/changelog.xml | 8 ++ 4 files changed, 279 insertions(+), 1 deletion(-) diff --git a/java/org/apache/juli/JsonFormatter.java b/java/org/apache/juli/JsonFormatter.java new file mode 100644 index 00..b0ae7e9576 --- /dev/null +++ b/java/org/apache/juli/JsonFormatter.java @@ -0,0 +1,208 @@ +/* + * 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.juli; + +import java.util.logging.LogRecord; + +/** + * Provides the same information as the one line format but using JSON formatting. + * All the information of the LogRecord is included as a one line JSON document, + * including the full stack trace of the associated exception if any. + * + * The LogRecord is mapped as attributes: + * + * time: the log record timestamp + * level: the log level + * thread: the current on which the log occurred + * class: the class from which the log originated + * method: the method from which the log originated + * message: the log message + * error: the message from an exception, if present + * trace: the full stack trace from an exception, if present, represented as an array of string + * (the message first, then one string per stack trace element prefixed by a string, + * then moving on to the cause exception if any) + * + */ +public class JsonFormatter extends OneLineFormatter { + +@Override +public String format(LogRecord record) { +StringBuilder sb = new StringBuilder(); +sb.append('{'); + +// Timestamp +sb.append("\"time\": \""); +addTimestamp(sb, record.getMillis()); +sb.append("\", "); + +// Severity +sb.append("\"level\": \""); +sb.append(record.getLevel().getLocalizedName()); +sb.append("\", "); + +// Thread +sb.append("\"thread\": \""); +final String threadName = Thread.currentThread().getName(); +if (threadName != null && threadName.startsWith(AsyncFileHandler.THREAD_PREFIX)) { +// If using the async handler can't get the thread name from the +// current thread. +sb.append(getThreadName(record.getThreadID())); +} else { +sb.append(threadName); +} +sb.append("\", "); + +// Source +sb.append("\"class\": \""); +sb.append(record.getSourceClassName()); +sb.append("\", "); +sb.append("\"method\": \""); +sb.append(record.getSourceMethodName()); +sb.append("\", "); + +// Message +sb.append("\"message\": \""); +sb.append(JSONFilter.escape(formatMessage(record))); + +Throwable t = record.getThrown(); +if (t != null) { +sb.append("\", "); + +// Error +sb.append("\"error\": \""); +sb.append(JSONFilter.escape(t.toString())); +sb.append("\", "); + +// Stack trace +sb.append("\"trace\": ["); +boolean first = true; +do { +if (!first) { +sb.append(','); +} else { +first = false; +} + sb.append('\"').append(JSONFilter.escape(t.toString())).append('\"'); +for (StackTraceElement element : t.getStackTrace()) { +sb.append(',').append('\"').append(' ').append(JSONFilter.escape(element.toString())).append('\"'); +} +t = t.getCause(); +} while (t != null); +
(tomcat) branch 9.0.x updated: Add JSON formatter to JULI
This is an automated email from the ASF dual-hosted git repository. remm 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 ce4c29bc36 Add JSON formatter to JULI ce4c29bc36 is described below commit ce4c29bc3694e04fc50835fdb16216eb3331584a Author: remm AuthorDate: Sat Feb 8 14:30:00 2025 +0100 Add JSON formatter to JULI Generates one line JSON, similar to access log. --- java/org/apache/juli/JsonFormatter.java | 208 java/org/apache/juli/OneLineFormatter.java | 5 +- test/org/apache/juli/TestJsonFormatter.java | 59 webapps/docs/changelog.xml | 8 ++ 4 files changed, 279 insertions(+), 1 deletion(-) diff --git a/java/org/apache/juli/JsonFormatter.java b/java/org/apache/juli/JsonFormatter.java new file mode 100644 index 00..b0ae7e9576 --- /dev/null +++ b/java/org/apache/juli/JsonFormatter.java @@ -0,0 +1,208 @@ +/* + * 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.juli; + +import java.util.logging.LogRecord; + +/** + * Provides the same information as the one line format but using JSON formatting. + * All the information of the LogRecord is included as a one line JSON document, + * including the full stack trace of the associated exception if any. + * + * The LogRecord is mapped as attributes: + * + * time: the log record timestamp + * level: the log level + * thread: the current on which the log occurred + * class: the class from which the log originated + * method: the method from which the log originated + * message: the log message + * error: the message from an exception, if present + * trace: the full stack trace from an exception, if present, represented as an array of string + * (the message first, then one string per stack trace element prefixed by a string, + * then moving on to the cause exception if any) + * + */ +public class JsonFormatter extends OneLineFormatter { + +@Override +public String format(LogRecord record) { +StringBuilder sb = new StringBuilder(); +sb.append('{'); + +// Timestamp +sb.append("\"time\": \""); +addTimestamp(sb, record.getMillis()); +sb.append("\", "); + +// Severity +sb.append("\"level\": \""); +sb.append(record.getLevel().getLocalizedName()); +sb.append("\", "); + +// Thread +sb.append("\"thread\": \""); +final String threadName = Thread.currentThread().getName(); +if (threadName != null && threadName.startsWith(AsyncFileHandler.THREAD_PREFIX)) { +// If using the async handler can't get the thread name from the +// current thread. +sb.append(getThreadName(record.getThreadID())); +} else { +sb.append(threadName); +} +sb.append("\", "); + +// Source +sb.append("\"class\": \""); +sb.append(record.getSourceClassName()); +sb.append("\", "); +sb.append("\"method\": \""); +sb.append(record.getSourceMethodName()); +sb.append("\", "); + +// Message +sb.append("\"message\": \""); +sb.append(JSONFilter.escape(formatMessage(record))); + +Throwable t = record.getThrown(); +if (t != null) { +sb.append("\", "); + +// Error +sb.append("\"error\": \""); +sb.append(JSONFilter.escape(t.toString())); +sb.append("\", "); + +// Stack trace +sb.append("\"trace\": ["); +boolean first = true; +do { +if (!first) { +sb.append(','); +} else { +first = false; +} + sb.append('\"').append(JSONFilter.escape(t.toString())).append('\"'); +for (StackTraceElement element : t.getStackTrace()) { +sb.append(',').append('\"').append(' ').append(JSONFilter.escape(element.toString())).append('\"'); +} +t = t.getCause(); +} while (t != null); +