1 package Jt.jndi; 2 3 import javax.naming.*; 5 import java.rmi.*; 6 import java.util.Properties ; 7 import java.util.*; 8 import Jt.*; 9 10 11 14 15 public class JtJNDIAdapter extends JtAdapter { 16 17 private String url = "t3://localhost:7001"; private String user = null; 19 private String password = null; 20 private String factory = "weblogic.jndi.WLInitialContextFactory"; private boolean initted = false; 22 private transient Context ctx = null; 23 24 28 29 public void setUrl (String url) { 30 this.url = url; 31 32 } 33 34 37 38 public String getUrl () { 39 return (url); 40 } 41 42 43 47 48 public void setUser (String user) { 49 this.user = user; 50 } 51 52 55 56 public String getUser () { 57 return (user); 58 } 59 60 61 65 66 public void setPassword (String password) { 67 this.password = password; 68 } 69 70 71 74 75 public String getPassword () { 76 return (password); 77 } 78 79 83 84 public void setFactory (String factory) { 85 this.factory = factory; 86 } 87 88 89 92 93 94 public String getFactory () { 95 return (factory); 96 } 97 98 99 100 102 private Object lookup (String jndiName) { 103 104 Object objref = null; 105 106 107 try { 108 109 if (!initted) { 110 initted = true; 111 ctx = getInitialContext(); 112 } 113 114 objref = ctx.lookup (jndiName); 115 116 117 } catch (Exception e) { 118 handleException (e); 119 } 120 return (objref); 121 122 } 123 124 125 private Object test () { 126 127 JtMessage msg = new JtMessage ("JtLOOKUP"); 128 129 msg.setMsgContent ("JtSessionFacade"); 130 131 return (processMessage (msg)); 132 133 } 134 135 142 143 public Object processMessage (Object event) { 144 145 String msgid = null; 146 JtMessage e = (JtMessage) event; 147 Object content; 148 149 if (e == null) 150 return null; 151 152 msgid = (String ) e.getMsgId (); 153 154 if (msgid == null) 155 return null; 156 157 content = e.getMsgContent(); 158 159 161 if (msgid.equals ("JtLOOKUP")) { 162 163 return (lookup ((String ) content)); 164 165 } 166 167 168 if (msgid.equals ("JtTEST")) { 169 170 return (test ()); 171 172 } 173 174 175 if (msgid.equals ("JtREMOVE")) { 176 177 return (null); 178 179 } 180 181 handleError ("processMessage: invalid message id:" + msgid); 182 return (null); 183 184 } 185 186 187 191 192 private Context getInitialContext() throws Exception { 193 Properties p = new Properties (); 194 p.put(Context.INITIAL_CONTEXT_FACTORY, 195 factory); 196 p.put(Context.PROVIDER_URL, url); 197 if (user != null) { 198 p.put(Context.SECURITY_PRINCIPAL, user); 200 if (password == null) 201 password = ""; 202 p.put(Context.SECURITY_CREDENTIALS, password); 203 } 204 return new InitialContext(p); 205 } 206 207 208 211 212 public static void main (String [] args) { 213 JtObject main; 214 JtJNDIAdapter adapter; 215 Object entry; 216 217 main = new JtObject (); 218 219 220 222 adapter = (JtJNDIAdapter) main.createObject ("Jt.jndi.JtJNDIAdapter", "adapter"); 223 224 226 entry = (Object ) main.sendMessage ("adapter", new JtMessage ("JtTEST")); 227 228 229 if (entry != null) 230 System.out.println ("JtJNDIAdapter: GO"); 231 else 232 System.out.println ("JtJNDIAdapter: FAIL"); 233 234 235 237 main.removeObject ("adapter"); 238 239 240 } 241 } 242 | Popular Tags |