Skip to content

Commit

Permalink
Don't store the proxied endpoint in onOpen
Browse files Browse the repository at this point in the history
Doing so overwrites the prior proxied endpoint, which means only the
last-opened connection's onOpen and onError get called.

We can just retrieve the proxied endpoint from the user properties
anyway, so don't need to store it at all.
  • Loading branch information
tobias committed Feb 20, 2015
1 parent 1c4d432 commit f5a9846
Showing 1 changed file with 15 additions and 8 deletions.
Expand Up @@ -23,27 +23,31 @@
import java.io.IOException;

public class DelegatingJavaxEndpoint extends Endpoint {
public static final String ENDPOINT_KEY = "session-endpoint";

@Override
public void onOpen(Session session, EndpointConfig endpointConfig) {
this.endpoint = (Endpoint)endpointConfig.getUserProperties().get("Endpoint");
if (this.endpoint != null) {
this.endpoint.onOpen(session, endpointConfig);
Endpoint endpoint = sessionEndpoint(session);
if (endpoint != null) {
endpoint.onOpen(session, endpointConfig);
} else {
close(session);
}
}

@Override
public void onClose(Session session, CloseReason closeReason) {
if (this.endpoint != null) {
this.endpoint.onClose(session, closeReason);
Endpoint endpoint = sessionEndpoint(session);
if (endpoint != null) {
endpoint.onClose(session, closeReason);
}
}

@Override
public void onError(Session session, Throwable err) {
if (this.endpoint != null) {
this.endpoint.onError(session, err);
Endpoint endpoint = sessionEndpoint(session);
if (endpoint != null) {
endpoint.onError(session, err);
} else {
close(session);
}
Expand All @@ -57,7 +61,10 @@ private void close(Session session) {
}
}

private Endpoint endpoint;
private Endpoint sessionEndpoint(final Session session) {
return (Endpoint)session.getUserProperties().get(ENDPOINT_KEY);
}

private final static CloseReason POLICY_CLOSE = new CloseReason(new CloseReason.CloseCode() {
@Override
public int getCode() {
Expand Down

0 comments on commit f5a9846

Please sign in to comment.