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
Solved

ejb wildfly example

Posted on 2017-01-29
2
23 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
2 Comments
 
LVL 7

Accepted Solution

by:
gudii9 earned 0 total points
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Join & Write a Comment

Suggested Solutions

This is an explanation of a simple data model to help parse a JSON feed
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…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

860 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