Advertisement
ridjis

ClientApp

Nov 18th, 2016
338
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.42 KB | None | 0 0
  1. import java.util.Properties;
  2.  
  3. import javax.naming.Context;
  4. import javax.naming.InitialContext;
  5. import javax.naming.NamingException;
  6.  
  7. import beans.AccountBean;
  8. import beans.AccountBeanRemote;
  9.  
  10. public class ClientApp {
  11.     private static Context initContext;
  12.     private static final String PKG_INTF = "org.jboss.ejb.client.naming";
  13.    
  14.     private static Context getInitContext() throws NamingException {
  15.         if (initContext == null) {
  16.             Properties prop = new Properties();
  17.             prop.put(Context.URL_PKG_PREFIXES, PKG_INTF);
  18.             initContext = new InitialContext(prop);
  19.         }
  20.         return initContext;
  21.     }
  22.    
  23.     private static String getLookupName() {
  24.         final String appName = "PlanerEAR";
  25.         final String moduleName = "PlanerEJB";
  26.         final String distinctName = "";
  27.         final String className = AccountBean.class.getSimpleName();
  28.         final String interfaceName = AccountBeanRemote.class.getName();
  29.        
  30.         return String.format("ejb:%s/%s/%s/%s!%s", appName, moduleName, distinctName, className, interfaceName);
  31.     }
  32.    
  33.     private static AccountBeanRemote getBean() {
  34.         Context ctx = null;
  35.         AccountBeanRemote bean = null;
  36.  
  37.         try {
  38.             ctx = getInitContext();
  39.             String name = getLookupName();
  40.             bean = (AccountBeanRemote) ctx.lookup(name);
  41.         } catch (Exception e) { e.printStackTrace(); }
  42.        
  43.         return bean;
  44.     }
  45.    
  46.     public static void main(String[] args) {
  47.         System.out.println(getBean().createAccount("a@b.com", "sifra", "Milanko", "Nikola"));
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement