2

我将我的 JBoss AS7.1.1 (standalone.xml) 配置为接受远程处理,但未打开 4447 端口。我的standalone.xml:

<subsystem xmlns="urn:jboss:domain:remoting:1.1">
    <connector name="remoting-connector" socket-binding="remoting" security-realm="ApplicationRealm"/>
</subsystem>    
<interfaces>
   <interface name="mine">
        <any-ipv4-address/>
    </interface>
</interfaces>

<socket-binding-group name="standard-sockets" default-interface="mine" port-offset="${jboss.socket.binding.port-offset:0}">
    <socket-binding name="management-native" interface="management" port="${jboss.management.native.port:9999}"/>
    <socket-binding name="management-http" interface="management" port="${jboss.management.http.port:9990}"/>
    <socket-binding name="management-https" interface="management" port="${jboss.management.https.port:9443}"/>
    <socket-binding name="ajp" port="8009"/>
    <socket-binding name="http" port="8080"/>
    <socket-binding name="https" port="8443"/>
    <socket-binding name="messaging" port="5445"/>
    <socket-binding name="messaging-throughput" port="5455"/>
    <socket-binding name="osgi-http" interface="management" port="8090"/>
    <socket-binding name="remoting" port="4447"/>
    <socket-binding name="txn-recovery-environment" port="4712"/>
    <socket-binding name="txn-status-manager" port="4713"/>
    <outbound-socket-binding name="mail-smtp">
        <remote-destination host="localhost" port="25"/>
    </outbound-socket-binding>
</socket-binding-group>

