Apache Camel rest 재 설정
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);
}
}