Solved

ejb wildfly example

Posted on 2017-01-29
2
69 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
ID: 42056521
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
JAVA API design with micro service cloud in mind 1 75
add projects t working set in maven 2 37
Is there a simpler dropbox system? 10 44
instagram media_id Grabber by TAG 1 24
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

685 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