zoukankan      html  css  js  c++  java
  • ejb 远程调用

    1,客户端代码:

    package com.example.test;
    
    import java.util.Hashtable;
    import java.util.Properties;
    
    import javax.naming.Context;
    import javax.naming.InitialContext;
    import javax.naming.NamingException;
    
    import com.example.HelloWorldRemote;
    
    //import cn.ejb.HelloWorldRemote;
    
    public class HelloWorldTest {
        public static void main(String[] args) {
            Properties jndiProperties = new Properties();
    //        Hashtable jndiProperties = new Hashtable();
            jndiProperties.put("jboss.naming.client.ejb.context", true);
            jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
            
            //写这里不行!!!
    //        jndiProperties.put(Context.SECURITY_PRINCIPAL, "testUser");
    //        jndiProperties.put(Context.SECURITY_CREDENTIALS, "12345678");
            
            
            try {
                Context context = new InitialContext(jndiProperties);
                final String appName = "";
                final String moduleName = "hello";
                final String distinctName = "";
    
                Object obj = context.lookup("ejb:" + appName + "/" + moduleName + "/" + distinctName + "/HelloWorld!com.example.HelloWorldRemote");
                System.out.println(obj);
                HelloWorldRemote hwr = (HelloWorldRemote) obj;
                String say = hwr.hello( );
                System.out.println(say);
            } catch (NamingException e) {
                e.printStackTrace();
            }
        }
    }

    2,src下的jboss-ejb-client.properties

    remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=false
    remote.connections=default
    remote.connection.default.host=211.100.75.242
    remote.connection.default.port = 4447
    remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false
    remote.connection.default.username=testUser
    remote.connection.default.password=12345678

     3,用jbossinadd-user.sh 加个 applicationRealm

    [userone@localhost bin]$ ./add-user.sh
    
    
    What type of user do you wish to add?
    
    a) Management User (mgmt-users.properties)
    
    b) Application User (application-users.properties)
    
    (a): b
    
    
    
    Enter the details of the new user to add.
    
    Realm (ApplicationRealm) :  ApplicationRealm ---->> Careful Here . You need to type this or leave it blank . I filled an incorrect value here and things went wrong from there .
    
    Username : testuser
    
    Password : testpassword
    
    Re-enter Password : testpassword
    
    
    
    What roles do you want this user to belong to? (Please enter a comma separated list, or leave blank for none) : testrole
    
    About to add user 'testuser' for realm 'ApplicationRealm'
    
    
    
    Is this correct yes/no? yes
    
    
    
    Added user 'testuser' to file '/home/userone/jboss-as-7.1.0.Final/standalone/configuration/application-users.properties'
    
    Added user 'testuser' to file '/home/userone/jboss-as-7.1.0.Final/domain/configuration/application-users.properties'
    
    Added user 'testuser' with roles testrole to file '/home/userone/jboss-as-7.1.0.Final/standalone/configuration/application-roles.properties'
    
    Added user 'testuser' with roles testrole to file '/home/userone/jboss-as-7.1.0.Final/domain/configuration/application-roles.properties'
    
    .
    大功告成了
    参考: .http://stackoverflow.com/questions/19129836/javax-security-sasl-saslexception-authentic-failed-while-connecting-to-jboss-7
    http://middlewaremagic.com/jboss/?p=1466
    https://docs.jboss.org/author/display/AS71/EJB+invocations+from+a+remote+client+using+JNDI
  • 相关阅读:
    read、write 与recv、send区别 gethostname
    网络粘包问题解决办法
    C++中 =default 和 =delete 使用
    c++ unordered_map 自定义key
    c++ list的坑
    c++ vector 的坑
    对于RBAC与shiro的一些思考
    求两个数的最大公约数&求N个数的最大公约数
    Nginx是什么?有什么用?
    如何做可靠的分布式锁,Redlock真的可行么
  • 原文地址:https://www.cnblogs.com/bigben0123/p/4819201.html
Copyright © 2011-2022 走看看