검색

91.4. 예제

download PDF

다음 예제에서는 다음과 같이 정의된 더 큰 EJB를 사용합니다.

GreaterLocal.java

public interface GreaterLocal {

    String hello(String name);

    String bye(String name);

}

및 구현

GreaterImpl.java

@Stateless
public class GreaterImpl implements GreaterLocal {

    public String hello(String name) {
        return "Hello " + name;
    }

    public String bye(String name) {
        return "Bye " + name;
    }

}

91.4.1. Java DSL 사용

이 예제에서는 EJB에서 hello 메서드를 호출하려고 합니다. 이 예제는 Apache OpenEJB를 사용하는 단위 테스트를 기반으로 하므로 OpenEJB 설정을 사용하여 EJB 구성 요소에 JndiContext 를 설정해야 합니다.

@Override
protected CamelContext createCamelContext() throws Exception {
    CamelContext answer = new DefaultCamelContext();

    // enlist EJB component using the JndiContext
    EjbComponent ejb = answer.getComponent("ejb", EjbComponent.class);
    ejb.setContext(createEjbContext());

    return answer;
}

private static Context createEjbContext() throws NamingException {
    // here we need to define our context factory to use OpenEJB for our testing
    Properties properties = new Properties();
    properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.LocalInitialContextFactory");

    return new InitialContext(properties);
}

그런 다음 Camel 경로에서 EJB를 사용할 준비가 되었습니다.

from("direct:start")
    // invoke the greeter EJB using the local interface and invoke the hello method
    .to("ejb:GreaterImplLocal?method=hello")
    .to("mock:result");

실제 애플리케이션 서버에서

실제 애플리케이션 서버에서는 애플리케이션 서버와 동일한 JVM에 기본 JndiContext 를 생성하고 일반적으로 JNDI 레지스트리에 액세스하고 EJB s를 조회할 수 있으므로 EJB구성 요소에서 JndiContext 를 설정할 필요가 없습니다. 그러나 원격 JVM 또는 likes에서 애플리케이션 서버에 액세스해야 하는 경우 사전에 속성을 준비해야 합니다.

Red Hat logoGithubRedditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 문서 정보

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

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

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

Red Hat 소개

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

© 2024 Red Hat, Inc.