1 52 53 package freemarker.debug; 54 55 import java.io.IOException ; 56 import java.io.ObjectInputStream ; 57 import java.io.ObjectOutputStream ; 58 import java.net.InetAddress ; 59 import java.net.Socket ; 60 import java.security.MessageDigest ; 61 62 import freemarker.template.utility.UndeclaredThrowableException; 63 64 70 public class DebuggerClient 71 { 72 private DebuggerClient() 73 { 74 } 75 76 92 public static Debugger getDebugger(InetAddress host, int port, String password) 93 throws 94 IOException 95 { 96 try 97 { 98 Socket s = new Socket (host, port); 99 try 100 { 101 ObjectOutputStream out = new ObjectOutputStream (s.getOutputStream()); 102 ObjectInputStream in = new ObjectInputStream (s.getInputStream()); 103 int protocolVersion = in.readInt(); 104 if(protocolVersion > 220) 105 { 106 throw new IOException ( 107 "Incompatible protocol version " + protocolVersion + 108 ". At most 220 was expected."); 109 } 110 byte[] challenge = (byte[])in.readObject(); 111 MessageDigest md = MessageDigest.getInstance("SHA"); 112 md.update(password.getBytes("UTF-8")); 113 md.update(challenge); 114 out.writeObject(md.digest()); 115 return (Debugger)in.readObject(); 116 } 117 finally 118 { 119 s.close(); 120 } 121 } 122 catch(IOException e) 123 { 124 throw e; 125 } 126 catch(Exception e) 127 { 128 throw new UndeclaredThrowableException(e); 129 } 130 } 131 } 132 | Popular Tags |