com.predic8.membrane.core.interceptor.flow.ConditionalInterceptor Maven / Gradle / Ivy
/* Copyright 2014 predic8 GmbH, www.predic8.com
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
package com.predic8.membrane.core.interceptor.flow;
import java.util.HashMap;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Required;
import com.google.common.base.Function;
import com.predic8.membrane.annot.MCAttribute;
import com.predic8.membrane.annot.MCElement;
import com.predic8.membrane.core.Router;
import com.predic8.membrane.core.exchange.Exchange;
import com.predic8.membrane.core.interceptor.Interceptor;
import com.predic8.membrane.core.interceptor.InterceptorFlowController;
import com.predic8.membrane.core.interceptor.Outcome;
import com.predic8.membrane.core.lang.LanguageSupport;
import com.predic8.membrane.core.lang.groovy.GroovyLanguageSupport;
/**
* @description
*
* The "if" interceptor supports conditional execution of a group of executors.
*
*
*
* Note that this is a draft implementation only: Design decissions are still pending.
*
*
* - 'evaluate condition only once': Should the condition be reevaluated once response handling has begun?
* - 'evaluate condition always during request handling already' (even when 'if' is nested in 'response')
* - What happens to ABORT handling of interceptor A in
<request><if test="..."><A /></if></response>
*
*/
@MCElement(name="if")
public class ConditionalInterceptor extends AbstractFlowInterceptor {
private static final Logger log = LoggerFactory.getLogger(InterceptorFlowController.class);
// configuration
private String test;
private LanguageType language = LanguageType.GROOVY;
// state
private final InterceptorFlowController interceptorFlowController = new InterceptorFlowController();
private Function