1 28 29 package com.caucho.ejb.hessian; 30 31 import com.caucho.config.ConfigException; 32 import com.caucho.naming.AbstractModel; 33 import com.caucho.naming.ContextImpl; 34 import com.caucho.util.Base64; 35 import com.caucho.util.L10N; 36 37 import javax.naming.Context ; 38 import javax.naming.NamingException ; 39 import javax.naming.spi.InitialContextFactory ; 40 import java.util.Hashtable ; 41 42 45 public class HessianContextFactory implements InitialContextFactory { 46 static L10N L = new L10N(HessianContextFactory.class); 47 48 private AbstractModel _model; 49 50 53 public Context getInitialContext(Hashtable <?,?> environment) 54 throws NamingException 55 { 56 String prefix = (String ) environment.get(Context.PROVIDER_URL); 57 58 String user = (String ) environment.get(Context.SECURITY_PRINCIPAL); 59 String pw = (String ) environment.get(Context.SECURITY_CREDENTIALS); 60 61 if (! prefix.endsWith("/")) 62 prefix = prefix + '/'; 63 64 if (user != null) { 65 String auth = Base64.encode(user + ':' + pw); 66 67 HessianModel model = new HessianModel(prefix); 68 HessianClientContainer client; 69 try { 70 client = new HessianClientContainer(model.getURLPrefix()); 71 client.setBasicAuthentication(auth); 72 } catch (ConfigException e) { 73 throw new NamingException (e.toString()); 74 } 75 76 model.setClientContainer(client); 77 78 return new ContextImpl(model, environment); 79 } 80 81 if (_model == null) 82 _model = new HessianModel(prefix); 83 84 return new ContextImpl(_model, environment); 85 } 86 } 87 | Popular Tags |