@Override public boolean matches(final HttpRequest context, Boolean matched) { boolean result = false; if (matcher == null) { result = true; } else if (matched != null) { result = matched == matcher; } if (!result) { mockServerLogger.trace(context, "Failed to match [{}] with [{}]", matched, this.matcher); } return result; }
@Override public void channelInactive(ChannelHandlerContext ctx) { mockServerLogger.trace("web socket client disconnected"); }
public void trace(final String message, final Object... arguments) { trace(null, message, arguments); }
public boolean matches(final HttpRequest context, byte[] matched) { boolean result = false; if (matcher == null || matcher.length == 0 || Arrays.equals(matcher, matched)) { result = true; } if (!result) { mockServerLogger.trace(context, "Failed to perform binary match [{}] with [{}] because {}", (Object) matched); } return not != result; }
private Integer getFirstBoundPort(List<Future<Channel>> channelFutures) { for (Future<Channel> channelOpened : channelFutures) { try { return ((InetSocketAddress) channelOpened.get(2, SECONDS).localAddress()).getPort(); } catch (Exception e) { mockServerLogger.trace("Exception while retrieving port from channel future, ignoring port for this channel", e); } } return -1; }
private List<Integer> getBoundPorts(List<Future<Channel>> channelFutures) { List<Integer> ports = new ArrayList<>(); for (Future<Channel> channelOpened : channelFutures) { try { ports.add(((InetSocketAddress) channelOpened.get(3, SECONDS).localAddress()).getPort()); } catch (Exception e) { mockServerLogger.trace("Exception while retrieving port from channel future, ignoring port for this channel", e); } } return ports; }
public boolean matches(final HttpRequest context, String matched) { boolean result = false; try { String validation = jsonSchemaValidator.isValid(matched); result = validation.isEmpty(); if (!result) { mockServerLogger.trace(context, "Failed to match JSON: {}with schema: {}because: {}", matched, this.schema, validation); } } catch (Exception e) { mockServerLogger.trace(context, "Failed to match JSON: {}with schema: {}because: {}", matched, this.schema, e.getMessage()); } return not != result; }
public boolean matches(final HttpRequest context, String matched) { boolean result = false; try { String validation = xmlSchemaValidator.isValid(matched); result = validation.isEmpty(); if (!result) { mockServerLogger.trace(context, "Failed to match [{}] with schema [{}] because [{}]", matched, this.schema, validation); } } catch (Exception e) { mockServerLogger.trace(context, "Failed to match [{}] with schema [{}] because [{}]", matched, this.schema, e.getMessage()); } return not != result; }
public XPathMatcher(MockServerLogger mockServerLogger, String matcher) { this.mockServerLogger = mockServerLogger; this.matcher = matcher; if (StringUtils.isNotBlank(matcher)) { try { xpathExpression = XPathFactory.newInstance().newXPath().compile(matcher); } catch (XPathExpressionException e) { mockServerLogger.trace("Error while creating xpath expression for [" + matcher + "] assuming matcher not xpath - " + e.getMessage(), e); } } }
public JsonPathMatcher(MockServerLogger mockServerLogger, String matcher) { this.mockServerLogger = mockServerLogger; this.matcher = matcher; if (StringUtils.isNotBlank(matcher)) { try { jsonPath = JsonPath.compile(matcher); } catch (Throwable throwable) { mockServerLogger.trace("Error while creating xpath expression for [" + matcher + "] assuming matcher not xpath - " + throwable.getMessage(), throwable); } } }
public boolean matches(final HttpRequest context, final String matched) { boolean result = false; if (xpathExpression == null) { mockServerLogger.trace(context, "Attempting match against null XPath Expression for [" + matched + "]" + new RuntimeException("Attempting match against null XPath Expression for [" + matched + "]")); } else if (matcher.equals(matched)) { result = true; } else if (matched != null) { try { result = (Boolean) xpathExpression.evaluate(stringToXmlDocumentParser.buildDocument(matched, new StringToXmlDocumentParser.ErrorLogger() { @Override public void logError(final String matched, final Exception exception) { mockServerLogger.warn(context, "SAXParseException while performing match between [" + matcher + "] and [" + matched + "]", exception); } }), XPathConstants.BOOLEAN); } catch (Exception e) { mockServerLogger.trace(context, "Error while matching xpath [" + matcher + "] against string [" + matched + "] assuming no match - " + e.getMessage()); } } if (!result) { mockServerLogger.trace("Failed to match [{}] with [{}]", matched, matcher); } return not != result; }
public boolean matches(final HttpRequest context, String matched) { boolean result = false; if (jsonPath == null) { mockServerLogger.trace(context, "Attempting match against null XPath Expression for [" + matched + "]" + new RuntimeException("Attempting match against null XPath Expression for [" + matched + "]")); } else if (matcher.equals(matched)) { result = true; } else if (matched != null) { try { result = !jsonPath.<JSONArray>read(matched).isEmpty(); } catch (Exception e) { mockServerLogger.trace(context, "Failed to match JSON: {}with JsonPath: {}because: {}", matched, jsonPath, e.getMessage()); } } if (!result) { mockServerLogger.trace("Failed to match [{}] with [{}]", matched, matcher); } return not != result; }
public boolean matches(final HttpRequest context, String matched) { boolean result = false; if (matcher.matches(context, parseString(matched))) { result = true; } if (!result) { mockServerLogger.trace(context, "Failed to match [{}] with [{}]", matched, this.matcher); } return not != result; }
public boolean matches(final HttpRequest context, KeysAndValues values) { boolean result = false; if (hashMap == null || hashMap.isEmpty() || values == null) { result = true; } else if (values.toCaseInsensitiveRegexMultiMap().containsAll(hashMap)) { result = true; } else { mockServerLogger.trace(context, "Map [{}] is not a subset of {}", this.hashMap, values); } return not != result; } }
public boolean matches(final HttpRequest context, KeysToMultiValues values) { boolean result = false; if (multiMap == null || multiMap.isEmpty()) { result = true; } else if (values.toCaseInsensitiveRegexMultiMap().containsAll(multiMap)) { result = true; } else { mockServerLogger.trace(context, "Map [{}] is not a subset of {}", multiMap, values); } return not != result; }
public boolean matches(final HttpRequest context, NottableString matched) { boolean result = false; if (diffBuilder != null) { try { Diff diff = diffBuilder.withTest(Input.fromString(normaliseXmlString(matched.getValue()))).build(); result = !diff.hasDifferences(); if (!result) { mockServerLogger.trace("Failed to match [{}] with schema [{}] because [{}]", matched, this.matcher, diff.toString()); } } catch (Exception e) { mockServerLogger.trace(context, "Failed to match [{}] with schema [{}] because [{}]", matched, this.matcher, e.getMessage()); } } return matcher.isNot() != (not != result); }
public boolean matches(final HttpRequest context, NottableString matched) { boolean result = false; if (matches(matcher.getValue(), matched.getValue(), false)) { result = true; } if (!result) { mockServerLogger.trace(context, "Failed to match [{}] with [{}]", matched, this.matcher); } return matched.isNot() != (matcher.isNot() != (not != result)); }
public boolean matches(final HttpRequest context, NottableString matched) { boolean result = false; if (matches(matcher.getValue(), matched.getValue(), false)) { result = true; } if (!result) { mockServerLogger.trace(context, "Failed to match [{}] with [{}]", matched, this.matcher); } return matched.isNot() != (matcher.isNot() != (not != result)); }
public boolean matches(final HttpRequest context, NottableString matched) { boolean result = false; if (matches(matcher.getValue(), matched.getValue(), false)) { result = true; } if (!result) { mockServerLogger.trace(context, "Failed to match [{}] with [{}]", matched, this.matcher); } return matched.isNot() != (matcher.isNot() != (not != result)); }
private void returnNotFound(ResponseWriter responseWriter, HttpRequest request) { HttpResponse response = notFoundResponse(); if (request.getHeaders().containsEntry("x-forwarded-by", "MockServer")) { response.withHeader("x-forwarded-by", "MockServer"); mockServerLogger.trace(request, "no expectation for:{}returning response:{}", request, notFoundResponse()); } else { httpStateHandler.log(new RequestLogEntry(request)); mockServerLogger.info(EXPECTATION_NOT_MATCHED, request, "no expectation for:{}returning response:{}", request, notFoundResponse()); } responseWriter.writeResponse(request, response, false); } }