Skip to content

Commit

Permalink
WICKET-6965 Store application name to avoid accessing the session dur…
Browse files Browse the repository at this point in the history
…ing `onClose` and `onError` (apache#507)
  • Loading branch information
theigl authored Apr 4, 2022
1 parent eb8ea96 commit 243f6ff
Showing 1 changed file with 6 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,16 @@ public class WicketEndpoint extends Endpoint
*/
private static final String WICKET_APP_PARAM_NAME = "wicket-app-name";

private String applicationName;
private JavaxWebSocketProcessor javaxWebSocketProcessor;

@Override
public void onOpen(Session session, EndpointConfig endpointConfig)
{
String appName = getApplicationName(session);
applicationName = getApplicationName(session);

WebApplication app = (WebApplication) WebApplication.get(appName);
if (RUNNING_APPLICATIONS.add(appName))
WebApplication app = (WebApplication)WebApplication.get(applicationName);
if (RUNNING_APPLICATIONS.add(applicationName))
{
app.getApplicationListeners().add(new ApplicationListener());
}
Expand Down Expand Up @@ -90,8 +91,7 @@ public void onClose(Session session, CloseReason closeReason)
LOG.debug("Web Socket connection with id '{}' has been closed with code '{}' and reason: {}",
session.getId(), closeCode, reasonPhrase);

String applicationName = getApplicationName(session);
if (isApplicationAlive(applicationName) && javaxWebSocketProcessor != null)
if (javaxWebSocketProcessor != null && isApplicationAlive(applicationName))
{
javaxWebSocketProcessor.onClose(closeCode, reasonPhrase);
}
Expand All @@ -111,8 +111,7 @@ public void onError(Session session, Throwable t)

super.onError(session, t);

String applicationName = getApplicationName(session);
if (isApplicationAlive(applicationName) && javaxWebSocketProcessor != null)
if (javaxWebSocketProcessor != null && isApplicationAlive(applicationName))
{
javaxWebSocketProcessor.onError(t);
}
Expand Down

0 comments on commit 243f6ff

Please sign in to comment.