-
Notifications
You must be signed in to change notification settings - Fork 328
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1743 from rmsamitha/master
Websocket access logging feature
- Loading branch information
Showing
3 changed files
with
386 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
134 changes: 134 additions & 0 deletions
134
...va/org/wso2/carbon/inbound/endpoint/protocol/websocket/WebSocketAccessLoggingHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
/* | ||
* Copyright (c) 2025, WSO2 LLC. (http://www.wso2.org) All Rights Reserved. | ||
* | ||
* WSO2 Inc. 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.wso2.carbon.inbound.endpoint.protocol.websocket; | ||
|
||
import io.netty.channel.ChannelHandlerContext; | ||
import io.netty.channel.ChannelPromise; | ||
import io.netty.handler.logging.ByteBufFormat; | ||
import io.netty.handler.logging.LogLevel; | ||
import io.netty.handler.logging.LoggingHandler; | ||
|
||
import java.net.SocketAddress; | ||
|
||
/** | ||
* This class is used for managing logging the access logs of the WebSocket APIs. | ||
*/ | ||
public class WebSocketAccessLoggingHandler extends LoggingHandler { | ||
|
||
WebsocketAccessLogger websocketAccessLogger; | ||
|
||
public WebSocketAccessLoggingHandler(LogLevel level) { | ||
super(level, ByteBufFormat.HEX_DUMP); | ||
// Initialize log properties | ||
websocketAccessLogger = new WebsocketAccessLogger(this.logger); | ||
} | ||
|
||
@Override | ||
public void channelRegistered(ChannelHandlerContext ctx) { | ||
if (this.logger.isEnabled(this.internalLevel)) { | ||
websocketAccessLogger.logChannelRegistered(ctx); | ||
} | ||
ctx.fireChannelRegistered(); | ||
} | ||
|
||
@Override | ||
public void channelRead(ChannelHandlerContext ctx, Object msg) { | ||
if (logger.isEnabled(internalLevel)) { | ||
websocketAccessLogger.logChannelRead(ctx, msg); | ||
} | ||
ctx.fireChannelRead(msg); | ||
} | ||
|
||
@Override | ||
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { | ||
if (logger.isEnabled(internalLevel)) { | ||
websocketAccessLogger.logChannelWrite(ctx, msg); | ||
} | ||
ctx.write(msg, promise); | ||
} | ||
|
||
@Override | ||
public void channelUnregistered(ChannelHandlerContext ctx) { | ||
if (logger.isEnabled(internalLevel)) { | ||
websocketAccessLogger.logChannelUnregistered(ctx); | ||
} | ||
ctx.fireChannelUnregistered(); | ||
} | ||
|
||
@Override | ||
public void channelActive(ChannelHandlerContext ctx) { | ||
ctx.fireChannelActive(); | ||
} | ||
|
||
@Override | ||
public void channelInactive(ChannelHandlerContext ctx) { | ||
ctx.fireChannelInactive(); | ||
} | ||
|
||
@Override | ||
public void channelReadComplete(ChannelHandlerContext ctx) { | ||
ctx.fireChannelReadComplete(); | ||
} | ||
|
||
@Override | ||
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) { | ||
ctx.fireUserEventTriggered(evt); | ||
} | ||
|
||
@Override | ||
public void channelWritabilityChanged(ChannelHandlerContext ctx) { | ||
ctx.fireChannelWritabilityChanged(); | ||
} | ||
|
||
@Override | ||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { | ||
ctx.fireExceptionCaught(cause); | ||
} | ||
|
||
@Override | ||
public void close(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception { | ||
ctx.close(promise); | ||
} | ||
|
||
@Override | ||
public void flush(ChannelHandlerContext ctx) throws Exception { | ||
ctx.flush(); | ||
} | ||
|
||
@Override | ||
public void bind(ChannelHandlerContext ctx, SocketAddress localAddress, ChannelPromise promise) throws Exception { | ||
ctx.bind(localAddress, promise); | ||
} | ||
|
||
@Override | ||
public void connect(ChannelHandlerContext ctx, SocketAddress remoteAddress, SocketAddress localAddress, | ||
ChannelPromise promise) throws Exception { | ||
ctx.connect(remoteAddress, localAddress, promise); | ||
} | ||
|
||
@Override | ||
public void disconnect(ChannelHandlerContext ctx, ChannelPromise promise) { | ||
ctx.disconnect(promise); | ||
} | ||
|
||
@Override | ||
public void deregister(ChannelHandlerContext ctx, ChannelPromise promise) { | ||
ctx.deregister(promise); | ||
} | ||
} |
Oops, something went wrong.