1 28 29 package com.caucho.ejb.burlap; 30 31 import com.caucho.hessian.io.HessianRemoteObject; 32 import com.caucho.hessian.io.HessianRemoteResolver; 33 import com.caucho.log.Log; 34 import com.caucho.vfs.Path; 35 import com.caucho.vfs.ReadStream; 36 import com.caucho.vfs.ReadWritePair; 37 import com.caucho.vfs.Vfs; 38 import com.caucho.vfs.WriteStream; 39 40 import java.io.IOException ; 41 import java.rmi.RemoteException ; 42 import java.util.logging.Level ; 43 import java.util.logging.Logger ; 44 45 48 public abstract class BurlapStub implements HessianRemoteObject { 49 private static final Logger log = Log.open(BurlapStub.class); 50 51 protected String _url; 52 protected transient Path _urlPath; 53 protected transient BurlapClientContainer _client; 54 protected transient HessianRemoteResolver _resolver; 55 56 62 void _init(String url, BurlapClientContainer client) 63 { 64 _url = url; 65 _urlPath = Vfs.lookup(url); 66 67 _burlap_setClientContainer(client); 68 69 if (log.isLoggable(Level.FINER)) 70 log.finer("burlap stub:" + _urlPath + " " + this); 71 } 72 73 79 public String getHessianURL() 80 { 81 return _url; 82 } 83 84 void _burlap_setURLPath(Path urlPath) 85 { 86 _urlPath = urlPath; 87 88 if (log.isLoggable(Level.FINER)) 89 log.finer("burlap setURL:" + _urlPath + " " + this); 90 91 _url = _urlPath.getURL(); 92 } 93 94 void _burlap_setClientContainer(HessianRemoteResolver resolver) 95 { 96 _resolver = resolver; 97 if (resolver instanceof BurlapClientContainer) 98 _client = (BurlapClientContainer) resolver; 99 } 100 101 protected BurlapWriter _burlap_openWriter() 102 throws RemoteException 103 { 104 try { 105 ReadWritePair pair = _urlPath.openReadWrite(); 106 ReadStream is = pair.getReadStream(); 107 WriteStream os = pair.getWriteStream(); 108 109 if (_client != null) { 110 String auth = _client.getBasicAuthentication(); 111 if (auth != null) 112 os.setAttribute("Authorization", auth); 113 } 114 115 BurlapWriter out = new BurlapWriter(is, os); 116 117 out.setRemoteResolver(_resolver); 118 119 return out; 120 } catch (IOException e) { 121 throw new RemoteException (String.valueOf(e)); 122 } 123 } 124 125 protected void _burlap_freeWriter(BurlapWriter out) 126 throws IOException 127 { 128 out.close(); 129 } 130 } 131 | Popular Tags |