Guest User

Source code that throws exception

a guest
Aug 31st, 2010
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. package programmaticlogintest;
  2.  
  3. import com.sun.appserv.security.ProgrammaticLogin;
  4. import javax.naming.InitialContext;
  5. import demo.CalculatorRemote;
  6. import java.util.Hashtable;
  7. import javax.naming.NamingException;
  8. import javax.rmi.PortableRemoteObject;
  9.  
  10.  
  11. public class Main {
  12.  
  13. /**
  14. * @param args the command line arguments
  15. */
  16. public static void main(String[] args) throws NamingException {
  17.  
  18.  
  19. System.out.println("Hello World!");
  20.  
  21. ProgrammaticLogin pm = new ProgrammaticLogin();
  22. pm.login("endasil", "hej123"); //user and password of a user mapped to admin role
  23.  
  24. //corbaname:iiop:myhost.mycompany.com:9810/NameServiceServerRoo
  25. // Initial environment with various properties
  26. Hashtable env = new Hashtable();
  27.  
  28.  
  29. env.put("java.naming.factory.initial", "com.sun.enterprise.naming.SerialInitContextFactory");
  30. env.put("java.naming.factory.url.pkgs", "com.sun.enterprise.naming");
  31. env.put("java.naming.factory.state", "com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl");
  32. env.put("java.naming.provider.url", "localhost");
  33. env.put("org.omg.CORBA.ORBInitialHost", "127.0.0.1");
  34. env.put("org.omg.CORBA.ORBInitialPort", "3700");
  35. InitialContext ctx;
  36.  
  37. try {
  38. javax.swing.JOptionPane.showMessageDialog(null, "before InitialContext");
  39.  
  40. @h@ ctx = new InitialContext(env); <--- Exception is thrown by this one here!!
  41.  
  42. javax.swing.JOptionPane.showMessageDialog(null, "After initialContext");
  43. Object ref = ctx.lookup("demo.CalculatorRemote");
  44. javax.swing.JOptionPane.showMessageDialog(null, "Afterctx.lookup");
  45. CalculatorRemote calc = (CalculatorRemote) PortableRemoteObject.narrow(ref, CalculatorRemote.class);
  46. javax.swing.JOptionPane.showMessageDialog(null, "2 + 2 = " + calc.add(2, 2));
  47.  
  48.  
  49.  
  50. // javax.swing.JOptionPane.showMessageDialog(null, calc.hello("Mr Demo"));
  51. } catch (Exception ex) {
  52.  
  53. javax.swing.JOptionPane.showMessageDialog(null, "Exception" +ex.toString());
  54. }
  55. }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment