Guest User

Untitled

a guest
Nov 18th, 2013
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.02 KB | None | 0 0
  1. Exception in thread "main" java.lang.IllegalStateException: No EJB receiver available for handling [appName:,modulename:HelloWorldSessionBean,distinctname:] combination for invocation context org.jboss.ejb.client.EJBClientInvocationContext@41408b80
  2. at org.jboss.ejb.client.EJBClientContext.requireEJBReceiver(EJBClientContext.java:584)
  3. at org.jboss.ejb.client.ReceiverInterceptor.handleInvocation(ReceiverInterceptor.java:119)
  4. at org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClientInvocationContext.java:181)
  5. at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:136)
  6. at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:121)
  7. at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:104)
  8. at $Proxy0.sayHello(Unknown Source)
  9. at com.ibytecode.client.EJBApplicationClient.main(EJBApplicationClient.java:16)
  10.  
  11. import javax.ejb.Remote;
  12.  
  13. @Remote
  14. public interface HelloWorld {
  15.  
  16. public String sayHello();
  17.  
  18.  
  19. }
  20.  
  21. import com.ibytecode.business.HelloWorld;
  22. import javax.ejb.Stateless;
  23.  
  24. /**
  25. * Session Bean implementation class HelloWorldBean
  26. */
  27. @Stateless
  28. public class HelloWorldBean implements HelloWorld {
  29.  
  30. /**
  31. * Default constructor.
  32. */
  33. public HelloWorldBean() {
  34. }
  35.  
  36. public String sayHello() {
  37. return "Hello World !!!";
  38. }
  39.  
  40. package com.ibytecode.client;
  41.  
  42. import javax.naming.Context;
  43. import javax.naming.NamingException;
  44.  
  45. import com.ibytecode.business.HelloWorld;
  46. import com.ibytecode.businesslogic.HelloWorldBean;
  47. import com.ibytecode.clientutility.ClientUtility;
  48.  
  49. public class EJBApplicationClient {
  50.  
  51. public static void main(String[] args) {
  52. // TODO Auto-generated method stub
  53.  
  54. HelloWorld bean = doLookup();
  55. System.out.println(bean.sayHello()); // 4. Call business logic
  56.  
  57. }
  58.  
  59. private static HelloWorld doLookup() {
  60. Context context = null;
  61. HelloWorld bean = null;
  62. try {
  63. // 1. Obtaining Context
  64. context = ClientUtility.getInitialContext();
  65. // 2. Generate JNDI Lookup name
  66. String lookupName = getLookupName();
  67. // 3. Lookup and cast
  68. bean = (HelloWorld) context.lookup(lookupName);
  69.  
  70. } catch (NamingException e) {
  71. e.printStackTrace();
  72. }
  73. return bean;
  74. }
  75.  
  76.  
  77. private static String getLookupName() {
  78. /*
  79. The app name is the EAR name of the deployed EJB without .ear suffix.
  80. Since we haven't deployed the application as a .ear,
  81. the app name for us will be an empty string
  82. */
  83. String appName = "";
  84.  
  85. /* The module name is the JAR name of the deployed EJB
  86. without the .jar suffix.
  87. */
  88. String moduleName = "HelloWorldSessionBean";
  89.  
  90. /*AS7 allows each deployment to have an (optional) distinct name.
  91. This can be an empty string if distinct name is not specified.
  92. */
  93. String distinctName = "";
  94.  
  95. // The EJB bean implementation class name
  96. String beanName = HelloWorldBean.class.getSimpleName();
  97.  
  98. // Fully qualified remote interface name
  99. final String interfaceName = HelloWorld.class.getName();
  100.  
  101. // Create a look up string name
  102. String name = "ejb:" + appName + "/" + moduleName + "/" +
  103. distinctName + "/" + beanName + "!" + interfaceName;
  104.  
  105. return name;
  106. }
  107.  
  108.  
  109. }
  110.  
  111. import java.util.Properties;
  112. import javax.naming.Context;
  113. import javax.naming.InitialContext;
  114. import javax.naming.NamingException;
  115.  
  116. public class ClientUtility {
  117.  
  118. private static Context initialContext;
  119.  
  120. private static final String PKG_INTERFACES = "org.jboss.ejb.client.naming";
  121.  
  122. public static Context getInitialContext() throws NamingException {
  123. if (initialContext == null) {
  124. Properties properties = new Properties();
  125. properties.put("jboss.naming.client.ejb.context", true);
  126. properties.put(Context.URL_PKG_PREFIXES, PKG_INTERFACES);
  127.  
  128.  
  129. initialContext = new InitialContext(properties);
  130. }
  131. return initialContext;
  132. }
  133.  
  134. java:global/MyBankLogicEAR/MyBankLogic/Account!main.IAccount
  135. java:app/MyBankLogic/Account!main.IAccount
  136. java:module/Account!main.IAccount
  137. java:jboss/exported/MyBankLogicEAR/MyBankLogic/Account!main.IAccount
  138. java:global/MyBankLogicEAR/MyBankLogic/Account
  139. java:app/MyBankLogic/Account
  140. java:module/Account
  141.  
  142. final Hashtable jndiProperties = new Hashtable();
  143. jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
  144. try {
  145. final Context context = new InitialContext(jndiProperties);
  146. String appName = "";
  147. String moduleName = "jboss-firstbean";
  148. String distinctName = "";
  149. String beanName = "FirstBean";
  150. String interfaceFullName = "ejb.RemoteFirstBean";
  151. final String jndi = "ejb:" + appName + "/" + moduleName + "/" + distinctName + "/" + beanName + "!" + viewClassName;
  152. RemoteFirstBean statelessRemote = (RemoteFirstBean)context.lookup(jndi);
  153.  
  154. } catch (NamingException ex) {
  155. System.out.println("problems");
  156. }
Advertisement
Add Comment
Please, Sign In to add comment