tabish121 commented on code in PR #4493: URL: https://github.com/apache/activemq-artemis/pull/4493#discussion_r1211906696
########## artemis-server/src/main/java/org/apache/activemq/artemis/core/server/protocol/websocket/WebSocketFrameEncoderType.java: ########## @@ -0,0 +1,33 @@ +/** + * 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.activemq.artemis.core.server.protocol.websocket; + +public enum WebSocketFrameEncoderType { + BINARY, TEXT; + + public static WebSocketFrameEncoderType valueOfType(String type) { + switch (type) { + case "binary": + return BINARY; + case "text": + return TEXT; + default: + return null; Review Comment: Instead of returning null here why not just throw an exception that indicates that this is an invalid argument here to avoid any chance of NPE later ########## artemis-server/src/test/java/org/apache/activemq/artemis/core/server/protocol/websocket/WebSocketFrameEncoderTest.java: ########## @@ -60,11 +61,22 @@ public class WebSocketFrameEncoderTest { @Before public void setUp() throws Exception { - spy = spy(new WebSocketFrameEncoder(maxFramePayloadLength)); + binarySpy = spy(new WebSocketFrameEncoder(maxFramePayloadLength, WebSocketFrameEncoderType.BINARY)); + textSpy = spy(new WebSocketFrameEncoder(maxFramePayloadLength, WebSocketFrameEncoderType.TEXT)); } @Test - public void testWriteNonByteBuf() throws Exception { + public void testWriteNonByteBufBinary() throws Exception { + testWriteNonByteBuf(binarySpy); + } + + Review Comment: Extra newline ########## artemis-server/src/main/java/org/apache/activemq/artemis/core/protocol/ProtocolHandler.java: ########## @@ -158,7 +160,12 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception } stompMaxFramePayloadLength = stompMaxFramePayloadLength != -1 ? stompMaxFramePayloadLength : TransportConstants.DEFAULT_WEB_SOCKET_MAX_FRAME_PAYLOAD_LENGTH; int webSocketMaxFramePayloadLength = ConfigurationHelper.getIntProperty(TransportConstants.WEB_SOCKET_MAX_FRAME_PAYLOAD_LENGTH, -1, nettyAcceptor.getConfiguration()); - ctx.pipeline().addLast("websocket-handler", new WebSocketServerHandler(websocketSubprotocolIds, webSocketMaxFramePayloadLength != -1 ? webSocketMaxFramePayloadLength : stompMaxFramePayloadLength)); + String encoderConfigType = ConfigurationHelper.getStringProperty(TransportConstants.WEB_SOCKET_ENCODER_TYPE, TransportConstants.DEFAULT_WEB_SOCKET_ENCODER_TYPE, nettyAcceptor.getConfiguration()); + WebSocketFrameEncoderType encoderType = WebSocketFrameEncoderType.valueOfType(encoderConfigType); + if (encoderType == null) { Review Comment: As noted below I'd just have the 'valuefType' method validate and throw instead of needing to check here -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
