103.9. 이름이 잘못 설정 사용
Camel 2.9.3에서 사용할수 있는
#set 옵션을 사용하면 소비자 끝점과 생산자 끝점 모두에서 파일 인코딩을 구성할 수 있습니다. 예를 들어 utf-8 파일을 읽고 파일을 iso-8859-1로 변환하려면 다음을 수행할 수 있습니다.
from("file:inbox?charset=utf-8") .to("file:outbox?charset=iso-8859-1")
from("file:inbox?charset=utf-8")
.to("file:outbox?charset=iso-8859-1")
경로에서 convertBodyTo
를 사용할 수도 있습니다. 아래 예제에서는 여전히 utf-8 형식으로 된 파일을 입력했지만 파일 내용을 iso-8859-1 형식의 바이트 배열로 변환하려고 합니다. 그런 다음Bean이 데이터를 처리하도록 합니다. 현재 baseline을 사용하여 outbox 폴더에 콘텐츠를 쓰기 전에 다음을 수행합니다.
from("file:inbox?charset=utf-8") .convertBodyTo(byte[].class, "iso-8859-1") .to("bean:myBean") .to("file:outbox");
from("file:inbox?charset=utf-8")
.convertBodyTo(byte[].class, "iso-8859-1")
.to("bean:myBean")
.to("file:outbox");
소비자 끝점에서ECDHEset을 생략하면 Camel은 파일의 =set를 알 수 없으며 기본적으로 "UTF-8"을 사용합니다. 그러나 org.apache.camel.default.charset
키로 다른 기본 인코딩을 재정의하고 사용하도록 JVM 시스템 속성을 구성할 수 있습니다.
아래 예제에서는 파일이 UTF-8 인코딩에 없는 경우 파일 읽기의 기본 인코딩이 될 수 있습니다.
이 예제에서는 파일을 작성할 때 콘텐츠가 이미 바이트 배열로 변환되어 추가 인코딩 없이 그대로 콘텐츠를 직접 작성합니다.
from("file:inbox") .convertBodyTo(byte[].class, "iso-8859-1") .to("bean:myBean") .to("file:outbox");
from("file:inbox")
.convertBodyTo(byte[].class, "iso-8859-1")
.to("bean:myBean")
.to("file:outbox");
Exchange.CHARSET_NAME
키와 교환에서 속성을 설정하여 파일을 작성할 때 인코딩 동적 인코딩을 재정의하고 제어할 수도 있습니다. 예를 들어 아래 경로에서 메시지 헤더의 값으로 속성을 설정합니다.
from("file:inbox") .convertBodyTo(byte[].class, "iso-8859-1") .to("bean:myBean") .setProperty(Exchange.CHARSET_NAME, header("someCharsetHeader")) .to("file:outbox");
from("file:inbox")
.convertBodyTo(byte[].class, "iso-8859-1")
.to("bean:myBean")
.setProperty(Exchange.CHARSET_NAME, header("someCharsetHeader"))
.to("file:outbox");
간단한 항목을 유지하여 동일한 인코딩으로 파일을 선택하고 파일을 특정 인코딩으로 작성한 경우 엔드포인트에서-2020: set 옵션을
사용하는 것이 좋습니다.
끝점에서 명시적으로 set
옵션을 구성한 경우 Exchange.CHARSET_NAME
속성에 관계없이 해당 구성이 사용됩니다.
일부 문제가 있는 경우 org.apache.camel.component.file
에서 DEBUG 로깅을 활성화하고 특정ECDHE 세트를 사용하여 파일을 읽고 쓸 때 Camel 로그를 활성화할 수 있습니다.
예를 들어 아래 경로는 다음을 기록합니다.
from("file:inbox?charset=utf-8") .to("file:outbox?charset=iso-8859-1")
from("file:inbox?charset=utf-8")
.to("file:outbox?charset=iso-8859-1")
및 로그:
DEBUG GenericFileConverter - Read file /Users/davsclaus/workspace/camel/camel-core/target/charset/input/input.txt with charset utf-8 DEBUG FileOperations - Using Reader to write file: target/charset/output.txt with charset: iso-8859-1
DEBUG GenericFileConverter - Read file /Users/davsclaus/workspace/camel/camel-core/target/charset/input/input.txt with charset utf-8
DEBUG FileOperations - Using Reader to write file: target/charset/output.txt with charset: iso-8859-1