-
1. Re: i m new to willdfy and i m getting errors on configuring jndi for remote ejb application
mayerw01 Dec 9, 2015 9:52 AM (in response to taichimaster84)I think it may help if you post your source code.
But you could try to add this property:
properties.put("jboss.naming.client.ejb.context", true);
-
2. Re: i m new to willdfy and i m getting errors on configuring jndi for remote ejb application
taichimaster84 Dec 9, 2015 2:10 PM (in response to mayerw01)i tried it but it's not working maybe im missing some library , this is my client code:
package com.tutorialspoint.test;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.List;
import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import com.tutorialspoints.stateless.LibrarySessionBean;
import com.tutorialspoints.stateless.LibrarySessionBeanRemote;
public class EJBTester {
BufferedReader brConsoleReader = null;
{
brConsoleReader = new BufferedReader(new InputStreamReader(System.in));
}
public static void main(String[] args) {
EJBTester ejbTester = new EJBTester();
ejbTester.testStatelessEjb();
}
private void showGUI() {
System.out.println("**********************");
System.out.println("Welcome to Book Store");
System.out.println("**********************");
System.out.print("Options \n1. Add Book\n2. Exit \nEnter Choice: ");
}
private void testStatelessEjb() {
try {
int choice = 1;
LibrarySessionBeanRemote libraryBean = lookupRemoteStatelessLibrarySession();
while (choice != 2) {
String bookName;
showGUI();
String strChoice = brConsoleReader.readLine();
choice = Integer.parseInt(strChoice);
if (choice == 1) {
System.out.print("Enter book name: ");
bookName = brConsoleReader.readLine();
libraryBean.addBook(bookName);
} else if (choice == 2) {
break;
}
}
List<String> booksList = libraryBean.getBooks();
System.out.println("Book(s) entered so far: " + booksList.size());
for (int i = 0; i < booksList.size(); ++i) {
System.out.println((i + 1) + ". " + booksList.get(i));
}
LibrarySessionBeanRemote libraryBean1 = lookupRemoteStatelessLibrarySession();
List<String> booksList1 = libraryBean1.getBooks();
System.out
.println("***Using second lookup to get library stateless object***");
System.out.println("Book(s) entered so far: " + booksList1.size());
for (int i = 0; i < booksList1.size(); ++i) {
System.out.println((i + 1) + ". " + booksList1.get(i));
}
} catch (Exception e) {
System.out.println(e.getMessage());
e.printStackTrace();
} finally {
try {
if (brConsoleReader != null) {
brConsoleReader.close();
}
} catch (IOException ex) {
System.out.println(ex.getMessage());
}
}
}
private static LibrarySessionBeanRemote lookupRemoteStatelessLibrarySession()
throws NamingException {
Properties prop = new Properties();
prop.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
prop.put(Context.PROVIDER_URL, "http-remoting://127.0.0.1:8080");
prop.put(Context.SECURITY_PRINCIPAL, "username");
prop.put(Context.SECURITY_CREDENTIALS, "password");
prop.put("jboss.naming.client.ejb.context", true);
prop.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
Context context = new InitialContext(prop);
// The app name is the application name of the deployed EJBs. This is
// typically the ear name
// without the .ear suffix. However, the application name could be
// overridden in the application.xml of the
// EJB deployment on the server.
// Since we haven't deployed the application as a .ear, the app name for
// us will be an empty string
final String appName = "";
// This is the module name of the deployed EJBs on the server. This is
// typically the jar name of the
// EJB deployment, without the .jar suffix, but can be overridden via
// the ejb-jar.xml
// In this example, we have deployed the EJBs in a
// jboss-as-ejb-remote-app.jar, so the module name is
// jboss-as-ejb-remote-app
final String moduleName = "EjbComponent";
// AS7 allows each deployment to have an (optional) distinct name. We
// haven't specified a distinct name for
// our EJB deployment, so this is an empty string
final String distinctName = "";
// The EJB name which by default is the simple class name of the bean
// implementation class
final String beanName = LibrarySessionBean.class.getSimpleName();
// the remote view fully qualified class name
final String viewClassName = LibrarySessionBeanRemote.class.getName();
// let's do the lookup
context.lookup( "ejb:" + appName + "/" + moduleName + "/" + distinctName + "/" + beanName + "!" + viewClassName);
return (LibrarySessionBeanRemote) context.lookup( "ejb:" + appName + "/" + moduleName + "/" + distinctName + "/" + beanName + "!" + viewClassName);
}
}
THIS IS MY EJB CODE:
package com.tutorialspoints.stateless;
import java.util.List;
import javax.ejb.Remote;
public interface LibrarySessionBeanRemote {
void addBook(String bookName);
List<String> getBooks();
}
package com.tutorialspoints.stateless;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.Remote;
import javax.ejb.Stateless;
/**
* Session Bean implementation class NewSessionBean
*/
@Stateless
@Remote(LibrarySessionBeanRemote.class)
public class LibrarySessionBean implements LibrarySessionBeanRemote {
List<String> bookShelf;
public LibrarySessionBean() {
bookShelf = new ArrayList<String>();
}
public void addBook(String bookName) {
bookShelf.add(bookName);
}
public List<String> getBooks() {
return bookShelf;
}
}
-
3. Re: i m new to willdfy and i m getting errors on configuring jndi for remote ejb application
mayerw01 Dec 10, 2015 5:38 AM (in response to taichimaster84)This indicates a lookup problem.
You should remove the "ejb:"
So you should replace
return (LibrarySessionBeanRemote) context.lookup( "ejb:" + appName + "/" + moduleName + "/" + distinctName + "/" + beanName + "!" + viewClassName);
with
return (LibrarySessionBeanRemote) context.lookup( appName + "/" + moduleName + "/" + distinctName + "/" + beanName + "!" + viewClassName);
-
4. Re: i m new to willdfy and i m getting errors on configuring jndi for remote ejb application
taichimaster84 Dec 10, 2015 3:35 PM (in response to mayerw01)thanks very much i tried it and it worked