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
  • 相关阅读:
    favorite 单词学习 主要是发音 fa vor it 注意 ri不连读 是自然带出来的r的尾音
    echart 带表格
    正则 小于等于1 小数最多两位
    period 发音 per + iod 没有ri音 (per=round od=hod=way)
    SelectZenEmpty 下拉框 支持 最大长度 超出... vue 组件
    expensive pens 就是 spend 花费 pend 就是 to pay
    reciterdoc 资料库 支持中文搜索了。 vuepresspluginfulltextsearch(用一半)
    react 中 动态添加 class,防止图片 重复加载, 主要是 backgroundimage的二次加载会有新请求,和图片的闪烁
    vscode 格式化 vue 和 js代码 vetur prettier beautify
    sign 单词学习 本质:去分开
  • 原文地址:https://www.cnblogs.com/bigben0123/p/4819201.html
Copyright © 2011-2022 走看看