@HarnessConfiguration(name = "action") public void setAction(String action) { if (ActionType.SEND.name().equalsIgnoreCase(action)) { this.action = ActionType.SEND; } else if (ActionType.RECEIVE.name().equalsIgnoreCase(action)) { this.action = ActionType.RECEIVE; } else { getErrors() .add( new HarnessError( this, "Configuration", "Invalid action (send or receive) type:" + action)); } }
public void run(HarnessContext context) { if (getErrors().size() == 0) { if (action == null) { getErrors().add(new HarnessError(this, "Configuration", "Action not set!")); } } if (getErrors().size() == 0) { log.info("Running action " + action); MessageEndpoint endpoint = buildEndpoint(); if (ActionType.SEND.equals(action)) { try { message = buildMessage(); message.getProperties().putAll(properties); if (getMessage() != null && log.isTraceEnabled()) { log.trace("Sending message:" + String.valueOf(getMessage().getBody())); } endpoint.send(message); } catch (SendException e) { log.error("Problem sending message", e); getErrors().add(new HarnessError(this, "Problem sending message", e)); } } else if (ActionType.RECEIVE.equals(action)) { try { message = endpoint.read(); if (getMessage() != null && log.isTraceEnabled()) { log.trace("Pulled message:" + String.valueOf(getMessage().getBody())); } } catch (SendException e) { log.error("Problem reading message", e); getErrors().add(new HarnessError(this, "Problem reading message", e)); } } } else { log.info("There were errors, not processing send / receive"); } }