Solved

ejb wildfly example

Posted on 2017-01-29
2
200 Views
Last Modified: 2017-03-20
Hi,

I am trying ejb stateless bean example on wildfly 10.

my code as follows
package com.gp;

import javax.ejb.LocalBean;
import javax.ejb.Stateless;

/**
 * Session Bean implementation class GreetBean
 */
@Stateless
@LocalBean
public class GreetBean implements GreetBeanRemote {

    /**
     * Default constructor. 
     */
    public GreetBean() {
        // TODO Auto-generated constructor stub
    }

    @Override
    public void greet(String name) {
	// TODO Auto-generated method stub
	System.out.println("hello dear"+name);
	
    }

}

Open in new window

package com.gp;

import javax.ejb.Remote;

@Remote
public interface GreetBeanRemote {
void greet(String name);
}

Open in new window


package com.gp;

import java.util.Hashtable;

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

public class GreetClient {

    public static void main(String[] args) {
	// TODO Auto-generated method stub

	//String host = "192.168.56.1";// localhost 127.0.0.1
	String host = "127.0.0.1";// localhost 127.0.0.1
	String port = "8180";
	Hashtable<Object, Object> props = new Hashtable<>();
	props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContext");
	props.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");

	props.put("jboss.naming.client.ejb.context", false);
	props.put("org.jboss.ejb.client.scoped.context", true);

	props.put("endpoint.name", "client-endpoint");
	props.put("remote.connectionprovider.create.options.org.xnio.Options.SSL_Enables", true);

	props.put("remote.connections", "default");
	props.put("remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANANYMOUS", false);

	props.put(Context.PROVIDER_URL, "http-remoting://" + host + ":" + port);
	props.put("remote.connection.default.host", host);
	props.put("remote.connection.default.port", port);

	String beanName = GreetBean.class.getSimpleName();
	String interfaceName = GreetBeanRemote.class.getName();
	String moduleName = "GreetEJBProjectStateless";

	String lookUpName = "ejb:/" + moduleName + "/" + beanName + "!" + interfaceName;

	System.out.println("lookUpName is---->" + lookUpName);

	Context context;
	try {
	    context = new InitialContext(props);

	    GreetBeanRemote bean = (GreetBeanRemote) context.lookup(lookUpName);
	    bean.greet("gp");
	} catch (NamingException e) {
	    // TODO Auto-generated catch block
	    e.printStackTrace();
	}

	/*
	 * java:global/GreetEJBProjectStaless/GreetBean!com.gp.GreetBean
	 * java:app/GreetEJBProjectStaless/GreetBean!com.gp.GreetBean
	 * java:module/GreetBean!com.gp.GreetBean
	 * java:global/GreetEJBProjectStaless/GreetBean!com.gp.GreetBeanRemote
	 * java:app/GreetEJBProjectStaless/GreetBean!com.gp.GreetBeanRemote
	 * java:module/GreetBean!com.gp.GreetBeanRemote
	 * java:jboss/exported/GreetEJBProjectStaless/GreetBean!com.gp.
	 * GreetBeanRemote
	 */

    }

}

Open in new window

ejb-jar.xml is

<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/ejb-jar_3_2.xsd" version="3.2">
  <display-name>GreetEJBProjectStaless</display-name>
</ejb-jar>

Open in new window


structure is as attached


i am getting below error
lookUpName is---->ejb:/GreetEJBProjectStateless/GreetBean!com.gp.GreetBeanRemote
javax.naming.NoInitialContextException: Cannot instantiate class: org.jboss.naming.remote.client.InitialContext [Root exception is java.lang.ClassNotFoundException: org.jboss.naming.remote.client.InitialContext]
      at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
      at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
      at javax.naming.InitialContext.init(Unknown Source)
      at javax.naming.InitialContext.<init>(Unknown Source)
      at com.gp.GreetClient.main(GreetClient.java:44)
Caused by: java.lang.ClassNotFoundException: org.jboss.naming.remote.client.InitialContext
      at java.net.URLClassLoader.findClass(Unknown Source)
      at java.lang.ClassLoader.loadClass(Unknown Source)
      at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
      at java.lang.ClassLoader.loadClass(Unknown Source)
      at java.lang.Class.forName0(Native Method)
      at java.lang.Class.forName(Unknown Source)
      at com.sun.naming.internal.VersionHelper12.loadClass(Unknown Source)
      at com.sun.naming.internal.VersionHelper12.loadClass(Unknown Source)
      ... 5 more
please advise
strEjb2.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: 42056521
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
Make the most of your online learning experience.
This video teaches viewers about errors in exception handling.
Starting up a Project
Suggested Courses

623 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