검색

35.4. ExchangeHelper 클래스

download PDF

35.4.1. 개요

org.apache.camel.util.ExchangeHelper 클래스는 프로세서를 구현할 때 유용한 메서드를 제공하는 Apache Camel 유틸리티 클래스입니다.

35.4.2. 끝점 확인

정적 resolveEndpoint() 메서드는 ExchangeHelper 클래스에서 가장 유용한 메서드 중 하나입니다. 프로세서 내에서 새 끝점 인스턴스를 만드는 데 사용할 수 있습니다.

예 35.6. resolveEndpoint() 메서드

public final class ExchangeHelper {
    ...
    @SuppressWarnings({"unchecked" })
    public static Endpoint
    resolveEndpoint(Exchange exchange, Object value)
        throws NoSuchEndpointException { ... }
    ...
}

resolveEndpoint() 에 대한 첫 번째 인수는 교환 인스턴스이며 두 번째 인수는 일반적으로 엔드포인트 URI 문자열입니다. 예 35.7. “파일 끝점 생성” 교환 인스턴스 교환에서 새 파일 엔드포인트를 만드는 방법을 보여줍니다.

예 35.7. 파일 끝점 생성

Endpoint file_endp = ExchangeHelper.resolveEndpoint(exchange, "file://tmp/messages/in.xml");

35.4.3. 교환 액세스 권한을 래핑

Exchange Helper 클래스는 해당 get Cryostat Property() 메서드를 교환 클래스에서 래핑하는 getMandatory CryostatProperty() 형식의 여러 정적 메서드를 제공합니다. 이들의 차이점은 원래 get CryostatProperty() 접근자가 해당 속성을 사용할 수 없는 경우 null 을 반환하고 getMandatory CryostatProperty() 는 Java 예외를 throw한다는 것입니다. 다음 래퍼 메서드는 ExchangeHelper 클래스에서 구현됩니다.

public final class ExchangeHelper {
    ...
    public static <T> T getMandatoryProperty(Exchange exchange, String propertyName, Class<T> type)
        throws NoSuchPropertyException { ... }

    public static <T> T getMandatoryHeader(Exchange exchange, String propertyName, Class<T> type)
        throws NoSuchHeaderException { ... }

    public static Object getMandatoryInBody(Exchange exchange)
        throws InvalidPayloadException { ... }

    public static <T> T getMandatoryInBody(Exchange exchange, Class<T> type)
        throws InvalidPayloadException { ... }

    public static Object getMandatoryOutBody(Exchange exchange)
        throws InvalidPayloadException { ... }

    public static <T> T getMandatoryOutBody(Exchange exchange, Class<T> type)
        throws InvalidPayloadException { ... }
    ...
}

35.4.4. 교환 패턴 테스트

다양한 교환 패턴은 In 메시지를 보유하는 것과 호환됩니다. 몇 가지 다른 교환 패턴은 외부 메시지 유지와도 호환됩니다. 교환 개체가 In 메시지 또는 Out 메시지를 유지할 수 있는지 여부를 확인하는 빠른 방법을 제공하기 위해 ExchangeHelper 클래스는 다음 메서드를 제공합니다.

public final class ExchangeHelper {
    ...
    public static boolean isInCapable(Exchange exchange) { ... }

    public static boolean isOutCapable(Exchange exchange) { ... }
    ...
}

35.4.5. In message의 MIME 콘텐츠 유형 가져오기

교환의 수신 메시지의 MIME 콘텐츠 유형을 찾으려면 ExchangeHelper.getContentType(exchange) 메서드를 호출하여 액세스할 수 있습니다. 이를 구현하기 위해 ExchangeHelper 개체는 In message의 Content-Type header Cryostat- Cryostatthis 메서드의 값을 조회하여 헤더 값을 채우기 위해 기본 구성 요소를 사용합니다.

Red Hat logoGithubRedditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 문서 정보

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

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

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

Red Hat 소개

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

© 2024 Red Hat, Inc.