public MessageLogEntry deserialize(String jsonMessageLogEntry) { MessageLogEntry messageLogEntry = null; if (jsonMessageLogEntry != null && !jsonMessageLogEntry.isEmpty()) { try { messageLogEntry = objectMapper.readValue(jsonMessageLogEntry, MessageLogEntry.class); } catch (Exception e) { mockServerLogger.error((HttpRequest) null, e, "exception while parsing {}for MessageLogEntry", jsonMessageLogEntry); throw new RuntimeException("Exception while parsing MessageLogEntry for [" + jsonMessageLogEntry + "]", e); } } return messageLogEntry; }
public PortBinding deserialize(String jsonPortBinding) { PortBinding portBinding = null; if (jsonPortBinding != null && !jsonPortBinding.isEmpty()) { try { portBinding = objectMapper.readValue(jsonPortBinding, PortBinding.class); } catch (Exception e) { mockServerLogger.error((HttpRequest) null, e, "exception while parsing {}for PortBinding", jsonPortBinding); throw new RuntimeException("Exception while parsing PortBinding for [" + jsonPortBinding + "]", e); } } return portBinding; }
public String serialize(MessageLogEntry messageLogEntry) { try { return objectMapper .writerWithDefaultPrettyPrinter() .writeValueAsString(messageLogEntry); } catch (Exception e) { mockServerLogger.error(String.format("Exception while serializing messageLogEntry to JSON with value %s", messageLogEntry), e); throw new RuntimeException(String.format("Exception while serializing messageLogEntry to JSON with value %s", messageLogEntry), e); } }
public List<Integer> toList(String integers) { List<Integer> integerList = new ArrayList<Integer>(); for (String integer : Splitter.on(",").split(integers)) { try { integerList.add(Integer.parseInt(integer.trim())); } catch (NumberFormatException nfe) { mockServerLogger.error("NumberFormatException converting " + integer + " to integer", nfe); } } return integerList; }
public static void writeToOutputStream(byte[] data, ServletResponse response) { try { OutputStream output = response.getOutputStream(); output.write(data); output.close(); } catch (IOException ioe) { MOCK_SERVER_LOGGER.error(String.format("IOException while writing [%s] to HttpServletResponse output stream", new String(data)), ioe); throw new RuntimeException(String.format("IOException while writing [%s] to HttpServletResponse output stream", new String(data)), ioe); } }
public String serialize(VerificationSequence verificationSequence) { try { return objectMapper .writerWithDefaultPrettyPrinter() .writeValueAsString(new VerificationSequenceDTO(verificationSequence)); } catch (Exception e) { mockServerLogger.error("Exception while serializing verificationSequence to JSON with value " + verificationSequence, e); throw new RuntimeException("Exception while serializing verificationSequence to JSON with value " + verificationSequence, e); } }
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { mockServerLogger.error("web socket client caught exception", cause); final SettableFuture<String> registrationFuture = ctx.channel().attr(REGISTRATION_FUTURE).get(); if (!registrationFuture.isDone()) { registrationFuture.setException(cause); } ctx.close(); } }
public String serialize(Verification verification) { try { return objectMapper .writerWithDefaultPrettyPrinter() .writeValueAsString(new VerificationDTO(verification)); } catch (Exception e) { mockServerLogger.error("Exception while serializing verification to JSON with value " + verification, e); throw new RuntimeException("Exception while serializing verification to JSON with value " + verification, e); } }
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { if (shouldNotIgnoreException(cause)) { mockServerLogger.error("Exception caught by SOCKS proxy handler -> closing pipeline " + ctx.channel(), cause); } ctx.close(); } }
@Override public void operationComplete(ChannelFuture future) { if (future.isSuccess()) { ctx.channel().read(); } else { if (isNotSocketClosedException(future.cause())) { mockServerLogger.error("Exception while returning response for request \"" + request.method() + " " + request.uri() + "\"", future.cause()); } future.channel().close(); } } });
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { if (shouldNotIgnoreException(cause)) { mockServerLogger.error("Exception caught by upstream relay handler -> closing pipeline " + ctx.channel(), cause); } closeOnFlush(ctx.channel()); }
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { if (shouldNotIgnoreException(cause)) { mockServerLogger.error("Exception caught by port unification handler -> closing pipeline " + ctx.channel(), cause); } closeOnFlush(ctx.channel()); } }
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { if (shouldNotIgnoreException(cause)) { mockServerLogger.error("Exception caught by downstream relay handler -> closing pipeline " + ctx.channel(), cause); } closeOnFlush(ctx.channel()); }
private static Integer readIntegerProperty(String key, int defaultValue) { try { return Integer.parseInt(readPropertyHierarchically(key, "" + defaultValue)); } catch (NumberFormatException nfe) { MockServerLogger.MOCK_SERVER_LOGGER.error("NumberFormatException converting " + key + " with value [" + readPropertyHierarchically(key, "" + defaultValue) + "]", nfe); return defaultValue; } }
private static Long readLongProperty(String key, long defaultValue) { try { return Long.parseLong(readPropertyHierarchically(key, "" + defaultValue)); } catch (NumberFormatException nfe) { MockServerLogger.MOCK_SERVER_LOGGER.error("NumberFormatException converting " + key + " with value [" + readPropertyHierarchically(key, "" + defaultValue) + "]", nfe); return defaultValue; } }
private static String toJson(Object object) { String json = ""; try { json = ObjectMapperFactory.createObjectMapper().writeValueAsString(object); } catch (JsonProcessingException e) { new MockServerLogger(JsonBody.class).error("error mapping object for json body to JSON", e); } return json; }
private static SchemaFactory buildSchemaFactory() { SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); try { schemaFactory.setProperty(XMLConstants.ACCESS_EXTERNAL_DTD, "all"); schemaFactory.setProperty(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "all"); } catch (Exception e) { new MockServerLogger(XmlSchemaValidator.class).error("exception configuring schema factory", e); } return schemaFactory; }
private static List<Integer> readIntegerListProperty(String key, Integer defaultValue) { try { return INTEGER_STRING_LIST_PARSER.toList(readPropertyHierarchically(key, "" + defaultValue)); } catch (NumberFormatException nfe) { MockServerLogger.MOCK_SERVER_LOGGER.error("NumberFormatException converting " + key + " with value [" + readPropertyHierarchically(key, "" + defaultValue) + "]", nfe); return Collections.emptyList(); } }
protected HttpForwardActionResult sendRequest(HttpRequest httpRequest, @Nullable InetSocketAddress remoteAddress) { try { return new HttpForwardActionResult(httpRequest, httpClient.sendRequest(hopByHopHeaderFilter.onRequest(httpRequest), remoteAddress)); } catch (Exception e) { mockServerLogger.error(httpRequest, e, "Exception forwarding request " + httpRequest); } return notFoundFuture(httpRequest); }
private void setQueryString(HttpRequest httpRequest, QueryStringDecoder queryStringDecoder) { Parameters parameters = new Parameters(); try { parameters.withEntries(queryStringDecoder.parameters()); } catch (IllegalArgumentException iae) { mockServerLogger.error(httpRequest, "Exception while parsing query string", iae); } httpRequest.withQueryStringParameters(parameters); }