KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > blogs > XMLRPCServlet


1 /*
2  * ____.
3  * __/\ ______| |__/\. _______
4  * __ .____| | \ | +----+ \
5  * _______| /--| | | - \ _ | : - \_________
6  * \\______: :---| : : | : | \________>
7  * |__\---\_____________:______: :____|____:_____\
8  * /_____|
9  *
10  * . . . i n j a h i a w e t r u s t . . .
11  *
12  *
13  *
14  * ----- BEGIN LICENSE BLOCK -----
15  * Version: JCSL 1.0
16  *
17  * The contents of this file are subject to the Jahia Community Source License
18  * 1.0 or later (the "License"); you may not use this file except in
19  * compliance with the License. You may obtain a copy of the License at
20  * http://www.jahia.org/license
21  *
22  * Software distributed under the License is distributed on an "AS IS" basis,
23  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
24  * for the rights, obligations and limitations governing use of the contents
25  * of the file. The Original and Upgraded Code is the Jahia CMS and Portal
26  * Server. The developer of the Original and Upgraded Code is JAHIA Ltd. JAHIA
27  * Ltd. owns the copyrights in the portions it created. All Rights Reserved.
28  *
29  * The Shared Modifications are Jahia View Helper.
30  *
31  * The Developer of the Shared Modifications is Jahia Solution Sàrl.
32  * Portions created by the Initial Developer are Copyright (C) 2002 by the
33  * Initial Developer. All Rights Reserved.
34  *
35  * ----- END LICENSE BLOCK -----
36  */

37
38 package org.jahia.blogs;
39
40 import org.jahia.blogs.api.BloggerAPI;
41 import org.jahia.blogs.api.MetaWeblogAPI;
42 import org.jahia.blogs.api.MovableTypeAPI;
43
44 import javax.servlet.ServletConfig JavaDoc;
45 import javax.servlet.ServletException JavaDoc;
46 import javax.servlet.http.HttpServlet JavaDoc;
47 import javax.servlet.http.HttpServletRequest JavaDoc;
48 import javax.servlet.http.HttpServletResponse JavaDoc;
49
50 import org.apache.xmlrpc.XmlRpcServer;
51
52 import org.apache.log4j.Logger;
53
54 import java.io.OutputStream JavaDoc;
55 import java.io.IOException JavaDoc;
56
57 /**
58  * Basic Servlet accepting requests from XML-RPC blog clients
59  *
60  * @author Xavier Lawrence
61  */

62 public class XMLRPCServlet extends HttpServlet JavaDoc {
63     
64     // log4j logger
65
static Logger log = Logger.getLogger(MetaWeblogAPIImpl.class);
66     
67     private transient XmlRpcServer xmlRpcServer = new XmlRpcServer();
68     private BloggerAPI bloggerAPIHandler;
69     private MetaWeblogAPI metaWeblogAPIHandler;
70     private MovableTypeAPI movableTypeAPIHandler;
71        
72     /**
73      * Initializes the servlet.
74      */

75     public void init(ServletConfig JavaDoc config) throws ServletException JavaDoc {
76         super.init(config);
77         try {
78             bloggerAPIHandler = new BloggerAPIImpl();
79             xmlRpcServer.addHandler("blogger", bloggerAPIHandler);
80             
81             metaWeblogAPIHandler = new MetaWeblogAPIImpl();
82             xmlRpcServer.addHandler("metaWeblog", metaWeblogAPIHandler);
83             
84             movableTypeAPIHandler = new MovableTypeAPIImpl();
85             xmlRpcServer.addHandler("mt", movableTypeAPIHandler);
86             
87         } catch (Exception JavaDoc e) {
88             log.error("Initialization of XML-RPC servlet failed", e);
89         }
90     }
91     
92     /**
93      */

94     protected void service(HttpServletRequest JavaDoc request,
95             HttpServletResponse JavaDoc response)
96             throws ServletException JavaDoc, IOException JavaDoc {
97         log.debug("\n\nService for BLOG REQUEST");
98         
99         // Set ThreadLocal variables
100
ServletResources.setCurrentRequest(request);
101         ServletResources.setCurrentResponse(response);
102         ServletResources.setCurrentConfig(super.getServletConfig());
103         
104         byte[] result = xmlRpcServer.execute(request.getInputStream());
105         log.debug("Result: "+ new String JavaDoc(result));
106         
107         response.setContentType("text/xml");
108         response.setContentLength(result.length);
109         
110         OutputStream JavaDoc output = response.getOutputStream();
111         output.write(result);
112         output.flush();
113         
114         // Cleanup ThreadLocal variables
115
ServletResources.setCurrentRequest(null);
116         ServletResources.setCurrentResponse(null);
117         ServletResources.setCurrentConfig(null);
118         
119         log.debug("END Service for BLOG REQUEST\n");
120     }
121 }
122
Popular Tags