Update upstream source from tag 'upstream/2.1.5'
Update to upstream version '2.1.5'
with Debian dir 5fcad89009ba84b812245a11d7979548b75ff347
Markus Koschany
5 years ago
27 | 27 | <groupId>org.jboss.logmanager</groupId> |
28 | 28 | <artifactId>jboss-logmanager</artifactId> |
29 | 29 | <packaging>jar</packaging> |
30 | <version>2.1.4.Final</version> | |
30 | <version>2.1.5.Final</version> | |
31 | 31 | |
32 | 32 | <parent> |
33 | 33 | <groupId>org.jboss</groupId> |
46 | 46 | <properties> |
47 | 47 | <!-- Dependency versions --> |
48 | 48 | <version.javax.json>1.0</version.javax.json> |
49 | <version.org.byteman>4.0.3</version.org.byteman> | |
49 | <version.org.byteman>4.0.4</version.org.byteman> | |
50 | 50 | <version.org.glassfish.javax.json>1.0.4</version.org.glassfish.javax.json> |
51 | 51 | <version.org.jboss.modules.jboss-modules>1.7.0.Final</version.org.jboss.modules.jboss-modules> |
52 | 52 | <version.org.wildfly.common.wildfly-common>1.2.0.Final</version.org.wildfly.common.wildfly-common> |
53 | 53 | <version.junit.junit>4.12</version.junit.junit> |
54 | ||
55 | <!-- Plugin versions --> | |
56 | <version.org.jboss.apiviz.plugin>1.3.2.GA</version.org.jboss.apiviz.plugin> | |
57 | 54 | |
58 | 55 | <!-- Test properties --> |
59 | 56 | <org.jboss.test.address>127.0.0.1</org.jboss.test.address> |
296 | 293 | </plugin> |
297 | 294 | </plugins> |
298 | 295 | </build> |
299 | <reporting> | |
300 | <plugins> | |
301 | <plugin> | |
302 | <artifactId>maven-javadoc-plugin</artifactId> | |
303 | <configuration> | |
304 | <doclet>net.gleamynode.apiviz.APIviz</doclet> | |
305 | <docletArtifact> | |
306 | <groupId>org.jboss.apiviz</groupId> | |
307 | <artifactId>apiviz</artifactId> | |
308 | <version>${version.org.jboss.apiviz.plugin}</version> | |
309 | </docletArtifact> | |
310 | <doctitle>JBoss LogManager ${project.version}</doctitle> | |
311 | <header>JBoss LogManager ${project.version}</header> | |
312 | <footer>JBoss LogManager ${project.version}</footer> | |
313 | <bottom><![CDATA[<i>Copyright © 2017 JBoss, a division of Red Hat, Inc.</i>]]></bottom> | |
314 | <links> | |
315 | <link>http://docs.oracle.com/javase/8/docs/api/</link> | |
316 | </links> | |
317 | </configuration> | |
318 | </plugin> | |
319 | </plugins> | |
320 | </reporting> | |
321 | 296 | </project> |
109 | 109 | setSourceMethodName(original.getSourceMethodName()); |
110 | 110 | sourceFileName = original.sourceFileName; |
111 | 111 | sourceLineNumber = original.sourceLineNumber; |
112 | sourceModuleName = original.sourceModuleName; | |
113 | sourceModuleVersion = original.sourceModuleVersion; | |
112 | 114 | } |
113 | 115 | formatStyle = original.formatStyle; |
114 | 116 | mdcCopy = original.mdcCopy; |
110 | 110 | break; |
111 | 111 | } |
112 | 112 | case 'h': { |
113 | stepList.add(Formatters.hostnameFormatStep(leftJustify, minimumWidth, truncateBeginning, maximumWidth, argument == null ? "1" : argument)); | |
113 | stepList.add(Formatters.hostnameFormatStep(leftJustify, minimumWidth, truncateBeginning, maximumWidth, false)); | |
114 | 114 | break; |
115 | 115 | } |
116 | 116 | case 'H': { |
44 | 44 | /** |
45 | 45 | * Formatter utility methods. |
46 | 46 | */ |
47 | @SuppressWarnings({"WeakerAccess", "unused"}) | |
47 | 48 | public final class Formatters { |
48 | 49 | |
49 | 50 | public static final String THREAD_ID = "id"; |
50 | 51 | |
51 | 52 | private static final boolean DEFAULT_TRUNCATE_BEGINNING = false; |
52 | private static final String NEW_LINE = String.format("%n"); | |
53 | 53 | private static final Pattern PRECISION_INT_PATTERN = Pattern.compile("\\d+"); |
54 | 54 | |
55 | 55 | |
546 | 546 | * @return the format step |
547 | 547 | */ |
548 | 548 | public static FormatStep hostnameFormatStep(final boolean leftJustify, final int minimumWidth, final boolean truncateBeginning, final int maximumWidth, final boolean qualified) { |
549 | return hostnameFormatStep(leftJustify, minimumWidth, truncateBeginning, maximumWidth, qualified ? null : "1"); | |
549 | return qualified ? hostnameFormatStep(leftJustify, minimumWidth, truncateBeginning, maximumWidth, null) : new SegmentedFormatStep(leftJustify, minimumWidth, truncateBeginning, maximumWidth, null) { | |
550 | public String getSegmentedSubject(final ExtLogRecord record) { | |
551 | final String hostName = record.getHostName(); | |
552 | final int idx = hostName.indexOf('.'); | |
553 | return idx == -1 ? hostName :hostName.substring(0, idx); | |
554 | } | |
555 | }; | |
550 | 556 | } |
551 | 557 | |
552 | 558 | /** |
560 | 566 | * @return the format step |
561 | 567 | */ |
562 | 568 | public static FormatStep hostnameFormatStep(final boolean leftJustify, final int minimumWidth, final boolean truncateBeginning, final int maximumWidth, final String precision) { |
563 | return new SegmentedFormatStep(leftJustify, minimumWidth, truncateBeginning, maximumWidth, precision) { | |
569 | return new SegmentedFormatStep(leftJustify, minimumWidth, truncateBeginning, maximumWidth, null) { | |
564 | 570 | public String getSegmentedSubject(final ExtLogRecord record) { |
565 | return record.getHostName(); | |
571 | final String hostName = record.getHostName(); | |
572 | // Check for a specified precision. This is not passed to the constructor because we want truncate | |
573 | // segments from the right intsead of the left. | |
574 | if (precision != null && PRECISION_INT_PATTERN.matcher(precision).matches()) { | |
575 | int count = Integer.parseInt(precision); | |
576 | int end = 0; | |
577 | for (int i = 0; i < hostName.length(); i++) { | |
578 | // If we've got a dot we're at a new segment | |
579 | if (hostName.charAt(i) == '.') { | |
580 | count--; | |
581 | end = i; | |
582 | } | |
583 | // We've reached the precision we want | |
584 | if (count == 0) { | |
585 | break; | |
586 | } | |
587 | } | |
588 | if (end != 0 && count == 0) { | |
589 | return hostName.substring(0, end); | |
590 | } | |
591 | } | |
592 | return hostName; | |
566 | 593 | } |
567 | 594 | }; |
568 | 595 | } |
24 | 24 | import java.io.UnsupportedEncodingException; |
25 | 25 | import java.io.Writer; |
26 | 26 | |
27 | import java.nio.charset.Charset; | |
27 | 28 | import java.util.logging.ErrorManager; |
28 | 29 | import java.util.logging.Formatter; |
29 | 30 | |
34 | 35 | public class OutputStreamHandler extends WriterHandler { |
35 | 36 | |
36 | 37 | private OutputStream outputStream; |
38 | private Charset charset; | |
37 | 39 | |
38 | 40 | /** |
39 | 41 | * Construct a new instance with no formatter. |
83 | 85 | public void setEncoding(final String encoding) throws SecurityException, UnsupportedEncodingException { |
84 | 86 | // superclass checks access |
85 | 87 | synchronized (outputLock) { |
88 | charset = encoding == null ? null : Charset.forName(encoding); | |
86 | 89 | super.setEncoding(encoding); |
87 | if (this.outputStream != null) { | |
88 | final OutputStream outputStream = this.outputStream; | |
89 | updateWriter(outputStream, encoding); | |
90 | } | |
90 | // we only want to change the writer, not the output stream | |
91 | final OutputStream outputStream = this.outputStream; | |
92 | if (outputStream != null) { | |
93 | super.setWriter(getNewWriter(outputStream)); | |
94 | } | |
91 | 95 | } |
92 | 96 | } |
93 | 97 | |
95 | 99 | public void setWriter(final Writer writer) { |
96 | 100 | synchronized (outputLock) { |
97 | 101 | super.setWriter(writer); |
102 | final OutputStream oldStream = this.outputStream; | |
98 | 103 | outputStream = null; |
104 | safeFlush(oldStream); | |
105 | safeClose(oldStream); | |
99 | 106 | } |
100 | 107 | } |
101 | 108 | |
102 | 109 | /** |
103 | * Set the output stream to write to. | |
110 | * Set the output stream to write to. The output stream will then belong to this handler; when the handler is | |
111 | * closed or a new writer or output stream is set, this output stream will be closed. | |
104 | 112 | * |
105 | 113 | * @param outputStream the new output stream or {@code null} for none |
106 | 114 | */ |
107 | 115 | public void setOutputStream(final OutputStream outputStream) { |
116 | if (outputStream == null) { | |
117 | // call ours, not the superclass one | |
118 | this.setWriter(null); | |
119 | return; | |
120 | } | |
108 | 121 | checkAccess(this); |
122 | // Close the writer, then close the old stream, then establish the new stream with a new writer. | |
109 | 123 | try { |
110 | 124 | synchronized (outputLock) { |
111 | this.outputStream = outputStream; | |
112 | updateWriter(outputStream, getEncoding()); | |
125 | final OutputStream oldStream = this.outputStream; | |
126 | // do not close the old stream if creating the writer fails | |
127 | final Writer writer = getNewWriter(outputStream); | |
128 | try { | |
129 | this.outputStream = outputStream; | |
130 | super.setWriter(writer); | |
131 | } finally { | |
132 | safeFlush(oldStream); | |
133 | safeClose(oldStream); | |
134 | } | |
113 | 135 | } |
114 | } catch (UnsupportedEncodingException e) { | |
115 | throw new IllegalArgumentException("The specified encoding is invalid"); | |
116 | 136 | } catch (Exception e) { |
117 | 137 | reportError("Error opening output stream", e, ErrorManager.OPEN_FAILURE); |
118 | 138 | return; |
119 | 139 | } |
120 | 140 | } |
121 | 141 | |
122 | private void updateWriter(final OutputStream newOutputStream, final String encoding) throws UnsupportedEncodingException { | |
123 | final UninterruptibleOutputStream outputStream = new UninterruptibleOutputStream(newOutputStream); | |
124 | super.setWriter(newOutputStream == null ? null : encoding == null ? new OutputStreamWriter(outputStream) : new OutputStreamWriter(outputStream, encoding)); | |
142 | private Writer getNewWriter(OutputStream newOutputStream) { | |
143 | if (newOutputStream == null) return null; | |
144 | final UninterruptibleOutputStream outputStream = new UninterruptibleOutputStream(new UncloseableOutputStream(newOutputStream)); | |
145 | final Charset charset = this.charset; | |
146 | return charset == null ? new OutputStreamWriter(outputStream) : new OutputStreamWriter(outputStream, charset); | |
125 | 147 | } |
126 | 148 | } |
497 | 497 | |
498 | 498 | @Override |
499 | 499 | public final void doPublish(final ExtLogRecord record) { |
500 | // Don't log empty messages | |
501 | if (record.getMessage() == null || record.getMessage().isEmpty()) { | |
502 | return; | |
503 | } | |
504 | 500 | synchronized (outputLock) { |
505 | 501 | init(); |
506 | 502 | if (out == null) { |
164 | 164 | } catch (Throwable ignored) {} |
165 | 165 | } |
166 | 166 | |
167 | private void safeFlush(Flushable f) { | |
167 | void safeFlush(Flushable f) { | |
168 | 168 | try { |
169 | 169 | if (f != null) f.flush(); |
170 | 170 | } catch (Exception e) { |
247 | 247 | Assert.assertTrue(formatted.contains("CIRCULAR REFERENCE:java.lang.IllegalStateException: suppressedLevel1")); |
248 | 248 | } |
249 | 249 | |
250 | @Test | |
251 | public void unqualifiedHost() { | |
252 | final String hostName = "logmanager.jboss.org"; | |
253 | final ExtLogRecord record = createLogRecord("test"); | |
254 | record.setHostName(hostName); | |
255 | PatternFormatter formatter = new PatternFormatter("%h"); | |
256 | Assert.assertEquals("logmanager", formatter.format(record)); | |
257 | ||
258 | // This should still return just the first portion | |
259 | formatter = new PatternFormatter("%h{2}"); | |
260 | Assert.assertEquals("logmanager", formatter.format(record)); | |
261 | ||
262 | // Should truncate from the beginning | |
263 | formatter = new PatternFormatter("%.3h"); | |
264 | Assert.assertEquals("log", formatter.format(record)); | |
265 | ||
266 | // Should truncate from the end | |
267 | formatter = new PatternFormatter("%.-7h"); | |
268 | Assert.assertEquals("manager", formatter.format(record)); | |
269 | } | |
270 | ||
271 | @Test | |
272 | public void qualifiedHost() { | |
273 | final String hostName = "logmanager.jboss.org"; | |
274 | final ExtLogRecord record = createLogRecord("test"); | |
275 | record.setHostName(hostName); | |
276 | PatternFormatter formatter = new PatternFormatter("%H"); | |
277 | Assert.assertEquals(hostName, formatter.format(record)); | |
278 | ||
279 | formatter = new PatternFormatter("%H{1}"); | |
280 | Assert.assertEquals("logmanager", formatter.format(record)); | |
281 | ||
282 | formatter = new PatternFormatter("%H{2}"); | |
283 | Assert.assertEquals("logmanager.jboss", formatter.format(record)); | |
284 | ||
285 | formatter = new PatternFormatter("%H{3}"); | |
286 | Assert.assertEquals(hostName, formatter.format(record)); | |
287 | ||
288 | formatter = new PatternFormatter("%H{4}"); | |
289 | Assert.assertEquals(hostName, formatter.format(record)); | |
290 | ||
291 | // Truncate from the beginning | |
292 | formatter = new PatternFormatter("%.10H"); | |
293 | Assert.assertEquals("logmanager", formatter.format(record)); | |
294 | ||
295 | // Truncate from the end | |
296 | formatter = new PatternFormatter("%.-3H"); | |
297 | Assert.assertEquals("org", formatter.format(record)); | |
298 | formatter = new PatternFormatter("%.-5H{2}"); | |
299 | Assert.assertEquals("jboss", formatter.format(record)); | |
300 | } | |
301 | ||
250 | 302 | |
251 | 303 | private void systemProperties(final String propertyPrefix) throws Exception { |
252 | 304 | final ExtLogRecord record = createLogRecord("test"); |
179 | 179 | part2 = "second message 𥹖"; |
180 | 180 | testMultibyteTruncation(part1, part2, 2); |
181 | 181 | |
182 | } | |
183 | ||
184 | @Test | |
185 | public void testNullMessage() throws Exception { | |
186 | // Setup the handler | |
187 | handler.setSyslogType(SyslogType.RFC5424); | |
188 | final ByteArrayOutputStream out = new ByteArrayOutputStream(); | |
189 | handler.setOutputStream(out); | |
190 | ||
191 | final Calendar cal = getCalendar(); | |
192 | // Create the record | |
193 | handler.setHostname("test"); | |
194 | ExtLogRecord record = createRecord(cal, null); | |
195 | final String expectedMessage = "<14>1 2012-01-09T04:39:22.000" + calculateTimeZone(cal) + " test java " + handler.getPid() + " - - " + BOM + "null"; | |
196 | handler.publish(record); | |
197 | Assert.assertEquals(expectedMessage, createString(out)); | |
182 | 198 | } |
183 | 199 | |
184 | 200 | private void testMultibyteTruncation(final String part1, final String part2, final int charsToTruncate) throws Exception { |
Binary diff not shown
Binary diff not shown
17 | 17 | |
18 | 18 | dname="CN=localhost, OU=Server Unit, O=Red Hat, L=Raleigh, S=NC, C=US" |
19 | 19 | # Create server keystore - file server-keystore.jks |
20 | keytool -genkey -v -alias server -keystore server-keystore.jks -validity 3650 -keypass testpassword -storepass testpassword -dname "${dname}" | |
20 | keytool -genkey -v -alias server -keystore server-keystore.jks -keyalg RSA -validity 3650 -keypass testpassword -storepass testpassword -dname "${dname}" | |
21 | 21 | |
22 | 22 | # Export Server's Public Key - file server.cer |
23 | 23 | keytool -export -keystore server-keystore.jks -alias server -file server.cer -keypass testpassword -storepass testpassword |
24 | 24 | |
25 | 25 | # Export Client Key Store - file client-keystore.jsk |
26 | keytool -genkey -v -alias client -keystore client-keystore.jks -validity 3650 -keypass testpassword -storepass testpassword -dname "${dname}" | |
26 | keytool -genkey -v -alias client -keystore client-keystore.jks -keyalg RSA -validity 3650 -keypass testpassword -storepass testpassword -dname "${dname}" | |
27 | 27 | |
28 | 28 | # Exporting Client's Public Key - file client.cer |
29 | 29 | keytool -export -keystore client-keystore.jks -alias client -file client.cer -keypass testpassword -storepass testpassword |
30 | 30 | |
31 | 31 | # Importing Client's Public key into server's truststore |
32 | keytool -import -v -trustcacerts -alias client -file client.cer -keystore server-keystore.jks -keypass testpassword -storepass testpassword | |
32 | keytool -import -v -trustcacerts -alias client -file client.cer -keystore server-keystore.jks -keypass testpassword -storepass testpassword -noprompt | |
33 | 33 | |
34 | 34 | # Importing Server's Public key into client's truststore |
35 | keytool -import -v -trustcacerts -alias server -file server.cer -keystore client-keystore.jks -keypass testpassword -storepass testpassword | |
35 | keytool -import -v -trustcacerts -alias server -file server.cer -keystore client-keystore.jks -keypass testpassword -storepass testpassword -noprompt | |
36 | 36 | |
37 | 37 | popd |
Binary diff not shown
Binary diff not shown