客户端程序:

    public class Homework4EJB3Client {

    /**
     * Looks up and returns the proxy to remote stateless calculator bean
     *
     * @return
     * @throws NamingException
     */
    private static IMailService lookupRemoteStatelessMessaging() throws NamingException {
        final Hashtable jndiProperties = new Hashtable();
        jndiProperties.put("jboss.naming.client.ejb.context", true);
        jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
        final Context context = new InitialContext(jndiProperties);
        // The app name is the application name of the deployed EJBs. This is typically the ear name
        // without the .ear suffix. However, the application name could be overridden in the application.xml of the
        // EJB deployment on the server.
        // Since we haven't deployed the application as a .ear, the app name for us will be an empty string
        final String appName = "";
        // This is the module name of the deployed EJBs on the server. This is typically the jar name of the
        // EJB deployment, without the .jar suffix, but can be overridden via the ejb-jar.xml
        // In this example, we have deployed the EJBs in a jboss-as-ejb-remote-app.jar, so the module name is
        // jboss-as-ejb-remote-app
        final String moduleName = "Homework4Quartz";
        // AS7 allows each deployment to have an (optional) distinct name. We haven't specified a distinct name for
        // our EJB deployment, so this is an empty string
        final String distinctName = "";
        // The EJB name which by default is the simple class name of the bean implementation class
        final String beanName = "MailService";
        // the remote view fully qualified class name
        final String viewClassName = "hu.infokristaly.homework.quartz.middle.service.IMailService";
        // let's do the lookup
        return (IMailService) context.lookup("ejb:" + appName + "/" + moduleName + "/" + distinctName + "/" + beanName + "!" + viewClassName);
    }

    private static IMailService getIMailService() {
        Properties clientProp = new Properties();  
        clientProp.put("remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED", "false");  
        clientProp.put("remote.connections", "default");  
        clientProp.put("remote.connection.default.port", "4447");  
        clientProp.put("remote.connection.default.host", "192.168.1.25");  
        clientProp.put("remote.connection.default.username", "quickstartUser");  
        clientProp.put("remote.connection.default.password", "quickstartPassword");  
        clientProp.put("remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS", "false");  


        EJBClientConfiguration cc = new PropertiesBasedEJBClientConfiguration(clientProp);  
        ContextSelector<EJBClientContext> selector = new ConfigBasedEJBClientContextSelector(cc);  
        EJBClientContext.setSelector(selector);  

        final String appName = "";
        final String moduleName = "Homework4Quartz";
        final String distinctName = "";
        final String beanName = "MailService";
        final String viewClassName = "hu.infokristaly.homework.quartz.middle.service.IMailService";

        Properties props = new Properties();  
        props.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
        IMailService result = null;
        try {
            Context ctx = new InitialContext(props);
            result = (IMailService) ctx.lookup("ejb:" + appName + "/" + moduleName + "/" + distinctName + "/" + beanName + "!" + viewClassName);
        } catch (NamingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return result;
    }

    @SuppressWarnings({ "unchecked", "rawtypes" })
    public static void main(String[] args) {
        try {
            Object o = lookupRemoteStatelessMessaging();
            //Object o = getIMailService();
            if (o instanceof IMailService) {
                String result = ((IMailService)o).getMail();
                System.out.println(result);
                ((IMailService)o).sendMail();
            }
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

我使用了 jboss-ejb-client.properties:

endpoint.name=client-endpoint
remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=false

remote.connections=default

remote.connection.default.host=192.168.1.25
remote.connection.default.port = 4447
remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false

remote.connection.default.username=quickstartUser
remote.connection.default.password=quickstartPassword

在服务器端 Java 代码:

@Named
@Stateless
@Remote(IMailService.class)
public class MailService implements IMailService {

@Inject
private EntityManager em;

@Override
public void sendMail() {
    System.out.println("EntityManager:"+em);
    System.out.println("Mail sent");
}

@Override
public String getMail() {
    return new String("Mail sent");
}

}

客户端使用 jboss-client.jar 和服务器导出 java:jboss/exported/Homework4Quartz/MailService!hu.infokristaly.homework.quartz.middle.service.IMailService 接口。

所以,一切都很好,如果我将 localhost 用于 remote.connection.default.host,但如果我使用远程 ip 则会失败

WARN: Could not register a EJB receiver for connection to remote://192.168.1.25:4447
java.lang.RuntimeException: Operation failed with status WAITING
    at org.jboss.ejb.client.remoting.IoFutureHelper.get(IoFutureHelper.java:93)
    at org.jboss.ejb.client.remoting.ConfigBasedEJBClientContextSelector.setupEJBReceivers(ConfigBasedEJBClientContextSelector.java:121)
    at org.jboss.ejb.client.remoting.ConfigBasedEJBClientContextSelector.<init>(ConfigBasedEJBClientContextSelector.java:78)
    at org.jboss.ejb.client.EJBClientContext.<clinit>(EJBClientContext.java:77)
    at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:120)
    at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:104)
    at com.sun.proxy.$Proxy0.getMail(Unknown Source)
    at hu.infokristaly.homework.ejb3client.Homework4EJB3Client.main(Homework4EJB3Client.java:100)

java.lang.IllegalStateException: No EJB receiver available for handling [appName:,modulename:Homework4Quartz,distinctname:] combination for invocation context org.jboss.ejb.client.EJBClientInvocationContext@2eb9e305
    at org.jboss.ejb.client.EJBClientContext.requireEJBReceiver(EJBClientContext.java:584)
    at org.jboss.ejb.client.ReceiverInterceptor.handleInvocation(ReceiverInterceptor.java:119)
    at org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClientInvocationContext.java:181)
    at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:136)
    at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:121)
    at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:104)
    at com.sun.proxy.$Proxy0.getMail(Unknown Source)
    at hu.infokristaly.homework.ejb3client.Homework4EJB3Client.main(Homework4EJB3Client.java:100)

我也在另一边使用了 add-user (application-users.properties, quickstartUser, quickstartPassword, guest)。如何在不同的机器上运行客户端和服务器?

4

1 回答 1

1

做得好,如果我在 remote.connection.default.host 使用主机名而不是 IP 地址,一切正常。

于 2013-09-29T12:14:29.363 回答