wsky / top-link

embedded duplex multi-channel endpoint and connection management for c#/java/...
6 stars 1 forks source link

handleConnect got unexpected exception, maybe return null statusCode and statusPhase, that client mistaken connected #62

Closed wsky closed 11 years ago

wsky commented 11 years ago
} catch (LinkException e) {
            ack.statusCode = e.getErrorCode();
            ack.statusPhase = e.getMessage();
            this.logger.warn(Text.E_REFUSE, e);
        }

if e from this:

try {
            this.internalTopService.checkSign(headers);
        } catch (Exception e2) {
            throw new LinkException(e2.getMessage(), e2);
        }

if e2 was java.lang.NullPointerException, message was null, so both errorCode and message passed to client were null

wsky commented 11 years ago

same as internalOnMessage

private void internalOnMessage(ChannelContext context, Message msg, Identity msgFrom) throws LinkException {
        if (msg.messageType == MessageType.SENDACK) {
            this.endpoint.getMessageHandler().onMessage(msg.content, msgFrom);
            return;
        }

        EndpointContext endpointContext = new EndpointContext(
                context, this.endpoint, msgFrom, msg.flag, msg.token);
        endpointContext.setMessage(msg.content);
        try {
            this.endpoint.getMessageHandler().onMessage(endpointContext);
        } catch (Exception e) {
            // onMessage error should be reply to client
            if (e instanceof LinkException)
                endpointContext.error(
                        ((LinkException) e).getErrorCode(),
                        ((LinkException) e).getMessage());
            else
                endpointContext.error(0, e.getMessage());
        }
    }