@Test public void transformMessage() throws TransformerException { final MuleMessage muleMessageMock = mock(MuleMessage.class); transformer = new ValidateSenderIdTransformer() { protected X509CertificateEvaluator getX509CertificateEvaluator(String property) { X509CertificateEvaluator evaluator = mock(X509CertificateEvaluator.class); evaluator.setPropertyName("CN"); when(evaluator.evaluate(X509CertificateEvaluator.EXPR_SENDERID, muleMessageMock)).thenReturn("1234"); return evaluator; }; }; transformer.setValidSenderIds("1234"); transformer.transformMessage(muleMessageMock, null); verify(muleMessageMock, times(1)).setSessionProperty("Sender", "1234"); }
@Override public Object transformMessage(MuleMessage message, String outputEncoding) throws TransformerException { X509CertificateEvaluator eval = this.getX509CertificateEvaluator(senderIdPropertyName); String senderId = (String) eval.evaluate(X509CertificateEvaluator.EXPR_SENDERID, message); if (senderId != null) { message.setSessionProperty("Sender", senderId); } else { message.setSessionProperty("Sender", ""); } if (validSenderIds.contains(senderId)) { log.debug("{} is a valid senderId!", senderId); } else { logAndThrowError("Invalid senderId [" + senderId + "], allowed senderIds are: " + validSenderIds); } return message; }
ValidateSenderIdTransformer extends AbstractMessageTransformer implements MuleContextAware { @Override public Object transformMessage(MuleMessage message, String outputEncoding) throws TransformerException { X509CertificateEvaluator eval = this.getX509CertificateEvaluator(senderIdPropertyName); String senderId = (String) eval.evaluate(X509CertificateEvaluator.EXPR_SENDERID, message); if (senderId != null) { message.setSessionProperty("Sender", senderId); } else { message.setSessionProperty("Sender", ""); } if (validSenderIds.contains(senderId)) { log.debug("{} is a valid senderId!", senderId); } else { logAndThrowError("Invalid senderId [" + senderId + "], allowed senderIds are: " + validSenderIds); } return message; } }
ValidateSenderIdTransformer extends AbstractMessageTransformer implements MuleContextAware { @Override public Object transformMessage(MuleMessage message, String outputEncoding) throws TransformerException { X509CertificateEvaluator eval = this.getX509CertificateEvaluator(senderIdPropertyName); String senderId = (String) eval.evaluate(X509CertificateEvaluator.EXPR_SENDERID, message); if (senderId != null) { message.setSessionProperty("Sender", senderId); } else { message.setSessionProperty("Sender", ""); } if (validSenderIds.contains(senderId)) { log.debug("{} is a valid senderId!", senderId); } else { logAndThrowError("Invalid senderId [" + senderId + "], allowed senderIds are: " + validSenderIds); } return message; }  }
ValidateSenderIdTransformer extends AbstractMessageTransformer implements MuleContextAware { @Override public Object transformMessage(MuleMessage message, String outputEncoding) throws TransformerException { X509CertificateEvaluator eval = this.getX509CertificateEvaluator(senderIdPropertyName); String senderId = (String) eval.evaluate(X509CertificateEvaluator.EXPR_SENDERID, message); if (senderId != null) { message.setSessionProperty("Sender", senderId); } else { message.setSessionProperty("Sender", ""); } if (validSenderIds.contains(senderId)) { log.debug("{} is a valid senderId!", senderId); } else { logAndThrowError("Invalid senderId [" + senderId + "], allowed senderIds are: " + validSenderIds); } return message; }  void setSenderIdPropertyName(String senderIdPropertyName); void setValidSenderIds(String validSenderIds); @Override Object transformMessage(MuleMessage message, String outputEncoding); }
ValidateSenderIdTransformer extends AbstractMessageTransformer implements MuleContextAware { @Override public Object transformMessage(MuleMessage message, String outputEncoding) throws TransformerException { X509CertificateEvaluator eval = this.getX509CertificateEvaluator(senderIdPropertyName); String senderId = (String) eval.evaluate(X509CertificateEvaluator.EXPR_SENDERID, message); if (senderId != null) { message.setSessionProperty("Sender", senderId); } else { message.setSessionProperty("Sender", ""); } if (validSenderIds.contains(senderId)) { log.debug("{} is a valid senderId!", senderId); } else { logAndThrowError("Invalid senderId [" + senderId + "], allowed senderIds are: " + validSenderIds); } return message; }  void setSenderIdPropertyName(String senderIdPropertyName); void setValidSenderIds(String validSenderIds); @Override Object transformMessage(MuleMessage message, String outputEncoding);  }