KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cayenne > remote > hessian > service > HessianService


1 /*****************************************************************
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  ****************************************************************/

19
20 package org.apache.cayenne.remote.hessian.service;
21
22 import java.util.Enumeration JavaDoc;
23 import java.util.HashMap JavaDoc;
24 import java.util.Map JavaDoc;
25
26 import javax.servlet.ServletConfig JavaDoc;
27 import javax.servlet.ServletException JavaDoc;
28 import javax.servlet.http.HttpServletRequest JavaDoc;
29 import javax.servlet.http.HttpSession JavaDoc;
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 /**
40  * An implementation of RemoteService using binary Hessian protocol. For more info on
41  * Hessian see http://www.caucho.com/resin-3.0/protocols/hessian.xtp.
42  *
43  * @see org.apache.cayenne.remote.hessian.service.HessianServlet
44  * @see org.apache.cayenne.remote.RemoteService
45  * @since 1.2
46  * @author Andrus Adamchik
47  */

48 public class HessianService extends HttpRemoteService implements Service {
49
50     public static final String JavaDoc[] SERVER_SERIALIZER_FACTORIES = new String JavaDoc[] {
51             EnumSerializerProxy.class.getName(), ServerSerializerFactory.class.getName()
52     };
53
54     /**
55      * Extracts parameters from ServletConfig and initializes the service.
56      */

57     public void init(ServletConfig JavaDoc config) throws ServletException JavaDoc {
58         Map JavaDoc properties = new HashMap JavaDoc();
59
60         Enumeration JavaDoc en = config.getInitParameterNames();
61         while (en.hasMoreElements()) {
62             String JavaDoc name = (String JavaDoc) en.nextElement();
63             properties.put(name, config.getInitParameter(name));
64         }
65
66         initService(properties);
67     }
68
69     /**
70      * Creates a Hessian SerializerFactory with Cayenne extensions.
71      */

72     SerializerFactory createSerializerFactory() {
73         return HessianConfig.createFactory(SERVER_SERIALIZER_FACTORIES, getRootChannel()
74                 .getEntityResolver());
75     }
76
77     protected HttpSession JavaDoc getSession(boolean create) {
78         HttpServletRequest JavaDoc request = (HttpServletRequest JavaDoc) ServiceContext
79                 .getContextRequest();
80         if (request == null) {
81             throw new IllegalStateException JavaDoc(
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