1 28 29 package com.caucho.ejb.hessian; 30 31 import com.caucho.hessian.io.HessianInput; 32 import com.caucho.util.CharBuffer; 33 import com.caucho.vfs.Path; 34 import com.caucho.vfs.ReadStream; 35 import com.caucho.vfs.ReadWritePair; 36 import com.caucho.vfs.WriteStream; 37 38 import java.io.IOException ; 39 40 43 public class MetaStub { 44 51 public static Object call(Path urlPath, String method, Object arg) 52 throws Throwable 53 { 54 return call(urlPath, method, new Object [] { arg }); 55 } 56 57 64 public static Object call(Path urlPath, String method, Object []args) 65 throws Throwable 66 { 67 ReadWritePair pair = urlPath.openReadWrite(); 68 69 ReadStream is = pair.getReadStream(); 70 WriteStream os = pair.getWriteStream(); 71 72 HessianInput in = new HessianInput(is); 73 HessianWriter out = new HessianWriter(os); 74 75 try { 76 out.call(method, args); 77 78 String status = (String ) is.getAttribute("status"); 79 80 if (! "200".equals(status)) { 81 CharBuffer msg = new CharBuffer(); 82 83 int ch; 84 while ((ch = is.readChar()) >= 0) 85 msg.append((char) ch); 86 87 throw new IOException ("bad status: " + status + "\n" + msg); 88 } 89 90 return in.readReply(null); 91 } finally { 92 os.close(); 93 is.close(); 94 } 95 } 96 } 97 | Popular Tags |