|
1 |
| package net.sf.crispy.impl.xmlrpc; |
|
2 |
| |
|
3 |
| import java.io.IOException; |
|
4 |
| import java.io.OutputStream; |
|
5 |
| import java.util.Hashtable; |
|
6 |
| import java.util.List; |
|
7 |
| import java.util.Map; |
|
8 |
| |
|
9 |
| import javax.servlet.ServletConfig; |
|
10 |
| import javax.servlet.ServletException; |
|
11 |
| import javax.servlet.http.HttpServlet; |
|
12 |
| import javax.servlet.http.HttpServletRequest; |
|
13 |
| import javax.servlet.http.HttpServletResponse; |
|
14 |
| |
|
15 |
| import net.sf.crispy.util.Util; |
|
16 |
| |
|
17 |
| import org.apache.commons.logging.Log; |
|
18 |
| import org.apache.commons.logging.LogFactory; |
|
19 |
| import org.apache.xmlrpc.XmlRpcServer; |
|
20 |
| |
|
21 |
| |
|
22 |
| |
|
23 |
| |
|
24 |
| |
|
25 |
| |
|
26 |
| |
|
27 |
| |
|
28 |
| public class XmlRpcHttpAdminServlet extends HttpServlet { |
|
29 |
| |
|
30 |
| protected static final Log log = LogFactory.getLog (XmlRpcAdminServiceImpl.class); |
|
31 |
| |
|
32 |
| private static final long serialVersionUID = 5325412481289471271L; |
|
33 |
| protected XmlRpcAdminServiceImpl adminService = null; |
|
34 |
| |
|
35 |
| |
|
36 |
2
| public void init(ServletConfig config) throws ServletException {
|
|
37 |
2
| Map lvMapService = new Hashtable();
|
|
38 |
2
| adminService = new XmlRpcAdminServiceImpl(new XmlRpcServer(), lvMapService, null);
|
|
39 |
2
| initTest();
|
|
40 |
| } |
|
41 |
| |
|
42 |
2
| private void initTest() {
|
|
43 |
2
| try {
|
|
44 |
2
| Object lvEchoImpl = Util.createObject("test.crispy.example.service.EchoImpl");
|
|
45 |
2
| adminService.addService("test.crispy.example.service.Echo", lvEchoImpl);
|
|
46 |
| } catch (Exception e) { |
|
47 |
| if (log.isDebugEnabled()) { log.debug("Can't load Test-Class test.crispy.example.service.Echo."); } |
|
48 |
| } |
|
49 |
| } |
|
50 |
| |
|
51 |
| |
|
52 |
1
| public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
|
|
53 |
1
| synchronized (adminService) {
|
|
54 |
1
| XmlRpcServer lvXmlRpcServer = adminService.getXmlRpcServer();
|
|
55 |
1
| byte[] result = lvXmlRpcServer.execute(req.getInputStream ());
|
|
56 |
1
| res.setContentType("text/xml");
|
|
57 |
1
| res.setContentLength(result.length);
|
|
58 |
1
| OutputStream output = res.getOutputStream();
|
|
59 |
1
| output.write(result);
|
|
60 |
1
| output.flush();
|
|
61 |
| } |
|
62 |
| } |
|
63 |
| |
|
64 |
| |
|
65 |
1
| public String addService(String pvServiceInterface, String pvImplClass) {
|
|
66 |
1
| return adminService.addService(pvServiceInterface, pvImplClass);
|
|
67 |
| } |
|
68 |
| |
|
69 |
1
| public String addService(String pvServiceInterface, Object pvServiceImpl) {
|
|
70 |
1
| return adminService.addService(pvServiceInterface, pvServiceImpl);
|
|
71 |
| } |
|
72 |
| |
|
73 |
| |
|
74 |
1
| public String removeService(String pvServiceInterface) {
|
|
75 |
1
| return adminService.removeService(pvServiceInterface);
|
|
76 |
| } |
|
77 |
| |
|
78 |
2
| public Boolean existService(String pvServiceInterface) {
|
|
79 |
2
| return adminService.existService(pvServiceInterface);
|
|
80 |
| } |
|
81 |
| |
|
82 |
3
| public List getAllService() {
|
|
83 |
3
| return adminService.getAllService();
|
|
84 |
| } |
|
85 |
| |
|
86 |
| |
|
87 |
| } |