@Override public void logError(final String matched, final Exception exception) { mockServerLogger.warn(context, "SAXParseException while performing match between [" + matcher + "] and [" + matched + "]", exception); } }), XPathConstants.BOOLEAN);
public void warn(final String message) { warn((HttpRequest) null, message); }
public void warn(final String message, final Object... arguments) { warn(null, message, arguments); }
private SSLContext getSSLContextInstance() throws NoSuchAlgorithmException { try { MOCK_SERVER_LOGGER.debug(SERVER_CONFIGURATION, "Using protocol {}", SSL_CONTEXT_PROTOCOL); return SSLContext.getInstance(SSL_CONTEXT_PROTOCOL); } catch (NoSuchAlgorithmException e) { MOCK_SERVER_LOGGER.warn("Protocol {} not available, falling back to {}", SSL_CONTEXT_PROTOCOL, SSL_CONTEXT_FALLBACK_PROTOCOL); return SSLContext.getInstance(SSL_CONTEXT_FALLBACK_PROTOCOL); } }
public static Charset getCharsetFromContentTypeHeader(String contentType) { Charset charset = DEFAULT_HTTP_CHARACTER_SET; if (contentType != null) { String charsetName = StringUtils.substringAfterLast(contentType, CHARSET.toString() + (char) HttpConstants.EQUALS).replaceAll("\"", ""); if (!Strings.isNullOrEmpty(charsetName)) { try { charset = Charset.forName(charsetName); } catch (UnsupportedCharsetException uce) { MOCK_SERVER_LOGGER.warn("Unsupported character set {} in Content-Type header: {}.", StringUtils.substringAfterLast(contentType, CHARSET.toString() + HttpConstants.EQUALS), contentType); } catch (IllegalCharsetNameException icne) { MOCK_SERVER_LOGGER.warn("Illegal character set {} in Content-Type header: {}.", StringUtils.substringAfterLast(contentType, CHARSET.toString() + HttpConstants.EQUALS), contentType); } } else if (UTF_8_CONTENT_TYPES.contains(contentType)) { charset = CharsetUtil.UTF_8; } } return charset; } }
@Override public void channelRead0(ChannelHandlerContext ctx, Object msg) { Channel ch = ctx.channel(); if (msg instanceof FullHttpResponse) { FullHttpResponse httpResponse = (FullHttpResponse) msg; final SettableFuture<String> registrationFuture = ch.attr(REGISTRATION_FUTURE).get(); if (httpResponse.headers().contains(UPGRADE, WEBSOCKET, true) && !handshaker.isHandshakeComplete()) { handshaker.finishHandshake(ch, httpResponse); final String clientRegistrationId = httpResponse.headers().get("X-CLIENT-REGISTRATION-ID"); registrationFuture.set(clientRegistrationId); mockServerLogger.trace("web socket client " + clientRegistrationId + " connected!"); } else if (httpResponse.status().equals(HttpResponseStatus.NOT_IMPLEMENTED)) { String message = readRequestBody(httpResponse); registrationFuture.setException(new WebSocketException(message)); mockServerLogger.warn(message); } else { registrationFuture.setException(new WebSocketException("Unsupported web socket message " + new FullHttpResponseToMockServerResponse().mapMockServerResponseToFullHttpResponse(httpResponse))); } } else if (msg instanceof WebSocketFrame) { WebSocketFrame frame = (WebSocketFrame) msg; if (frame instanceof TextWebSocketFrame) { webSocketClient.receivedTextWebSocketFrame((TextWebSocketFrame) frame); } else if (frame instanceof PingWebSocketFrame) { ctx.write(new PongWebSocketFrame(frame.content().retain())); } else if (frame instanceof CloseWebSocketFrame) { mockServerLogger.trace("web socket client received request to close"); ch.close(); } } }
/** * Stop MockServer gracefully (only support for Netty version, not supported for WAR version) */ public MockServerClient stop(boolean ignoreFailure) { MockServerEventBus.getInstance().publish(EventType.STOP); try { sendRequest(request().withMethod("PUT").withPath(calculatePath("stop"))); if (isRunning()) { for (int i = 0; isRunning() && i < 50; i++) { TimeUnit.MILLISECONDS.sleep(5); } } } catch (RejectedExecutionException ree) { mockServerLogger.trace("Request rejected because closing down but logging at trace level for information just in case due to some other actual error " + ree); } catch (Exception e) { if (!ignoreFailure) { mockServerLogger.warn("Failed to send stop request to MockServer " + e.getMessage()); } } if (!eventLoopGroup.isShuttingDown()) { eventLoopGroup.shutdownGracefully(); } return clientClass.cast(this); }
@Override public void logError(final String matched, final Exception exception) { mockServerLogger.warn(context, "SAXParseException while performing match between [" + matcher + "] and [" + matched + "]", exception); } }), XPathConstants.BOOLEAN);
public void warn(final String message, final Object... arguments) { warn(null, message, arguments); }
public void warn(final String message) { warn((HttpRequest) null, message); }
private SSLContext getSSLContextInstance() throws NoSuchAlgorithmException { try { MOCK_SERVER_LOGGER.debug(SERVER_CONFIGURATION, "Using protocol {}", SSL_CONTEXT_PROTOCOL); return SSLContext.getInstance(SSL_CONTEXT_PROTOCOL); } catch (NoSuchAlgorithmException e) { MOCK_SERVER_LOGGER.warn("Protocol {} not available, falling back to {}", SSL_CONTEXT_PROTOCOL, SSL_CONTEXT_FALLBACK_PROTOCOL); return SSLContext.getInstance(SSL_CONTEXT_FALLBACK_PROTOCOL); } }
public static Charset getCharsetFromContentTypeHeader(String contentType) { Charset charset = DEFAULT_HTTP_CHARACTER_SET; if (contentType != null) { String charsetName = StringUtils.substringAfterLast(contentType, CHARSET.toString() + (char) HttpConstants.EQUALS).replaceAll("\"", ""); if (!Strings.isNullOrEmpty(charsetName)) { try { charset = Charset.forName(charsetName); } catch (UnsupportedCharsetException uce) { MOCK_SERVER_LOGGER.warn("Unsupported character set {} in Content-Type header: {}.", StringUtils.substringAfterLast(contentType, CHARSET.toString() + HttpConstants.EQUALS), contentType); } catch (IllegalCharsetNameException icne) { MOCK_SERVER_LOGGER.warn("Illegal character set {} in Content-Type header: {}.", StringUtils.substringAfterLast(contentType, CHARSET.toString() + HttpConstants.EQUALS), contentType); } } else if (UTF_8_CONTENT_TYPES.contains(contentType)) { charset = CharsetUtil.UTF_8; } } return charset; } }
/** * Stop MockServer gracefully (only support for Netty version, not supported for WAR version) */ public MockServerClient stop(boolean ignoreFailure) { MockServerEventBus.getInstance().publish(EventType.STOP); try { sendRequest(request().withMethod("PUT").withPath(calculatePath("stop"))); if (isRunning()) { for (int i = 0; isRunning() && i < 50; i++) { TimeUnit.MILLISECONDS.sleep(5); } } } catch (RejectedExecutionException ree) { mockServerLogger.trace("Request rejected because closing down but logging at trace level for information just in case due to some other actual error " + ree); } catch (Exception e) { if (!ignoreFailure) { mockServerLogger.warn("Failed to send stop request to MockServer " + e.getMessage()); } } if (!eventLoopGroup.isShuttingDown()) { eventLoopGroup.shutdownGracefully(); } return clientClass.cast(this); }
@Override public void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception { Channel ch = ctx.channel(); if (msg instanceof FullHttpResponse) { FullHttpResponse httpResponse = (FullHttpResponse) msg; if (httpResponse.headers().contains(UPGRADE, WEBSOCKET, true) && !handshaker.isHandshakeComplete()) { handshaker.finishHandshake(ch, httpResponse); webSocketClient.registrationFuture().set(httpResponse.headers().get("X-CLIENT-REGISTRATION-ID")); mockServerLogger.trace("web socket client " + webSocketClient.registrationFuture().get() + " connected!"); } else if (httpResponse.status().equals(HttpResponseStatus.NOT_IMPLEMENTED)) { String message = readRequestBody(httpResponse); webSocketClient.registrationFuture().setException(new WebSocketException(message)); mockServerLogger.warn(message); } else { throw new WebSocketException("Unsupported web socket message " + new FullHttpResponseToMockServerResponse().mapMockServerResponseToFullHttpResponse(httpResponse)); } } else if (msg instanceof WebSocketFrame) { WebSocketFrame frame = (WebSocketFrame) msg; if (frame instanceof TextWebSocketFrame) { webSocketClient.receivedTextWebSocketFrame((TextWebSocketFrame) frame); } else if (frame instanceof PingWebSocketFrame) { ctx.write(new PongWebSocketFrame(frame.content().retain())); } else if (frame instanceof CloseWebSocketFrame) { mockServerLogger.trace("web socket client received request to close"); ch.close(); } } }