Apache Camel中的NoInitialContextException

时间:2015-06-10 07:23:45

标签: java ldap apache-camel initial-context

我有一条路由从数据库中提取一组人ID,拆分它们并为每个id执行LDAP查找。下面的代码已经简化,但我希望你能理解。

主要

<Style x:Key="DefaultCell" TargetType="{x:Type DataGridCell}">
            <Setter Property="Template">
                <Setter.Value>
                        <ControlTemplate TargetType="DataGridCell">

                        <local:CustomTextBlock Text="{Binding RelativeSource={RelativeSource TemplatedParent},Path=Content.Text}">
                            <!--InlineCollection="{Binding ., Converter={StaticResource StringToXamlConverter} }"/>-->
                            <local:CustomTextBlock.InlineCollection>
                              <MultiBinding Converter="{StaticResource StringToXamlConverter}">
                                    <Binding RelativeSource="{RelativeSource Self}" Path="." />
                                    <Binding RelativeSource="{RelativeSource Self}" Path="(local:SearchOperations.SearchTerm)"/>
                                </MultiBinding>
                            </local:CustomTextBlock.InlineCollection>                                
                        </local:CustomTextBlock>                     
                    </ControlTemplate>
                </Setter.Value> 
            </Setter>   

MyRouteBuilder

public class MainApp {
    public static void main(String... args) throws Exception {
        Main main = new Main();
        main.enableHangupSupport();
        // create mydb and bind it into registry
        DataSource dataSource = setupDataSource();
        main.bind("mydb", dataSource);
        // create ldap and bind it into registry
        InitialLdapContext ldap = setupLDAP();
        main.bind("dir", ldap);
        main.addRouteBuilder(new MyRouteBuilder());
        main.run(args);
    }

    private static InitialLdapContext setupLDAP() throws NamingException {
        Properties props = new Properties();
        props.setProperty(Context.INITIAL_CONTEXT_FACTORY,
            "com.sun.jndi.ldap.LdapCtxFactory");
        props.setProperty(Context.PROVIDER_URL, "ldap://mycompany:389");
        props.setProperty(Context.URL_PKG_PREFIXES, "com.sun.jndi.url");
        props.setProperty(Context.REFERRAL, "ignore");
        props.setProperty(Context.SECURITY_AUTHENTICATION, "simple");
        return new InitialLdapContext(props, null);
    }
}

AfterDbProcessor只需使用personid并将其放入消息中

的正文中
public class MyRouteBuilder extends RouteBuilder {
    public void configure() throws Exception {
        from("timer:start?period=0&delay=0&repeatCount=1")
        .process(new Processor() {
            public void process(Exchange exchange) throws Exception {
                System.out.println("Invoked timer at " + new Date());
            }
        })
        .setBody(constant("select personid from person"))
        .to("jdbc:mydb?outputType=StreamList")
        .split(body())
        .process(new AfterDbProcessor())
        .to("ldap:dir?base=ou=people,dc=mycompany&returnedAttributes=sn,fn")
        .process(new AfterLDAPProcessor());
     }
}

}

从数据库获取ID工作正常。首次查找到LDAP工作也很好,但第二次会崩溃并显示错误消息

public class AfterHOTProcessor implements Processor {
    public void process(Exchange exchange) throws Exception {
        Map<String, Object> row = exchange.getIn().getBody(Map.class);
        Integer personId = (Integer) row.get("henkilo_id");
        exchange.getIn().setBody("(uid=" + personId + ")");
   }

首次LDAP查找后,InitialLdapContext会发生什么?不,我需要重新初始化或重新创建或者什么?

0 个答案:

没有答案
相关问题