Solved

ejb wildfly example

Posted on 2017-01-29
2
111 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

Why You Need a DevOps Toolchain

IT needs to deliver services with more agility and velocity. IT must roll out application features and innovations faster to keep up with customer demands, which is where a DevOps toolchain steps in. View the infographic to see why you need a DevOps toolchain.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
web project error add remove 1 84
Running JavaFX on the Raspberry Pi 27 295
C qsort compare function issue 6 70
netbeans can not run self signed app 8 38
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
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 …

751 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