从一个服务器到多个可配置服务器的JNDI查找 [英] JNDI lookup from one server to many configurable servers

查看:145
本文介绍了从一个服务器到多个可配置服务器的JNDI查找的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在不同机器上配置了几个JBoss服务器,不同的IP(不是集群,属于不同客户的单独的JBoss 7.1.1实例)。完全相同的EAR部署在所有系统上。我们尝试从一个系统向另一个系统发送一个名为的POJO。



问题



我们尝试了一切,但无法获取被调用的远程方法。连接已建立但未使用(在某些情况下使用本地bean)。我们可以做些什么来让沟通工作?



我们已经尝试遵循这些手册(迄今为止没有运气):



来自远程服务器实例的EJB调用



本手册说明:


请注意,本章将介绍在目标服务器上部署
,而在客户端服务器上部署的情况。


由于没有目标或客户端服务器,在两台服务器上都部署了该bean。这两个服务器可以是客户端或目的地,这取决于场景,例如客户A可能希望今天向客户B发送,客户​​C可能希望明天向客户A发送。明天之后,客户A可能希望向客户C发送



资料来源: https://docs.jboss.org/author/display/AS71/EJB+来自+ a + remote + server +实例的调用+



使用JNDI远程客户端的EJB调用



这也没有。本手册使用的.properties文件在运行时无法更改,这使得该方法无法使用,即使它已经有效(它没有)。



来源: https://docs.jboss .org / author / display / AS71 / EJB + invocations + from + a + remote + client + using + JNDI



通过远程EJB调用JNDI - EJB客户端API或远程命名项目



此方法将jboss.naming.client.ejb.context设置为true。这将导致一个SecurityException,因为EJBClientContext.setSelector被调用。



来源: https://docs.jboss.org/author/display/AS71/Remote+EJB+调用+通过+ JNDI + - + EJB +客户端+ API +或+远程命名+项目



项目结构 p>

这是我们的项目结构:

  project / 
ear /
pom.xml
war /
pom.xml
src / main / java / com / acme / ejb /
DefaultGroupImportBean.java
ejb /
pom.xml
src / main / java / com / acme / ejb /
DefaultGroupTransferBean.java
ejb-api /
pom.xml
src / main / java / com / acme / ejb
GroupImportBean.java
GroupTransferBean.java
RemoteEjbClient.java

这是执行查找的类:

  public class RemoteEjbClient {

private static final String INITIAL_CONTEXT_FACTORY =org.jboss.naming.remote.client.InitialContextFactory;

public GroupTransferBean lookupGroupTransferBean(NamingContextConfiguration namingContextConfiguration)
throws NamingException {

上下文context = createInitialContext(namingContextConfiguration);
return(GroupTransferBean)context.lookup(namingContextConfiguration.getLookupName());
}

private Context createInitialContext(NamingContextConfiguration namingContextConfiguration)throws NamingException {
属性jndiProperties = new Properties();
jndiProperties.put(Context.INITIAL_CONTEXT_FACTORY,INITIAL_CONTEXT_FACTORY);
jndiProperties.put(Context.PROVIDER_URL,namingContextConfiguration.getProviderUrl());
jndiProperties.put(Context.SECURITY_PRINCIPAL,namingContextConfiguration.getPrincipal());
jndiProperties.put(Context.SECURITY_CREDENTIALS,namingContextConfiguration.getCredentials());

返回新的InitialContext(jndiProperties);
}
}

NamingContextConfiguration 是一个POJO描述另一个系统。我们在我们的数据库中存储-_NamingContextConfiguration_s(它们必须可以在运行时配置)。主体已经添加了 add-user.sh 应用程序用户)。



GroupTransferBean.java: / p>

  public interface GroupTransferBean {

void pushGroup(Group group);

void pushResources(String url,List< String> resources);
}

GroupImportBean.java:

  public interface GroupImportBean {

public void importGroup(Group group);

public void importResources(String url,List< String> resources);
}

DefaultGroupTransferBean.java:



$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b @EJB
private GroupImportBean groupImportBean;

@Override
public void pushGroup(Group group){
groupImportBean.importGroup(group);
}

@Override
public void pushResources(String url,List< String> resources){
groupImportBean.importResources(url,resources);
}
}

DefaultGroupImportBean.java:

  @Stateless 
@Remote(GroupImportBean.class)
@Interceptors(SpringBeanAutowiringInterceptor.class)
public class DefaultGroupImportBean implements GroupImportBean {

@Autowired
private GroupRepository groupRepository;

@Override
public void importGroup(Group group){
groupRepository.save(group);
}

@Override
public void importResources(String url,List< String> resources){
//做一些魔术
}
}

RemoteEjbClient由Spring控制器调用。

解决方案

几乎与以下描述的相同的问题:在多个服务器上查找相同的EJB



似乎不可能得到通过EJB在多个服务器之间的依赖连接,所以我们最终使用JMS为我们的服务器进行服务器通信。也许这也是你的选择。


