Copy to ClipboardCopied!Toggle word wrapToggle overflow
그러면 다음과 같이 경로를 정의할 수 있습니다.
from("servlet:hello?matchOnUriPrefix=true").process(new Processor() {
public void process(Exchange exchange) throws Exception {
String contentType = exchange.getIn().getHeader(Exchange.CONTENT_TYPE, String.class);
String path = exchange.getIn().getHeader(Exchange.HTTP_URI, String.class);
path = path.substring(path.lastIndexOf("/"));
assertEquals("Get a wrong content type", CONTENT_TYPE, contentType);
// assert camel http header
String charsetEncoding = exchange.getIn().getHeader(Exchange.HTTP_CHARACTER_ENCODING, String.class);
assertEquals("Get a wrong charset name from the message heaer", "UTF-8", charsetEncoding);
// assert exchange charset
assertEquals("Get a wrong charset naem from the exchange property", "UTF-8", exchange.getProperty(Exchange.CHARSET_NAME));
exchange.getOut().setHeader(Exchange.CONTENT_TYPE, contentType + "; charset=UTF-8");
exchange.getOut().setHeader("PATH", path);
exchange.getOut().setBody("<b>Hello World</b>");
}
});
from("servlet:hello?matchOnUriPrefix=true").process(new Processor() {
public void process(Exchange exchange) throws Exception {
String contentType = exchange.getIn().getHeader(Exchange.CONTENT_TYPE, String.class);
String path = exchange.getIn().getHeader(Exchange.HTTP_URI, String.class);
path = path.substring(path.lastIndexOf("/"));
assertEquals("Get a wrong content type", CONTENT_TYPE, contentType);
// assert camel http header
String charsetEncoding = exchange.getIn().getHeader(Exchange.HTTP_CHARACTER_ENCODING, String.class);
assertEquals("Get a wrong charset name from the message heaer", "UTF-8", charsetEncoding);
// assert exchange charset
assertEquals("Get a wrong charset naem from the exchange property", "UTF-8", exchange.getProperty(Exchange.CHARSET_NAME));
exchange.getOut().setHeader(Exchange.CONTENT_TYPE, contentType + "; charset=UTF-8");
exchange.getOut().setHeader("PATH", path);
exchange.getOut().setBody("<b>Hello World</b>");
}
});
Copy to ClipboardCopied!Toggle word wrapToggle overflow
참고
camel-servlet 끝점의 상대 경로 지정
당사는 HTTP 전송을 게시된 서블릿과 바인딩하고 있으며 서블릿의 애플리케이션 컨텍스트 경로를 알 수 없으므로 camel-servlet 엔드포인트는 상대 경로를 사용하여 끝점 URL을 지정합니다. 클라이언트는 서블릿 게시 주소 ("http://localhost:8080/camel/services") + RELATIVE_PATH("/hello")를 통해 camel-servlet 엔드포인트에 액세스할 수 있습니다.