Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
TurbineJsonRpcService |
|
| 1.2;1,2 |
1 | package org.apache.turbine.services.jsonrpc; | |
2 | ||
3 | /* | |
4 | * Licensed to the Apache Software Foundation (ASF) under one | |
5 | * or more contributor license agreements. See the NOTICE file | |
6 | * distributed with this work for additional information | |
7 | * regarding copyright ownership. The ASF licenses this file | |
8 | * to you under the Apache License, Version 2.0 (the | |
9 | * "License"); you may not use this file except in compliance | |
10 | * with the License. You may obtain a copy of the License at | |
11 | * | |
12 | * http://www.apache.org/licenses/LICENSE-2.0 | |
13 | * | |
14 | * Unless required by applicable law or agreed to in writing, | |
15 | * software distributed under the License is distributed on an | |
16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
17 | * KIND, either express or implied. See the License for the | |
18 | * specific language governing permissions and limitations | |
19 | * under the License. | |
20 | */ | |
21 | ||
22 | import java.io.CharArrayWriter; | |
23 | ||
24 | import javax.servlet.http.HttpServletRequest; | |
25 | import javax.servlet.http.HttpSession; | |
26 | ||
27 | import org.apache.turbine.services.TurbineBaseService; | |
28 | import org.jabsorb.JSONRPCBridge; | |
29 | ||
30 | ||
31 | /** | |
32 | * This is a service that will respond to JSON-RPC calls. | |
33 | * | |
34 | * @author <a href="mailto:seade@backstagetech.com.au">Scott Eade</a> | |
35 | * @version $Id: TurbineJsonRpcService.java 1706239 2015-10-01 13:18:35Z tv $ | |
36 | */ | |
37 | 0 | public class TurbineJsonRpcService |
38 | extends TurbineBaseService | |
39 | implements JsonRpcService | |
40 | { | |
41 | /** The key used to store the bridge in the session. */ | |
42 | public static final String JSON_BRIDGE_KEY = "JSONRPCBridge"; | |
43 | ||
44 | @Override | |
45 | public Object processCall(CharArrayWriter cdata, | |
46 | JSONRPCBridge json_bridge, HttpServletRequest request) | |
47 | { | |
48 | 0 | return JSONProcessor.processCall(cdata, json_bridge, request); |
49 | } | |
50 | ||
51 | @Override | |
52 | public void registerObjectGlobal(String key, Object value) | |
53 | { | |
54 | 0 | JSONRPCBridge.getGlobalBridge().registerObject(key, value); |
55 | 0 | } |
56 | ||
57 | @Override | |
58 | public void registerObject(HttpSession session, String key, Object value) | |
59 | { | |
60 | 0 | JSONRPCBridge json_bridge = getBridge(session); |
61 | 0 | json_bridge.registerObject(key, value); |
62 | 0 | } |
63 | ||
64 | @Override | |
65 | public JSONRPCBridge getBridge(HttpSession session) | |
66 | { | |
67 | 0 | JSONRPCBridge json_bridge = (JSONRPCBridge) session.getAttribute(JSON_BRIDGE_KEY); |
68 | 0 | if (json_bridge == null) |
69 | { | |
70 | 0 | json_bridge = new JSONRPCBridge(); |
71 | 0 | session.setAttribute(JSON_BRIDGE_KEY, json_bridge); |
72 | } | |
73 | 0 | return json_bridge; |
74 | } | |
75 | ||
76 | @Override | |
77 | public void clearBridge(HttpSession session) | |
78 | { | |
79 | 0 | session.removeAttribute(JSON_BRIDGE_KEY); |
80 | 0 | } |
81 | ||
82 | // The following is modeled on XmlRpcSercice. | |
83 | // /** | |
84 | // * Initialize the JsonRpcService. | |
85 | // * | |
86 | // * @throws InitializationException Something went wrong in the init stage. | |
87 | // */ | |
88 | // public void init() throws InitializationException | |
89 | // { | |
90 | // //Configuration conf = getConfiguration(); | |
91 | // setInit(true); | |
92 | // } | |
93 | // | |
94 | // /** | |
95 | // * Shuts down this service, stopping running threads. | |
96 | // */ | |
97 | // public void shutdown() | |
98 | // { | |
99 | // setInit(false); | |
100 | // } | |
101 | ||
102 | } |