Skip to content

Commit 9c91d82

Browse files
committed
Apply J-N-K patches for Openhab. update dependencies to be aligned with OH
1 parent 428ea3d commit 9c91d82

File tree

2 files changed

+65
-27
lines changed

2 files changed

+65
-27
lines changed

pom.xml

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111

1212
<properties>
1313
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
14-
</properties>
14+
<netty.version>4.1.42.Final</netty.version>
15+
16+
</properties>
1517

1618
<licenses>
1719
<license>
@@ -56,8 +58,44 @@
5658

5759
<dependency>
5860
<groupId>io.netty</groupId>
59-
<artifactId>netty-all</artifactId>
60-
<version>4.0.32.Final</version>
61+
<artifactId>netty-common</artifactId>
62+
<version>${netty.version}</version>
63+
</dependency>
64+
65+
<dependency>
66+
<groupId>io.netty</groupId>
67+
<artifactId>netty-buffer</artifactId>
68+
<version>${netty.version}</version>
69+
</dependency>
70+
71+
<dependency>
72+
<groupId>io.netty</groupId>
73+
<artifactId>netty-transport</artifactId>
74+
<version>${netty.version}</version>
75+
</dependency>
76+
77+
<dependency>
78+
<groupId>io.netty</groupId>
79+
<artifactId>netty-handler</artifactId>
80+
<version>${netty.version}</version>
81+
</dependency>
82+
83+
<dependency>
84+
<groupId>io.netty</groupId>
85+
<artifactId>netty-codec</artifactId>
86+
<version>${netty.version}</version>
87+
</dependency>
88+
89+
<dependency>
90+
<groupId>io.netty</groupId>
91+
<artifactId>netty-codec-http</artifactId>
92+
<version>${netty.version}</version>
93+
</dependency>
94+
95+
<dependency>
96+
<groupId>io.netty</groupId>
97+
<artifactId>netty-resolver</artifactId>
98+
<version>${netty.version}</version>
6199
</dependency>
62100

63101
<dependency>
@@ -102,12 +140,6 @@
102140
<version>3.4.1</version>
103141
</dependency>
104142

105-
<dependency>
106-
<groupId>commons-io</groupId>
107-
<artifactId>commons-io</artifactId>
108-
<version>2.4</version>
109-
</dependency>
110-
111143
<dependency>
112144
<groupId>junit</groupId>
113145
<artifactId>junit</artifactId>
@@ -178,7 +210,7 @@
178210
</plugin>
179211
<plugin>
180212
<artifactId>maven-assembly-plugin</artifactId>
181-
<version>3.1.0</version>
213+
<version>3.1.1</version>
182214
<configuration>
183215
<descriptors>
184216
<descriptor>deploy/distribution.xml</descriptor>

src/main/java/io/github/hapjava/server/impl/http/impl/LoggingHandler.java

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@
22

33
import io.netty.buffer.ByteBuf;
44
import io.netty.channel.*;
5-
import java.io.ByteArrayOutputStream;
65
import java.io.IOException;
7-
import java.nio.charset.StandardCharsets;
8-
import org.apache.commons.io.HexDump;
96
import org.slf4j.Logger;
107
import org.slf4j.LoggerFactory;
118

129
public class LoggingHandler extends ChannelDuplexHandler {
1310

14-
private static final Logger logger = LoggerFactory.getLogger(NettyHomekitHttpService.class);
11+
private static final Logger logger = LoggerFactory.getLogger(LoggingHandler.class);
12+
private static final char[] HEX_ARRAY = "0123456789ABCDEF".toCharArray();
1513

1614
@Override
1715
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
@@ -32,19 +30,27 @@ public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise)
3230

3331
private void logBytes(String type, ByteBuf buf, ChannelHandlerContext ctx) throws IOException {
3432
if (buf.readableBytes() > 0) {
35-
try (ByteArrayOutputStream stream = new ByteArrayOutputStream()) {
36-
byte[] bytes = new byte[buf.readableBytes()];
37-
buf.getBytes(0, bytes, 0, bytes.length);
38-
HexDump.dump(bytes, 0, stream, 0);
39-
stream.flush();
40-
logger.trace(
41-
String.format(
42-
"%s %s [%s]:%n%s%n",
43-
type,
44-
buf,
45-
ctx.channel().remoteAddress().toString(),
46-
stream.toString(StandardCharsets.UTF_8.name())));
47-
}
33+
byte[] bytes = new byte[buf.readableBytes()];
34+
buf.getBytes(0, bytes, 0, bytes.length);
35+
logger.trace(
36+
String.format(
37+
"%s %s [%s]:%n%s%n",
38+
type, buf, ctx.channel().remoteAddress().toString(), bytesToHex(bytes)));
4839
}
4940
}
41+
42+
/*
43+
This method is licensed under CC-BY-SA and published on Stackoverflow
44+
https://stackoverflow.com/questions/9655181/how-to-convert-a-byte-array-to-a-hex-string-in-java
45+
from the answer by Melquiades https://stackoverflow.com/users/2964945/melquiades
46+
*/
47+
private String bytesToHex(byte[] bytes) {
48+
char[] hexChars = new char[bytes.length * 2];
49+
for (int j = 0; j < bytes.length; j++) {
50+
int v = bytes[j] & 0xFF;
51+
hexChars[j * 2] = HEX_ARRAY[v >>> 4];
52+
hexChars[j * 2 + 1] = HEX_ARRAY[v & 0x0F];
53+
}
54+
return new String(hexChars);
55+
}
5056
}

0 commit comments

Comments
 (0)