class JsonWellFormedChecker extends FixedForwardPipe {

	@Override
	public PipeRunResult doPipe(Message message, IPipeLineSession session) throws PipeRunException {
		PipeForward forward = findForward("success");

		String input;
		try {
			input = message.asString();
		} catch (IOException e) {
			throw new PipeRunException(this, getLogPrefix(session)+"cannot open stream", e);
		}
		if (input.isEmpty()) {
			forward = findForward("failure");
		} else {
			try {
				new JSONObject(input);
			} catch (JSONException ex) {
				try {
					new JSONArray(input);
				} catch (JSONException ex1) {
					forward = findForward("failure");
				}
			}
		}
		return new PipeRunResult(forward, message);
	}

}