1 19 20 package org.apache.cayenne.remote.hessian.service; 21 22 import java.util.Enumeration ; 23 import java.util.HashMap ; 24 import java.util.Map ; 25 26 import javax.servlet.ServletConfig ; 27 import javax.servlet.ServletException ; 28 import javax.servlet.http.HttpServletRequest ; 29 import javax.servlet.http.HttpSession ; 30 31 import org.apache.cayenne.remote.hessian.EnumSerializerProxy; 32 import org.apache.cayenne.remote.hessian.HessianConfig; 33 import org.apache.cayenne.remote.service.HttpRemoteService; 34 35 import com.caucho.hessian.io.SerializerFactory; 36 import com.caucho.services.server.Service; 37 import com.caucho.services.server.ServiceContext; 38 39 48 public class HessianService extends HttpRemoteService implements Service { 49 50 public static final String [] SERVER_SERIALIZER_FACTORIES = new String [] { 51 EnumSerializerProxy.class.getName(), ServerSerializerFactory.class.getName() 52 }; 53 54 57 public void init(ServletConfig config) throws ServletException { 58 Map properties = new HashMap (); 59 60 Enumeration en = config.getInitParameterNames(); 61 while (en.hasMoreElements()) { 62 String name = (String ) en.nextElement(); 63 properties.put(name, config.getInitParameter(name)); 64 } 65 66 initService(properties); 67 } 68 69 72 SerializerFactory createSerializerFactory() { 73 return HessianConfig.createFactory(SERVER_SERIALIZER_FACTORIES, getRootChannel() 74 .getEntityResolver()); 75 } 76 77 protected HttpSession getSession(boolean create) { 78 HttpServletRequest request = (HttpServletRequest ) ServiceContext 79 .getContextRequest(); 80 if (request == null) { 81 throw new IllegalStateException ( 82 "Attempt to access HttpSession outside the request scope."); 83 } 84 85 return request.getSession(create); 86 } 87 88 public void destroy() { 89 destroyService(); 90 } 91 } 92 | Popular Tags |