很简单
在http返回的header里面加一个Location消息头,返回码改成301
示例代码如下:
package com.lala.rest.bean; import org.apache.camel.Exchange; import org.apache.camel.Processor; public class RedirectProcessor implements Processor { public void process(Exchange exchange) { permanentlyRedirect(exchange, "http://www.csdn.net"); } /** * 永久重定向 * 代表永久性转移(Permanently Moved)。 */ private void permanentlyRedirect(Exchange exchange, String location) { exchange.getOut().setHeader(Exchange.HTTP_RESPONSE_CODE, 301); exchange.getOut().setHeader("Location", location); } /** * 临时重定向 * 代表暂时性转移(Temporarily Moved )。 */ private void temporarilyRedirect(Exchange exchange, String location) { exchange.getOut().setHeader(Exchange.HTTP_RESPONSE_CODE, 302); exchange.getOut().setHeader("Location", location); } }