• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

WindhoverLabs / phoebus / #96

21 Nov 2023 04:15PM UTC coverage: 16.596% (+0.05%) from 16.544%
#96

push

web-flow
Merge pull request #90 from WindhoverLabs/88_out_of_memory_issues

WIP - 88 out of memory issues

97 of 217 new or added lines in 9 files covered. (44.7%)

4 existing lines in 3 files now uncovered.

17830 of 107434 relevant lines covered (16.6%)

0.17 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/core/commander-core/src/main/java/com/windhoverlabs/yamcs/core/WebSocketClientHandler.java
1
/*
2
 * Copyright 2012 The Netty Project
3
 *
4
 * The Netty Project licenses this file to you under the Apache License,
5
 * version 2.0 (the "License"); you may not use this file except in compliance
6
 * with the License. You may obtain a copy of the License at:
7
 *
8
 *   https://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
 * License for the specific language governing permissions and limitations
14
 * under the License.
15
 */
16
// The MIT License
17
//
18
// Copyright (c) 2009 Carl Bystršm
19
//
20
// Permission is hereby granted, free of charge, to any person obtaining a copy
21
// of this software and associated documentation files (the "Software"), to deal
22
// in the Software without restriction, including without limitation the rights
23
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
24
// copies of the Software, and to permit persons to whom the Software is
25
// furnished to do so, subject to the following conditions:
26
//
27
// The above copyright notice and this permission notice shall be included in
28
// all copies or substantial portions of the Software.
29
//
30
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
31
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
32
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
33
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
34
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
35
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
36
// THE SOFTWARE.
37

38
package com.windhoverlabs.yamcs.core;
39

40
import io.netty.channel.Channel;
41
import io.netty.channel.ChannelFuture;
42
import io.netty.channel.ChannelHandlerContext;
43
import io.netty.channel.ChannelPromise;
44
import io.netty.channel.SimpleChannelInboundHandler;
45
import io.netty.handler.codec.http.FullHttpResponse;
46
import io.netty.handler.codec.http.websocketx.CloseWebSocketFrame;
47
import io.netty.handler.codec.http.websocketx.PongWebSocketFrame;
48
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
49
import io.netty.handler.codec.http.websocketx.WebSocketClientHandshaker;
50
import io.netty.handler.codec.http.websocketx.WebSocketFrame;
51
import io.netty.handler.codec.http.websocketx.WebSocketHandshakeException;
52
import io.netty.util.CharsetUtil;
53

54
public class WebSocketClientHandler extends SimpleChannelInboundHandler<Object> {
55

56
  private final WebSocketClientHandshaker handshaker;
57
  private ChannelPromise handshakeFuture;
58

NEW
59
  public WebSocketClientHandler(WebSocketClientHandshaker handshaker) {
×
NEW
60
    this.handshaker = handshaker;
×
NEW
61
  }
×
62

63
  public ChannelFuture handshakeFuture() {
NEW
64
    return handshakeFuture;
×
65
  }
66

67
  @Override
68
  public void handlerAdded(ChannelHandlerContext ctx) {
NEW
69
    handshakeFuture = ctx.newPromise();
×
NEW
70
  }
×
71

72
  @Override
73
  public void channelActive(ChannelHandlerContext ctx) {
NEW
74
    handshaker.handshake(ctx.channel());
×
NEW
75
  }
×
76

77
  @Override
78
  public void channelInactive(ChannelHandlerContext ctx) {
NEW
79
    System.out.println("WebSocket Client disconnected!");
×
NEW
80
  }
×
81

82
  @Override
83
  public void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
NEW
84
    Channel ch = ctx.channel();
×
NEW
85
    if (!handshaker.isHandshakeComplete()) {
×
86
      try {
NEW
87
        handshaker.finishHandshake(ch, (FullHttpResponse) msg);
×
NEW
88
        System.out.println("WebSocket Client connected!");
×
NEW
89
        handshakeFuture.setSuccess();
×
NEW
90
      } catch (WebSocketHandshakeException e) {
×
NEW
91
        System.out.println("WebSocket Client failed to connect");
×
NEW
92
        handshakeFuture.setFailure(e);
×
NEW
93
      }
×
NEW
94
      return;
×
95
    }
96

NEW
97
    if (msg instanceof FullHttpResponse) {
×
NEW
98
      FullHttpResponse response = (FullHttpResponse) msg;
×
NEW
99
      throw new IllegalStateException(
×
100
          "Unexpected FullHttpResponse (getStatus="
NEW
101
              + response.status()
×
102
              + ", content="
NEW
103
              + response.content().toString(CharsetUtil.UTF_8)
×
104
              + ')');
105
    }
106

NEW
107
    WebSocketFrame frame = (WebSocketFrame) msg;
×
NEW
108
    if (frame instanceof TextWebSocketFrame) {
×
NEW
109
      TextWebSocketFrame textFrame = (TextWebSocketFrame) frame;
×
NEW
110
      System.out.println("WebSocket Client received message: " + textFrame.text());
×
NEW
111
    } else if (frame instanceof PongWebSocketFrame) {
×
NEW
112
      System.out.println("WebSocket Client received pong");
×
NEW
113
    } else if (frame instanceof CloseWebSocketFrame) {
×
NEW
114
      System.out.println("WebSocket Client received closing");
×
NEW
115
      ch.close();
×
116
    }
NEW
117
  }
×
118

119
  @Override
120
  public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
NEW
121
    cause.printStackTrace();
×
NEW
122
    if (!handshakeFuture.isDone()) {
×
NEW
123
      handshakeFuture.setFailure(cause);
×
124
    }
NEW
125
    ctx.close();
×
NEW
126
  }
×
127
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc