use of nl.nn.adapterframework.core.IValidator in project iaf by ibissource.
the class MessageSendingPipe method configure.
/**
* Checks whether a sender is defined for this pipe.
*/
@Override
public void configure() throws ConfigurationException {
super.configure();
msgLog = LogUtil.getMsgLogger(getAdapter(), this);
if (StringUtils.isNotEmpty(getStubFilename())) {
URL stubUrl;
try {
stubUrl = ClassUtils.getResourceURL(this, getStubFilename());
} catch (Throwable e) {
throw new ConfigurationException("got exception finding resource for stubfile [" + getStubFilename() + "]", e);
}
if (stubUrl == null) {
throw new ConfigurationException("could not find resource for stubfile [" + getStubFilename() + "]");
}
try {
returnString = Misc.resourceToString(stubUrl, Misc.LINE_SEPARATOR);
} catch (Throwable e) {
throw new ConfigurationException("got exception loading stubfile [" + getStubFilename() + "] from resource [" + stubUrl.toExternalForm() + "]", e);
}
} else {
propagateName();
if (getSender() == null) {
throw new ConfigurationException("no sender defined ");
}
// because sender might not have been set when addPipe() is called.
if (getParameterList() != null && getSender() instanceof ISenderWithParameters) {
for (Parameter p : getParameterList()) {
if (!p.getName().equals(STUBFILENAME)) {
((ISenderWithParameters) getSender()).addParameter(p);
}
}
}
try {
// In order to be able to suppress 'xxxSender may cause potential SQL injections!' config warnings
if (sender instanceof DirectQuerySender) {
((DirectQuerySender) getSender()).configure(getAdapter());
} else {
getSender().configure();
}
} catch (ConfigurationException e) {
throw new ConfigurationException("while configuring sender", e);
}
if (getSender() instanceof HasPhysicalDestination) {
log.info(getLogPrefix(null) + "has sender on " + ((HasPhysicalDestination) getSender()).getPhysicalDestinationName());
}
if (getListener() != null) {
if (getSender().isSynchronous()) {
throw new ConfigurationException("cannot have listener with synchronous sender");
}
try {
getListener().configure();
} catch (ConfigurationException e) {
throw new ConfigurationException("while configuring listener", e);
}
if (getListener() instanceof HasPhysicalDestination) {
log.info(getLogPrefix(null) + "has listener on " + ((HasPhysicalDestination) getListener()).getPhysicalDestinationName());
}
}
if (!(getHideMethod().equalsIgnoreCase("all")) && (!(getHideMethod().equalsIgnoreCase("firstHalf")))) {
throw new ConfigurationException("invalid value for hideMethod [" + getHideMethod() + "], must be 'all' or 'firstHalf'");
}
if (isCheckXmlWellFormed() || StringUtils.isNotEmpty(getCheckRootTag())) {
if (findForward(ILLEGAL_RESULT_FORWARD) == null)
throw new ConfigurationException("has no forward with name [illegalResult]");
}
if (!ConfigurationUtils.isConfigurationStubbed(getConfigurationClassLoader())) {
if (StringUtils.isNotEmpty(getTimeOutOnResult())) {
throw new ConfigurationException("timeOutOnResult only allowed in stub mode");
}
if (StringUtils.isNotEmpty(getExceptionOnResult())) {
throw new ConfigurationException("exceptionOnResult only allowed in stub mode");
}
}
if (getMaxRetries() > 0) {
if (getRetryMinInterval() < MIN_RETRY_INTERVAL) {
ConfigurationWarnings.add(this, log, "retryMinInterval [" + getRetryMinInterval() + "] should be greater than or equal to [" + MIN_RETRY_INTERVAL + "], assuming the lower limit");
setRetryMinInterval(MIN_RETRY_INTERVAL);
}
if (getRetryMaxInterval() > MAX_RETRY_INTERVAL) {
ConfigurationWarnings.add(this, log, "retryMaxInterval [" + getRetryMaxInterval() + "] should be less than or equal to [" + MAX_RETRY_INTERVAL + "], assuming the upper limit");
setRetryMaxInterval(MAX_RETRY_INTERVAL);
}
if (getRetryMaxInterval() < getRetryMinInterval()) {
ConfigurationWarnings.add(this, log, "retryMaxInterval [" + getRetryMaxInterval() + "] should be greater than or equal to [" + getRetryMinInterval() + "], assuming the lower limit");
setRetryMaxInterval(getRetryMinInterval());
}
}
}
ITransactionalStorage messageLog = getMessageLog();
if (messageLog == null) {
if (StringUtils.isEmpty(getStubFilename()) && !getSender().isSynchronous() && getListener() == null && !(getSender() instanceof nl.nn.adapterframework.senders.IbisLocalSender)) {
// sender is asynchronous and not a local sender, but has no messageLog
boolean suppressIntegrityCheckWarning = ConfigurationWarnings.isSuppressed(SuppressKeys.INTEGRITY_CHECK_SUPPRESS_KEY, getAdapter());
if (!suppressIntegrityCheckWarning) {
boolean legacyCheckMessageLog = AppConstants.getInstance(getConfigurationClassLoader()).getBoolean("messageLog.check", true);
if (!legacyCheckMessageLog) {
ConfigurationWarnings.add(this, log, "Suppressing integrityCheck warnings by setting property 'messageLog.check=false' has been replaced by by setting property 'warnings.suppress.integrityCheck=true'");
suppressIntegrityCheckWarning = true;
}
}
if (!suppressIntegrityCheckWarning) {
ConfigurationWarnings.add(this, log, "asynchronous sender [" + getSender().getName() + "] without sibling listener has no messageLog. " + "Service Managers will not be able to perform an integrity check (matching messages received by the adapter to messages sent by this pipe). " + "This warning can be suppressed globally by setting property 'warnings.suppress.integrityCheck=true', " + "or for this adapter only by setting property 'warnings.suppress.integrityCheck." + getAdapter().getName() + "=true'");
}
}
} else {
if (StringUtils.isNotEmpty(getHideRegex()) && StringUtils.isEmpty(messageLog.getHideRegex())) {
messageLog.setHideRegex(getHideRegex());
messageLog.setHideMethod(getHideMethod());
}
messageLog.configure();
if (messageLog instanceof HasPhysicalDestination) {
String msg = getLogPrefix(null) + "has messageLog in " + ((HasPhysicalDestination) messageLog).getPhysicalDestinationName();
log.info(msg);
if (getAdapter() != null)
getAdapter().getMessageKeeper().add(msg);
}
if (StringUtils.isNotEmpty(getAuditTrailXPath())) {
auditTrailTp = TransformerPool.configureTransformer(getLogPrefix(null), this, getAuditTrailNamespaceDefs(), getAuditTrailXPath(), null, OutputType.TEXT, false, null);
}
if (StringUtils.isNotEmpty(getCorrelationIDXPath()) || StringUtils.isNotEmpty(getCorrelationIDStyleSheet())) {
correlationIDTp = TransformerPool.configureTransformer(getLogPrefix(null), this, getCorrelationIDNamespaceDefs(), getCorrelationIDXPath(), getCorrelationIDStyleSheet(), OutputType.TEXT, false, null);
}
if (StringUtils.isNotEmpty(getLabelXPath()) || StringUtils.isNotEmpty(getLabelStyleSheet())) {
labelTp = TransformerPool.configureTransformer(getLogPrefix(null), this, getLabelNamespaceDefs(), getLabelXPath(), getLabelStyleSheet(), OutputType.TEXT, false, null);
}
}
if (StringUtils.isNotEmpty(getRetryXPath())) {
retryTp = TransformerPool.configureTransformer(getLogPrefix(null), this, getRetryNamespaceDefs(), getRetryXPath(), null, OutputType.TEXT, false, null);
}
IValidator inputValidator = getInputValidator();
IValidator outputValidator = getOutputValidator();
if (inputValidator != null && outputValidator == null && inputValidator instanceof IDualModeValidator) {
outputValidator = ((IDualModeValidator) inputValidator).getResponseValidator();
setOutputValidator(outputValidator);
}
if (inputValidator != null) {
PipeForward pf = new PipeForward();
pf.setName(PipeForward.SUCCESS_FORWARD_NAME);
inputValidator.registerForward(pf);
configure(inputValidator);
}
if (outputValidator != null) {
PipeForward pf = new PipeForward();
pf.setName(PipeForward.SUCCESS_FORWARD_NAME);
outputValidator.registerForward(pf);
configure(outputValidator);
}
if (getInputWrapper() != null) {
PipeForward pf = new PipeForward();
pf.setName(PipeForward.SUCCESS_FORWARD_NAME);
getInputWrapper().registerForward(pf);
if (getInputWrapper() instanceof EsbSoapWrapperPipe) {
EsbSoapWrapperPipe eswPipe = (EsbSoapWrapperPipe) getInputWrapper();
ISender sender = getSender();
eswPipe.retrievePhysicalDestinationFromSender(sender);
}
configure(getInputWrapper());
}
if (getOutputWrapper() != null) {
PipeForward pf = new PipeForward();
pf.setName(PipeForward.SUCCESS_FORWARD_NAME);
getOutputWrapper().registerForward(pf);
configure(getOutputWrapper());
}
registerEvent(PIPE_TIMEOUT_MONITOR_EVENT);
registerEvent(PIPE_CLEAR_TIMEOUT_MONITOR_EVENT);
registerEvent(PIPE_EXCEPTION_MONITOR_EVENT);
}
use of nl.nn.adapterframework.core.IValidator in project iaf by ibissource.
the class CorePipeLineProcessor method processPipeLine.
@Override
public PipeLineResult processPipeLine(PipeLine pipeLine, String messageId, Message message, PipeLineSession pipeLineSession, String firstPipe) throws PipeRunException {
if (message.isEmpty()) {
if (StringUtils.isNotEmpty(pipeLine.getAdapterToRunBeforeOnEmptyInput())) {
log.debug("running adapterBeforeOnEmptyInput");
IbisManager ibisManager = applicationContext.getBean(IbisManager.class);
IAdapter adapter = ibisManager.getRegisteredAdapter(pipeLine.getAdapterToRunBeforeOnEmptyInput());
if (adapter == null) {
log.warn("adapterToRunBefore with specified name [" + pipeLine.getAdapterToRunBeforeOnEmptyInput() + "] could not be retrieved");
} else {
PipeLineResult plr = adapter.processMessage(messageId, message, pipeLineSession);
if (plr == null || !plr.isSuccessful()) {
throw new PipeRunException(null, "adapterToRunBefore [" + pipeLine.getAdapterToRunBeforeOnEmptyInput() + "] ended with state [" + (plr == null ? "null" : plr.getState()) + "]");
}
message = plr.getResult();
log.debug("input after running adapterBeforeOnEmptyInput [" + message + "]");
}
}
}
// ready indicates whether the pipeline processing is complete
boolean ready = false;
// get the first pipe to run
IForwardTarget forwardTarget = pipeLine.getPipe(pipeLine.getFirstPipe());
boolean inputValidateError = false;
IValidator inputValidator = pipeLine.getInputValidator();
if (inputValidator != null) {
log.debug("validating input");
PipeRunResult validationResult = pipeProcessor.processPipe(pipeLine, inputValidator, message, pipeLineSession);
if (validationResult != null) {
if (!validationResult.isSuccessful()) {
forwardTarget = pipeLine.resolveForward(inputValidator, validationResult.getPipeForward());
log.warn("forwarding execution flow to [" + forwardTarget.getName() + "] due to validation fault");
inputValidateError = true;
}
Message validatedMessage = validationResult.getResult();
if (!validatedMessage.isEmpty()) {
message = validatedMessage;
}
}
}
if (!inputValidateError) {
IPipe inputWrapper = pipeLine.getInputWrapper();
if (inputWrapper != null) {
log.debug("wrapping input");
PipeRunResult wrapResult = pipeProcessor.processPipe(pipeLine, inputWrapper, message, pipeLineSession);
if (wrapResult != null && !wrapResult.isSuccessful()) {
forwardTarget = pipeLine.resolveForward(inputWrapper, wrapResult.getPipeForward());
log.warn("forwarding execution flow to [" + forwardTarget.getName() + "] due to wrap fault");
} else {
message = wrapResult.getResult();
}
log.debug("input after wrapping [" + message + "]");
}
}
long size = message.size();
if (size > 0) {
pipeLine.getRequestSizeStats().addValue(size);
}
if (pipeLine.isStoreOriginalMessageWithoutNamespaces()) {
String input;
try {
input = message.asString();
} catch (IOException e) {
throw new PipeRunException(null, "cannot open stream", e);
}
if (XmlUtils.isWellFormed(input)) {
IPipe pipe = forwardTarget instanceof IPipe ? (IPipe) forwardTarget : null;
try {
TransformerPool tpRemoveNamespaces = XmlUtils.getRemoveNamespacesTransformerPool(true, true);
String xsltResult = tpRemoveNamespaces.transform(message, null);
pipeLineSession.put("originalMessageWithoutNamespaces", xsltResult);
} catch (IOException e) {
throw new PipeRunException(pipe, "cannot retrieve removeNamespaces", e);
} catch (ConfigurationException ce) {
throw new PipeRunException(pipe, "got error creating transformer for removeNamespaces", ce);
} catch (TransformerException te) {
throw new PipeRunException(pipe, "got error transforming removeNamespaces", te);
} catch (SAXException se) {
throw new PipeRunException(pipe, "caught SAXException", se);
}
} else {
log.warn("original message is not well-formed");
pipeLineSession.put("originalMessageWithoutNamespaces", message);
}
}
PipeLineResult pipeLineResult = new PipeLineResult();
boolean outputValidationFailed = false;
try {
while (!ready) {
if (forwardTarget instanceof PipeLineExit) {
PipeLineExit plExit = (PipeLineExit) forwardTarget;
if (!plExit.isEmptyResult()) {
boolean outputWrapError = false;
IPipe outputWrapper = pipeLine.getOutputWrapper();
if (outputWrapper != null) {
log.debug("wrapping PipeLineResult");
PipeRunResult wrapResult = pipeProcessor.processPipe(pipeLine, outputWrapper, message, pipeLineSession);
if (wrapResult != null && !wrapResult.isSuccessful()) {
forwardTarget = pipeLine.resolveForward(outputWrapper, wrapResult.getPipeForward());
log.warn("forwarding execution flow to [" + forwardTarget.getName() + "] due to wrap fault");
outputWrapError = true;
} else {
log.debug("wrap succeeded");
message = wrapResult.getResult();
}
if (log.isDebugEnabled())
log.debug("PipeLineResult after wrapping: " + (message == null ? "<null>" : "(" + message.getClass().getSimpleName() + ") [" + message + "]"));
}
if (!outputWrapError) {
IValidator outputValidator = pipeLine.getOutputValidator();
if (outputValidator != null) {
if (outputValidationFailed) {
log.debug("validating error message after PipeLineResult validation failed");
} else {
log.debug("validating PipeLineResult");
}
String exitSpecificResponseRoot = plExit.getResponseRoot();
PipeRunResult validationResult = pipeProcessor.validate(pipeLine, outputValidator, message, pipeLineSession, exitSpecificResponseRoot);
if (!validationResult.isSuccessful()) {
if (!outputValidationFailed) {
outputValidationFailed = true;
forwardTarget = pipeLine.resolveForward(outputValidator, validationResult.getPipeForward());
log.warn("forwarding execution flow to [" + forwardTarget.getName() + "] due to validation fault");
} else {
// to avoid endless looping
log.warn("validation of error message by validator [" + outputValidator.getName() + "] failed, returning result anyhow");
message = validationResult.getResult();
ready = true;
}
} else {
log.debug("validation succeeded");
message = validationResult.getResult();
ready = true;
}
} else {
ready = true;
}
} else {
ready = true;
}
} else {
ready = true;
}
if (ready) {
ExitState state = plExit.getState();
pipeLineResult.setState(state);
pipeLineResult.setExitCode(plExit.getExitCode());
if (message.asObject() != null && !plExit.isEmptyResult()) {
// TODO Replace with Message.isEmpty() once Larva can handle NULL responses...
pipeLineResult.setResult(message);
} else {
pipeLineResult.setResult(Message.nullMessage());
}
ready = true;
if (log.isDebugEnabled()) {
// for performance reasons
String skString = "";
for (Iterator<String> it = pipeLineSession.keySet().iterator(); it.hasNext(); ) {
String key = it.next();
Object value = pipeLineSession.get(key);
skString = skString + "\n " + key + "=[" + value + "]";
}
log.debug("Available session keys at finishing pipeline of adapter [" + pipeLine.getOwner().getName() + "]:" + skString);
log.debug("Pipeline of adapter [" + pipeLine.getOwner().getName() + "] finished processing messageId [" + messageId + "] result: " + (message == null ? "<null>" : "(" + message.getClass().getSimpleName() + ") [" + message + "]") + " with exit-state [" + state + "]");
}
}
} else {
IPipe pipeToRun = (IPipe) forwardTarget;
PipeRunResult pipeRunResult = pipeProcessor.processPipe(pipeLine, pipeToRun, message, pipeLineSession);
message = pipeRunResult.getResult();
// TODO: this should be moved to a StatisticsPipeProcessor
if (!(pipeToRun instanceof AbstractPipe) && !message.isEmpty()) {
StatisticsKeeper sizeStat = pipeLine.getPipeSizeStatistics(pipeToRun);
if (sizeStat != null) {
sizeStat.addValue(message.size());
}
}
PipeForward pipeForward = pipeRunResult.getPipeForward();
// get the next pipe to run
forwardTarget = pipeLine.resolveForward(pipeToRun, pipeForward);
}
}
} finally {
for (int i = 0; i < pipeLine.getExitHandlers().size(); i++) {
IPipeLineExitHandler exitHandler = pipeLine.getExitHandlers().get(i);
try {
if (log.isDebugEnabled())
log.debug("processing ExitHandler [" + exitHandler.getName() + "]");
exitHandler.atEndOfPipeLine(messageId, pipeLineResult, pipeLineSession);
} catch (Throwable t) {
log.warn("Caught Exception processing ExitHandler [" + exitHandler.getName() + "]", t);
}
}
}
return pipeLineResult;
}
use of nl.nn.adapterframework.core.IValidator in project iaf by ibissource.
the class Json2XmlValidatorTest method setupAcceptHeaderTest.
public String setupAcceptHeaderTest(String acceptHeaderValue) throws Exception {
pipe.setName("Response_To_Json_from_acceptHeader");
pipe.setInputFormatSessionKey("AcceptHeader");
pipe.setOutputFormat(DocumentFormat.XML);
pipe.setSchema("/Validation/NoNamespace/bp.xsd");
pipe.setResponseRoot("BusinessPartner");
pipe.setThrowException(true);
pipe.configure();
pipe.start();
session.put("AcceptHeader", acceptHeaderValue);
String input = TestFileUtils.getTestFile("/Validation/NoNamespace/bp-response-withNamespace.xml");
// first run the request validation ...
doPipe(pipe, input, session);
IValidator validator = pipe.getResponseValidator();
PipeRunResult prr_response = validator.doPipe(new Message(input), session);
return prr_response.getResult().asString();
}
use of nl.nn.adapterframework.core.IValidator in project iaf by ibissource.
the class WsdlTest method includeXsdInWsdlMixed.
@Test
public void includeXsdInWsdlMixed() throws XMLStreamException, IOException, ParserConfigurationException, SAXException, ConfigurationException, URISyntaxException, NamingException {
XmlValidator inputValidator = getXmlValidatorInstance("a", "b", "WsdlTest/test.xsd", "urn:webservice1 WsdlTest/test.xsd");
IValidator outputValidator = inputValidator.getResponseValidator();
PipeLine simple = mockPipeLine(inputValidator, outputValidator, "urn:webservice1", "IncludeXsds");
WsdlGenerator wsdl = new WsdlGenerator(simple);
wsdl.setUseIncludes(true);
wsdl.init();
test(wsdl, "WsdlTest/includexsds.test.wsdl");
}
use of nl.nn.adapterframework.core.IValidator in project iaf by ibissource.
the class WsdlTest method noroottagMixed.
@Test
public void noroottagMixed() throws XMLStreamException, IOException, SAXException, ParserConfigurationException, URISyntaxException, ConfigurationException, NamingException {
XmlValidator inputValidator = getXmlValidatorInstance(null, "b", "WsdlTest/test.xsd", "urn:webservice1 WsdlTest/test.xsd");
IValidator outputValidator = inputValidator.getResponseValidator();
PipeLine simple = mockPipeLine(inputValidator, outputValidator, "urn:webservice1", "TestRootTag");
WsdlGenerator wsdl = new WsdlGenerator(simple);
wsdl.init();
test(wsdl, "WsdlTest/noroottag.test.wsdl");
}
Aggregations