我有一个带有多个入口点(servlet 和 direct)的路由。通过servlet激活时需要做一定的工作。必须为 servlet 请求完成这项工作(即使存在不良行为者)。如果是通过直接进行的交流,则不得进行此项工作。这是代码中的示例:
// 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?
}
}