1 package dynaop.remote; 2 3 import java.io.IOException ; 4 import java.io.ObjectInputStream ; 5 import java.io.ObjectOutputStream ; 6 7 import javax.servlet.ServletConfig ; 8 import javax.servlet.ServletException ; 9 import javax.servlet.http.HttpServlet ; 10 import javax.servlet.http.HttpServletRequest ; 11 import javax.servlet.http.HttpServletResponse ; 12 13 import dynaop.ProxyFactory; 14 import dynaop.util.Classes; 15 16 51 public class Service extends HttpServlet { 52 53 Object serviceImplementation; 54 55 public void doPost(HttpServletRequest request, 56 HttpServletResponse response) throws ServletException , IOException { 57 try { 58 ObjectInputStream in = 59 new PatchedObjectInputStream(request.getInputStream()); 60 InvocationHandle invocation = 61 (InvocationHandle) in.readObject(); 62 in.close(); 63 64 Object result; 65 try { 66 result = invocation.invoke(this.serviceImplementation); 67 } 68 catch (Throwable t) { 69 result = t; 70 } 71 72 ObjectOutputStream out = 73 new ObjectOutputStream (response.getOutputStream()); 74 out.writeObject(result); 75 out.close(); 76 } 77 catch (ClassNotFoundException e) { 78 throw new ServletException (e); 79 } 80 } 81 82 public void init(ServletConfig config) throws ServletException { 83 super.init(config); 84 85 String className = config.getInitParameter("class"); 86 if (className == null) 87 throw new ServletException ( 88 "Specify service implementation class name in 'class' " + 89 "init param." 90 ); 91 try { 92 Class clazz = Classes.forName(className); 93 this.serviceImplementation = 94 ProxyFactory.getInstance().wrap(clazz.newInstance()); 95 } 96 catch (Exception e) { 97 throw new ServletException (e); 98 } 99 } 100 } 101 | Popular Tags |