이 콘텐츠는 선택한 언어로 제공되지 않습니다.

Chapter 40. Base64 DataFormat


Available as of Camel version 2.11

The Base64 data format is used for base64 encoding and decoding.

40.1. Options

The Base64 dataformat supports 4 options which are listed below.

NameDefaultJava TypeDescription

lineLength

76

Integer

To specific a maximum line length for the encoded data. By default 76 is used.

lineSeparator

 

String

The line separators to use. Uses new line characters (CRLF) by default.

urlSafe

false

Boolean

Instead of emitting '' and '/' we emit '-' and '_' respectively. urlSafe is only applied to encode operations. Decoding seamlessly handles both modes. Is by default false.

contentTypeHeader

false

Boolean

Whether the data format should set the Content-Type header with the type from the data format if the data format is capable of doing so. For example application/xml for data formats marshalling to XML, or application/json for data formats marshalling to JSon etc.

In Spring DSL, you configure the data format using this tag:

<camelContext>
    <dataFormats>
        <!-- for a newline character (\n), use the HTML entity notation coupled with the ASCII code. -->
        <base64 lineSeparator="&#10;" id="base64withNewLine" />
        <base64 lineLength="64" id="base64withLineLength64" />
    </dataFormats>
    ...
</camelContext>

Then you can use it later by its reference:

<route>
     <from uri="direct:startEncode" />
     <marshal ref="base64withLineLength64" />
     <to uri="mock:result" />
</route>

Most of the time, you won’t need to declare the data format if you use the default options. In that case, you can declare the data format inline as shown below.

40.2. Marshal

In this example we marshal the file content to base64 object.

from("file://data.bin")
    .marshal().base64()
    .to("jms://myqueue");

In Spring DSL:

 <from uri="file://data.bin">
 <marshal>
     <base64/>
 </marshal>
 <to uri="jms://myqueue"/>

40.3. Unmarshal

In this example we unmarshal the payload from the JMS queue to a byte[] object, before its processed by the newOrder processor.

from("jms://queue/order")
    .unmarshal().base64()
    .process("newOrder");

In Spring DSL:

 <from uri="jms://queue/order">
 <marshal>
     <base64/>
 </marshal>
 <to uri="bean:newOrder"/>

40.4. Dependencies

To use Base64 in your Camel routes you need to add a dependency on camel-base64 which implements this data format.

If you use Maven you can just add the following to your pom.xml:

<dependency>
  <groupId>org.apache.camel</groupId>
  <artifactId>camel-base64</artifactId>
  <version>x.x.x</version>  <!-- use the same version as your Camel core version -->
</dependency>
Red Hat logoGithubRedditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 문서 정보

Red Hat을 사용하는 고객은 신뢰할 수 있는 콘텐츠가 포함된 제품과 서비스를 통해 혁신하고 목표를 달성할 수 있습니다.

보다 포괄적 수용을 위한 오픈 소스 용어 교체

Red Hat은 코드, 문서, 웹 속성에서 문제가 있는 언어를 교체하기 위해 최선을 다하고 있습니다. 자세한 내용은 다음을 참조하세요.Red Hat 블로그.

Red Hat 소개

Red Hat은 기업이 핵심 데이터 센터에서 네트워크 에지에 이르기까지 플랫폼과 환경 전반에서 더 쉽게 작업할 수 있도록 강화된 솔루션을 제공합니다.

© 2024 Red Hat, Inc.