?
Solved

ejb stateless example

Posted on 2017-01-29
2
Medium Priority
?
131 Views
Last Modified: 2017-03-20
Hi,

I am working on below example

http://stackoverflow.com/questions/27519075/how-to-create-ejb-3-2-stateless-bean-project-and-running-it-on-wildfly-8

my code is
package com.example.ejbtest;
import javax.ejb.Stateless;


@Stateless
public class SLBean implements SLBeanRemote {

    public SLBean() {
    }

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

}

Open in new window


package com.example.ejbtest;

import javax.ejb.Remote;

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

Open in new window


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();
        }
    }
}

Open in new window

jboss-ejb- 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=8180
remote.connection.default.username=user1
remote.connection.default.password=password
remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false

Open in new window


when i run Test.java
i am getting below error

ejb:/EJBTest//SLBean!com.example.ejbtest.SLBeanRemote
javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial
      at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
      at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
      at javax.naming.InitialContext.getURLOrDefaultInitCtx(Unknown Source)
      at javax.naming.InitialContext.lookup(Unknown Source)
      at com.example.ejbtest.Test.main(Test.java:30)



i was not sure what are username and password i supposed to provide and where to double check..

i attached project structure.

please advise
strEjb.png
0
Comment
Question by:gudii9
1 Comment
 
LVL 7

Accepted Solution

by:
gudii9 earned 0 total points
ID: 42056514
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
This video teaches viewers about errors in exception handling.
Six Sigma Control Plans
Suggested Courses
Course of the Month13 days, 14 hours left to enroll

755 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question