11package de .rwth .idsg .steve .ocpp .ws ;
22
3+ import com .google .common .base .Strings ;
34import de .rwth .idsg .steve .config .WebSocketConfiguration ;
45import de .rwth .idsg .steve .ocpp .OcppVersion ;
5- import de .rwth .idsg .steve .ocpp .ws .custom .WsSessionSelectStrategy ;
66import de .rwth .idsg .steve .ocpp .ws .data .CommunicationContext ;
77import de .rwth .idsg .steve .ocpp .ws .data .SessionContext ;
88import de .rwth .idsg .steve .ocpp .ws .pipeline .IncomingPipeline ;
99import de .rwth .idsg .steve .repository .OcppServerRepository ;
1010import de .rwth .idsg .steve .service .NotificationService ;
1111import org .joda .time .DateTime ;
12- import org .slf4j .Logger ;
13- import org .slf4j .LoggerFactory ;
1412import org .springframework .beans .factory .annotation .Autowired ;
1513import org .springframework .web .socket .BinaryMessage ;
1614import org .springframework .web .socket .CloseStatus ;
3432 * @since 17.03.2015
3533 */
3634public abstract class AbstractWebSocketEndpoint implements WebSocketHandler {
37- private final Logger log = LoggerFactory .getLogger (getClass ());
3835
3936 @ Autowired private ScheduledExecutorService service ;
4037 @ Autowired private OcppServerRepository ocppServerRepository ;
4138 @ Autowired private FutureResponseContextStore futureResponseContextStore ;
42- @ Autowired private WsSessionSelectStrategy wsSessionSelectStrategy ;
4339 @ Autowired private NotificationService notificationService ;
4440
4541 public static final String CHARGEBOX_ID_KEY = "CHARGEBOX_ID_KEY" ;
4642
47- private IncomingPipeline pipeline ;
48- private SessionContextStoreImpl sessionContextStore ;
49-
43+ private final SessionContextStoreImpl sessionContextStore = new SessionContextStoreImpl ();
5044 private final List <Consumer <String >> connectedCallbackList = new ArrayList <>();
5145 private final List <Consumer <String >> disconnectedCallbackList = new ArrayList <>();
52-
5346 private final Object sessionContextLock = new Object ();
5447
48+ private IncomingPipeline pipeline ;
49+
5550 public abstract OcppVersion getVersion ();
5651
5752 public void init (IncomingPipeline pipeline ) {
5853 this .pipeline = pipeline ;
59- sessionContextStore = new SessionContextStoreImpl (wsSessionSelectStrategy );
6054
6155 connectedCallbackList .add ((chargeBoxId ) -> notificationService .ocppStationWebSocketConnected (chargeBoxId ));
6256 disconnectedCallbackList .add ((chargeBoxId ) -> notificationService .ocppStationWebSocketDisconnected (chargeBoxId ));
@@ -82,6 +76,12 @@ private void handleTextMessage(WebSocketSession session, TextMessage webSocketMe
8276 String incomingString = webSocketMessage .getPayload ();
8377 String chargeBoxId = getChargeBoxId (session );
8478
79+ // https://github.com/RWTH-i5-IDSG/steve/issues/66
80+ if (Strings .isNullOrEmpty (incomingString )) {
81+ WebSocketLogger .receivedEmptyText (chargeBoxId , session );
82+ return ;
83+ }
84+
8585 WebSocketLogger .receivedText (chargeBoxId , session , incomingString );
8686
8787 CommunicationContext context = new CommunicationContext (session , chargeBoxId );
@@ -92,8 +92,6 @@ private void handleTextMessage(WebSocketSession session, TextMessage webSocketMe
9292
9393 private void handlePongMessage (WebSocketSession session ) {
9494 WebSocketLogger .receivedPong (getChargeBoxId (session ), session );
95-
96- // TODO: Not sure about the following. Should update DB? Should call directly repo?
9795 ocppServerRepository .updateChargeboxHeartbeat (getChargeBoxId (session ), DateTime .now ());
9896 }
9997
@@ -106,7 +104,7 @@ public void afterConnectionEstablished(WebSocketSession session) throws Exceptio
106104 // Just to keep the connection alive, such that the servers do not close
107105 // the connection because of a idle timeout, we ping-pong at fixed intervals.
108106 ScheduledFuture pingSchedule = service .scheduleAtFixedRate (
109- new PingTask (session ),
107+ new PingTask (chargeBoxId , session ),
110108 WebSocketConfiguration .PING_INTERVAL ,
111109 WebSocketConfiguration .PING_INTERVAL ,
112110 TimeUnit .MINUTES );
@@ -151,8 +149,7 @@ public void afterConnectionClosed(WebSocketSession session, CloseStatus closeSta
151149
152150 @ Override
153151 public void handleTransportError (WebSocketSession session , Throwable throwable ) throws Exception {
154- log .error ("Oops" , throwable );
155- // TODO: Do something about this
152+ WebSocketLogger .transportError (getChargeBoxId (session ), session , throwable );
156153 }
157154
158155 @ Override
0 commit comments