private void logUsedEncoder(CoderWrapper<Encoder> encoder, Session session) { if (LOGGER.isLoggable(Level.FINEST)) { if (session instanceof TyrusSession) { ((TyrusSession) session).getDebugContext() .appendLogMessage(LOGGER, Level.FINEST, DebugContext.Type.MESSAGE_OUT, "Encoding with: ", encoder); } } }
private void logUsedEncoder(CoderWrapper<Encoder> encoder, Session session) { if (LOGGER.isLoggable(Level.FINEST)) { if (session instanceof TyrusSession) { ((TyrusSession) session).getDebugContext() .appendLogMessage(LOGGER, Level.FINEST, DebugContext.Type.MESSAGE_OUT, "Encoding with: ", encoder); } } }
private void logExtensionsAndSubprotocol(ProtocolHandler protocolHandler, DebugContext debugContext) { StringBuilder sb = new StringBuilder(); sb.append("Using negotiated extensions: ["); boolean isFirst = true; for (Extension extension : protocolHandler.getExtensions()) { if (isFirst) { isFirst = false; } else { sb.append(", "); } sb.append(extension.getName()); } sb.append("]"); debugContext.appendLogMessage(LOGGER, Level.FINE, DebugContext.Type.OTHER, "Using negotiated extensions: ", sb); debugContext.appendLogMessage(LOGGER, Level.FINE, DebugContext.Type.OTHER, "Using negotiated subprotocol: ", protocolHandler.getSubProtocol()); }
private void logExtensionsAndSubprotocol(ProtocolHandler protocolHandler, DebugContext debugContext) { StringBuilder sb = new StringBuilder(); sb.append("Using negotiated extensions: ["); boolean isFirst = true; for (Extension extension : protocolHandler.getExtensions()) { if (isFirst) { isFirst = false; } else { sb.append(", "); } sb.append(extension.getName()); } sb.append("]"); debugContext.appendLogMessage(LOGGER, Level.FINE, DebugContext.Type.OTHER, "Using negotiated extensions: ", sb); debugContext.appendLogMessage(LOGGER, Level.FINE, DebugContext.Type.OTHER, "Using negotiated subprotocol: ", protocolHandler.getSubProtocol()); }
private void logUpgradeRequest(UpgradeRequest upgradeRequest) { if (LOGGER.isLoggable(Level.FINE)) { debugContext.appendLogMessage(LOGGER, Level.FINE, DebugContext.Type.MESSAGE_OUT, "Sending handshake " + "request:\n" + Utils.stringifyUpgradeRequest(upgradeRequest)); } else { if (logUpgradeMessages) { debugContext.appendStandardOutputMessage(DebugContext.Type.MESSAGE_OUT, "Sending handshake " + "request:\n" + Utils.stringifyUpgradeRequest(upgradeRequest)); } } }
private void logUpgradeRequest(UpgradeRequest upgradeRequest) { if (LOGGER.isLoggable(Level.FINE)) { debugContext.appendLogMessage(LOGGER, Level.FINE, DebugContext.Type.MESSAGE_OUT, "Sending handshake " + "request:\n" + Utils.stringifyUpgradeRequest(upgradeRequest)); } else { if (logUpgradeMessages) { debugContext.appendStandardOutputMessage(DebugContext.Type.MESSAGE_OUT, "Sending handshake " + "request:\n" + Utils.stringifyUpgradeRequest(upgradeRequest)); } } }
private ArrayList<CoderWrapper<Decoder>> findApplicableDecoders(TyrusSession session, Object message, boolean isString) { ArrayList<CoderWrapper<Decoder>> result = new ArrayList<CoderWrapper<Decoder>>(); for (CoderWrapper<Decoder> dec : decoders) { if (isString && (Decoder.Text.class.isAssignableFrom(dec.getCoderClass()))) { final Decoder.Text decoder = (Decoder.Text) getCoderInstance(session, dec); if (decoder.willDecode((String) message)) { result.add(dec); } } else if (!isString && (Decoder.Binary.class.isAssignableFrom(dec.getCoderClass()))) { final Decoder.Binary decoder = (Decoder.Binary) getCoderInstance(session, dec); if (decoder.willDecode((ByteBuffer) message)) { result.add(dec); } } else if (isString && (Decoder.TextStream.class.isAssignableFrom(dec.getCoderClass()))) { result.add(dec); } else if (!isString && (Decoder.BinaryStream.class.isAssignableFrom(dec.getCoderClass()))) { result.add(dec); } } session.getDebugContext() .appendLogMessage(LOGGER, Level.FINEST, DebugContext.Type.MESSAGE_IN, "Applicable decoders: ", result); return result; }
private ArrayList<CoderWrapper<Decoder>> findApplicableDecoders(TyrusSession session, Object message, boolean isString) { ArrayList<CoderWrapper<Decoder>> result = new ArrayList<CoderWrapper<Decoder>>(); for (CoderWrapper<Decoder> dec : decoders) { if (isString && (Decoder.Text.class.isAssignableFrom(dec.getCoderClass()))) { final Decoder.Text decoder = (Decoder.Text) getCoderInstance(session, dec); if (decoder.willDecode((String) message)) { result.add(dec); } } else if (!isString && (Decoder.Binary.class.isAssignableFrom(dec.getCoderClass()))) { final Decoder.Binary decoder = (Decoder.Binary) getCoderInstance(session, dec); if (decoder.willDecode((ByteBuffer) message)) { result.add(dec); } } else if (isString && (Decoder.TextStream.class.isAssignableFrom(dec.getCoderClass()))) { result.add(dec); } else if (!isString && (Decoder.BinaryStream.class.isAssignableFrom(dec.getCoderClass()))) { result.add(dec); } } session.getDebugContext() .appendLogMessage(LOGGER, Level.FINEST, DebugContext.Type.MESSAGE_IN, "Applicable decoders: ", result); return result; }
TyrusEndpointWrapper getEndpointWrapper(UpgradeRequest request, DebugContext debugContext) throws HandshakeException { if (endpointWrappers.isEmpty()) { return null; } final String requestPath = request.getRequestUri(); for (Match m : Match.getAllMatches(requestPath, endpointWrappers, debugContext)) { final TyrusEndpointWrapper endpointWrapper = m.getEndpointWrapper(); for (Map.Entry<String, String> parameter : m.getParameters().entrySet()) { request.getParameterMap().put(parameter.getKey(), Arrays.asList(parameter.getValue())); } if (endpointWrapper.upgrade(request)) { debugContext.appendTraceMessage(LOGGER, Level.FINE, DebugContext.Type.MESSAGE_IN, "Endpoint selected as a match to the handshake URI: ", endpointWrapper.getEndpointPath()); debugContext.appendLogMessage(LOGGER, Level.FINER, DebugContext.Type.MESSAGE_IN, "Target endpoint: ", endpointWrapper); return endpointWrapper; } } return null; }
TyrusEndpointWrapper getEndpointWrapper(UpgradeRequest request, DebugContext debugContext) throws HandshakeException { if (endpointWrappers.isEmpty()) { return null; } final String requestPath = request.getRequestUri(); for (Match m : Match.getAllMatches(requestPath, endpointWrappers, debugContext)) { final TyrusEndpointWrapper endpointWrapper = m.getEndpointWrapper(); for (Map.Entry<String, String> parameter : m.getParameters().entrySet()) { request.getParameterMap().put(parameter.getKey(), Arrays.asList(parameter.getValue())); } if (endpointWrapper.upgrade(request)) { debugContext.appendTraceMessage(LOGGER, Level.FINE, DebugContext.Type.MESSAGE_IN, "Endpoint selected as a match to the handshake URI: ", endpointWrapper.getEndpointPath()); debugContext.appendLogMessage(LOGGER, Level.FINER, DebugContext.Type.MESSAGE_IN, "Target endpoint: ", endpointWrapper); return endpointWrapper; } } return null; }
@Override public void sendText(String partialMessage, boolean isLast) throws IOException { checkNotNull(partialMessage, "partialMessage"); session.getDebugContext().appendLogMessage(LOGGER, Level.FINEST, DebugContext.Type.MESSAGE_OUT, "Sending partial text message: ", partialMessage); final Future<?> future = webSocket.sendText(partialMessage, isLast); try { processFuture(future); } finally { session.restartIdleTimeoutExecutor(); } }
@Override public void sendText(String text) throws IOException { checkNotNull(text, "text"); session.getDebugContext() .appendLogMessage(LOGGER, Level.FINEST, DebugContext.Type.MESSAGE_OUT, "Sending text message: ", text); final Future<?> future = webSocket.sendText(text); try { processFuture(future); } finally { session.restartIdleTimeoutExecutor(); } }
@Override public void sendText(String partialMessage, boolean isLast) throws IOException { checkNotNull(partialMessage, "partialMessage"); session.getDebugContext().appendLogMessage(LOGGER, Level.FINEST, DebugContext.Type.MESSAGE_OUT, "Sending partial text message: ", partialMessage); final Future<?> future = webSocket.sendText(partialMessage, isLast); try { processFuture(future); } finally { session.restartIdleTimeoutExecutor(); } }
/** * Called by the provider when the web socket connection * has an incoming ping message from the given remote endpoint. * <p> * The endpoint needs to respond as soon as possible (see the websocket RFC). * No involvement from application layer, there is no ping listener. * * @param socket {@link TyrusWebSocket} who sent the message. * @param bytes the message. */ void onPing(TyrusWebSocket socket, ByteBuffer bytes) { TyrusSession session = getSession(socket); if (session == null) { LOGGER.log(Level.FINE, "Ping received on already closed connection."); return; } session.getDebugContext() .appendLogMessage(LOGGER, Level.FINEST, DebugContext.Type.MESSAGE_IN, "Received ping message"); session.restartIdleTimeoutExecutor(); try { session.getBasicRemote().sendPong(bytes); } catch (IOException e) { // do nothing. // we might consider calling onError, but there should be better defined exception. } }
@Override public void sendText(String text) throws IOException { checkNotNull(text, "text"); session.getDebugContext() .appendLogMessage(LOGGER, Level.FINEST, DebugContext.Type.MESSAGE_OUT, "Sending text message: ", text); final Future<?> future = webSocket.sendText(text); try { processFuture(future); } finally { session.restartIdleTimeoutExecutor(); } }
/** * Called by the provider when the web socket connection * has an incoming ping message from the given remote endpoint. * <p> * The endpoint needs to respond as soon as possible (see the websocket RFC). * No involvement from application layer, there is no ping listener. * * @param socket {@link TyrusWebSocket} who sent the message. * @param bytes the message. */ void onPing(TyrusWebSocket socket, ByteBuffer bytes) { TyrusSession session = getSession(socket); if (session == null) { LOGGER.log(Level.FINE, "Ping received on already closed connection."); return; } session.getDebugContext() .appendLogMessage(LOGGER, Level.FINEST, DebugContext.Type.MESSAGE_IN, "Received ping message"); session.restartIdleTimeoutExecutor(); try { session.getBasicRemote().sendPong(bytes); } catch (IOException e) { // do nothing. // we might consider calling onError, but there should be better defined exception. } }
@Override public void sendBinary(ByteBuffer data) throws IOException { checkNotNull(data, "data"); session.getDebugContext() .appendLogMessage(LOGGER, Level.FINEST, DebugContext.Type.MESSAGE_OUT, "Sending binary message"); final Future<?> future = webSocket.sendBinary(Utils.getRemainingArray(data)); try { processFuture(future); } finally { session.restartIdleTimeoutExecutor(); } }
@Override public void sendBinary(ByteBuffer partialByte, boolean isLast) throws IOException { checkNotNull(partialByte, "partialByte"); session.getDebugContext().appendLogMessage(LOGGER, Level.FINEST, DebugContext.Type.MESSAGE_OUT, "Sending partial binary message"); final Future<?> future = webSocket.sendBinary(Utils.getRemainingArray(partialByte), isLast); try { processFuture(future); } finally { session.restartIdleTimeoutExecutor(); } }
@Override public void sendBinary(ByteBuffer data) throws IOException { checkNotNull(data, "data"); session.getDebugContext() .appendLogMessage(LOGGER, Level.FINEST, DebugContext.Type.MESSAGE_OUT, "Sending binary message"); final Future<?> future = webSocket.sendBinary(Utils.getRemainingArray(data)); try { processFuture(future); } finally { session.restartIdleTimeoutExecutor(); } }
@Override public void sendBinary(ByteBuffer partialByte, boolean isLast) throws IOException { checkNotNull(partialByte, "partialByte"); session.getDebugContext().appendLogMessage(LOGGER, Level.FINEST, DebugContext.Type.MESSAGE_OUT, "Sending partial binary message"); final Future<?> future = webSocket.sendBinary(Utils.getRemainingArray(partialByte), isLast); try { processFuture(future); } finally { session.restartIdleTimeoutExecutor(); } }