Solved

ejb stateless example

Posted on 2017-01-29
2
41 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 7

Accepted Solution

by:
gudii9 earned 0 total points
ID: 42056514
0

Featured Post

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

Suggested Solutions

A short article about a problem I had getting the GPS LocationListener working.
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 tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

756 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