null
null

Reputation: 9144

How to create EJB 3.2 Stateless Bean Project and Running it on Wildfly 8?

I'm trying to create EJB 3.2 Stateless Bean Project but still no avail until now. I hope anyone can help me.

Here is the EJB Project structure on my eclipse:

enter image description here

SLBean.java

package com.example.ejbtest;

import javax.ejb.Stateless;


@Stateless
public class SLBean implements SLBeanRemote {

    public SLBean() {
    }

    @Override
    public String sayHello() {
        return "Hello World !!!";
    }

}

SLBeanRemote.java

package com.example.ejbtest;

import javax.ejb.Remote;

@Remote
public interface SLBeanRemote {
    public String sayHello();
}

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=localhost
remote.connection.default.port=4447
remote.connection.default.username=user1
remote.connection.default.password=password
remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false

Test.java

package com.example.ejbtest;

import java.util.Properties;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

public class Test {

    public static void main(String[] args) {
        Context context;
        try {
            Properties properties = new Properties();
            properties.put(Context.URL_PKG_PREFIXES,"org.jboss.ejb.client.naming");
            properties.put("jboss.naming.client.ejb.context", true);
            context = new InitialContext(properties);

            String appName = "";
            String moduleName = "EJBTest";
            String distinctName = "";
            String beanName = SLBean.class.getSimpleName();
            String viewClassName = SLBeanRemote.class.getName();

            String ejbString = "ejb:" + appName + "/" + moduleName + "/"
                    + distinctName + "/" + beanName + "!" + viewClassName;

            System.out.println(ejbString);

            SLBeanRemote remote = (SLBeanRemote) context.lookup(ejbString);
            System.out.println(remote.sayHello());

        } catch (NamingException e) {
            e.printStackTrace();
        }
    }
}

So after I run the EJBTest project on Wildfly Server through Eclipse, I run the Test.java as client program to connect to the remote stateless bean.

But what I got was error like this:

Exception in thread "main" java.lang.IllegalStateException: EJBCLIENT000025: No EJB receiver available for handling [appName:, moduleName:EJBTest, distinctName:] combination for invocation context org.jboss.ejb.client.EJBClientInvocationContext@28d72e3f at org.jboss.ejb.client.EJBClientContext.requireEJBReceiver(EJBClientContext.java:749) at org.jboss.ejb.client.ReceiverInterceptor.handleInvocation(ReceiverInterceptor.java:116) at org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClientInvocationContext.java:186)

Anyone can help?

Upvotes: 1

Views: 2104

Answers (1)

null
null

Reputation: 9144

Ok, I found the answer. I had made two mistakes:

  1. I didn't put the jboss-ejb-client.properties file in correct place, i.e. the root of source folder (ejbModule).

  2. According to this article, the remote port for Wildfly 8 has been incorporated to port 8080, so I just need to change the remote.connection.default.port to 8080 in jboss-ejb-client.properties.

Upvotes: 2

Related Questions