複数のエントリポイント(サーブレットと直接)を持つルートがあります。サーブレットを介してアクティブ化されると、特定の作業を実行する必要があります。この作業は、サーブレット要求に対して実行する必要があります(悪意のあるアクターが存在する場合でも)。直接の交換の場合、この作業を行ってはなりません。コードの例を次に示します。
// In a Route Builder somewhere.
from("servlet:///myService").inOut("direct:myService");
from("direct:myService").process(new ConditionalProcessor());
// Implementation of processor above.
public class ConditionalProcessor implements Processor {
@Override
public void process(Exchange exchange) throws Exception {
if(comesFromServlet(exchange)){
// Logic for Servlet.
} else {
// Logic for direct and other.
}
}
/**
* Must return true if the exchange started as a request to the servlet.
* Otherwise must return false.
*
* @param exchange
* @return
*/
public boolean comesFromServlet(Exchange exchange){
// What goes here?
}
}