We have a couple of JBoss servers on different machines with different IPs (not a cluster, single standalone JBoss 7.1.1 instances that belong to different customers). The exact same EAR is deployed on all systems. We try to send a POJO called Group from one system to another system.

The problem

We tried everything but are unable to get the remote methods called. The connection is established but not used (the local bean was used in some cases). What can we do to get the communication to work?

We have tried to follow these manuals (without any luck so far):

EJB invocations from a remote server instance

This manual states:

Note that this chapter deals with the case where the bean is deployed on the "Destination Server" but not on the "Client Server".

The bean is deployed on both servers because there is no destination or client server. Both servers can be client or destination, depending on the scenario, e.g. customer A could want to send a Group to customer B today and customer C could want to send a Group to customer A tomorrow. The day after tomorrow, customer A might want to send a Group to customer C.

Source: https://docs.jboss.org/author/display/AS71/EJB+invocations+from+a+remote+server+instance

EJB invocations from a remote client using JNDI

This didn't worked either. This manual uses .properties-files that cannot be changed at runtime which makes this approach unusable, even if it would have worked (which it didn't).

Source: https://docs.jboss.org/author/display/AS71/EJB+invocations+from+a+remote+client+using+JNDI

Remote EJB invocations via JNDI - EJB client API or remote-naming project

This approach sets "jboss.naming.client.ejb.context" to true. This causes a SecurityException because EJBClientContext.setSelector is called.

Source: https://docs.jboss.org/author/display/AS71/Remote+EJB+invocations+via+JNDI+-+EJB+client+API+or+remote-naming+project

Project structure

This is our project structure:

project/
    ear/
        pom.xml
    war/
        pom.xml
        src/main/java/com/acme/ejb/
            DefaultGroupImportBean.java
    ejb/
        pom.xml
        src/main/java/com/acme/ejb/
            DefaultGroupTransferBean.java
    ejb-api/
        pom.xml
        src/main/java/com/acme/ejb
            GroupImportBean.java
            GroupTransferBean.java
            RemoteEjbClient.java

This is the class that does the lookup:

public class RemoteEjbClient {

    private static final String INITIAL_CONTEXT_FACTORY = "org.jboss.naming.remote.client.InitialContextFactory";

    public GroupTransferBean lookupGroupTransferBean(NamingContextConfiguration namingContextConfiguration)
        throws NamingException {

        Context context = createInitialContext(namingContextConfiguration);
        return (GroupTransferBean) context.lookup(namingContextConfiguration.getLookupName());
    }

    private Context createInitialContext(NamingContextConfiguration namingContextConfiguration) throws NamingException {
        Properties jndiProperties = new Properties();
        jndiProperties.put(Context.INITIAL_CONTEXT_FACTORY, INITIAL_CONTEXT_FACTORY);
        jndiProperties.put(Context.PROVIDER_URL, namingContextConfiguration.getProviderUrl());
        jndiProperties.put(Context.SECURITY_PRINCIPAL, namingContextConfiguration.getPrincipal());
        jndiProperties.put(Context.SECURITY_CREDENTIALS, namingContextConfiguration.getCredentials());

        return new InitialContext(jndiProperties);
    }
}

NamingContextConfiguration is a POJO that describes another system. We store -_NamingContextConfiguration_s in our database (they must be configurable at runtime!). The principal has been added with add-user.sh (Application User).

GroupTransferBean.java:

public interface GroupTransferBean {

    void pushGroup(Group group);

    void pushResources(String url, List<String> resources);
}

GroupImportBean.java:

public interface GroupImportBean {

    public void importGroup(Group group);

    public void importResources(String url, List<String> resources);
}

DefaultGroupTransferBean.java:

@Stateless(mappedName = "GroupTransferBean")
@Remote(GroupTransferBean.class)
public class DefaultGroupTransferBean implements GroupTransferBean {

    @EJB
    private GroupImportBean groupImportBean;

    @Override
    public void pushGroup(Group group) {
        groupImportBean.importGroup(group);
    }

    @Override
    public void pushResources(String url, List<String> resources) {
        groupImportBean.importResources(url, resources);
    }
}

DefaultGroupImportBean.java:

@Stateless
@Remote(GroupImportBean.class)
@Interceptors(SpringBeanAutowiringInterceptor.class)
public class DefaultGroupImportBean implements GroupImportBean {

    @Autowired
    private GroupRepository groupRepository;

    @Override
    public void importGroup(Group group) {
        groupRepository.save(group);
    }

    @Override
    public void importResources(String url, List<String> resources) {
        // Do some magic
    }
}

The RemoteEjbClient is called by a Spring controller.

解决方案

Nearly the same question as described here: Lookup of same EJB on multiple servers

It seems to be impossible to get a reliant connection between multiple servers via EJB, so we ended up using JMS for our server to server communication. Maybe thats an option for you, too.

这篇关于从一个服务器到多个可配置服务器的JNDI查找的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