File Source: AdminServlet.java
1 /*
2 * Copyright 2005 David M Johnson (For RSS and Atom In Action)
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.apache.roller.weblogger.webservices.adminprotocol;
17
18 import java.io.IOException;
19 import java.io.InputStreamReader;
20 import java.io.Writer;
21
22 import javax.servlet.ServletException;
23 import javax.servlet.http.HttpServlet;
24 import javax.servlet.http.HttpServletRequest;
25 import javax.servlet.http.HttpServletResponse;
26 import org.apache.commons.logging.Log;
27 import org.apache.commons.logging.LogFactory;
28 import org.jdom.Document;
29 import org.jdom.output.XMLOutputter;
30 import org.jdom.output.Format;
31 import org.apache.roller.weblogger.webservices.adminprotocol.sdk.EntrySet;
32
33 /**
34 * Atom Admin Servlet implements the Atom Admin endpoint.
35 * This servlet simply delegates work to a particular handler object.
36 *
37 * @author jtb
38 * @web.servlet name="AdminServlet"
39 * @web.servlet-mapping url-pattern="/roller-services/rap/*"
40 */
/*
P/P * Method: void org.apache.roller.weblogger.webservices.adminprotocol.AdminServlet()
*/
41 public class AdminServlet extends HttpServlet {
/*
P/P * Method: org.apache.roller.weblogger.webservices.adminprotocol.AdminServlet__static_init
*
* Presumptions:
* org.apache.commons.logging.LogFactory:getFactory(...)@42 != null
*
* Postconditions:
* init'ed(logger)
*/
42 private static Log logger = LogFactory.getFactory().getInstance(AdminServlet.class);
43
44 /**
45 * Handles an Atom GET by calling handler and writing results to response.
46 */
47 protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
48 try {
/*
P/P * Method: void doGet(HttpServletRequest, HttpServletResponse)
*
* Preconditions:
* res != null
* (soft) logger != null
* (soft) org/apache/roller/weblogger/webservices/adminprotocol/Handler$URI.PATHINFO_PATTERN != null
*
* Presumptions:
* javax.servlet.http.HttpServletResponse:getWriter(...)@57 != null
* processGet(...)@52 != null
*/
+ 49 Handler handler = Handler.getHandler(req);
+ 50 String userName = handler.getUserName();
51
52 EntrySet c = handler.processGet();
53
54 res.setStatus(HttpServletResponse.SC_OK);
55 res.setContentType("application/xml; charset=utf-8");
56 String s = c.toString();
57 Writer writer = res.getWriter();
58 writer.write(s);
59 writer.close();
60 } catch (HandlerException he) {
61 res.sendError(he.getStatus(), he.getMessage());
62 he.printStackTrace(res.getWriter());
63 logger.error(he);
64 }
65 }
66
67 /**
68 * Handles an Atom POST by calling handler to identify URI, reading/parsing
69 * data, calling handler and writing results to response.
70 */
71 protected void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
72 try {
/*
P/P * Method: void doPost(HttpServletRequest, HttpServletResponse)
*
* Preconditions:
* res != null
* (soft) logger != null
* (soft) org/apache/roller/weblogger/webservices/adminprotocol/Handler$URI.PATHINFO_PATTERN != null
*
* Presumptions:
* javax.servlet.http.HttpServletResponse:getWriter(...)@81 != null
* processPost(...)@76 != null
*/
+ 73 Handler handler = Handler.getHandler(req);
+ 74 String userName = handler.getUserName();
75
76 EntrySet c = handler.processPost(new InputStreamReader(req.getInputStream()));
77
78 res.setStatus(HttpServletResponse.SC_CREATED);
79 res.setContentType("application/xml; charset=utf-8");
80 String s = c.toString();
81 Writer writer = res.getWriter();
82 writer.write(s);
83 writer.close();
84 } catch (HandlerException he) {
85 res.sendError(he.getStatus(), he.getMessage());
86 he.printStackTrace(res.getWriter());
87 logger.error(he);
88 }
89 }
90
91 /**
92 * Handles an Atom PUT by calling handler to identify URI, reading/parsing
93 * data, calling handler and writing results to response.
94 */
95 protected void doPut(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
96 try {
/*
P/P * Method: void doPut(HttpServletRequest, HttpServletResponse)
*
* Preconditions:
* res != null
* (soft) logger != null
* (soft) org/apache/roller/weblogger/webservices/adminprotocol/Handler$URI.PATHINFO_PATTERN != null
*
* Presumptions:
* javax.servlet.http.HttpServletResponse:getWriter(...)@105 != null
* processPut(...)@100 != null
*/
+ 97 Handler handler = Handler.getHandler(req);
+ 98 String userName = handler.getUserName();
99
100 EntrySet c = handler.processPut(new InputStreamReader(req.getInputStream()));
101
102 res.setStatus(HttpServletResponse.SC_OK);
103 res.setContentType("application/xml; charset=utf-8");
104 String s = c.toString();
105 Writer writer = res.getWriter();
106 writer.write(s);
107 writer.close();
108 } catch (HandlerException he) {
109 res.sendError(he.getStatus(), he.getMessage());
110 he.printStackTrace(res.getWriter());
111 logger.error(he);
112 }
113 }
114
115 /**
116 * Handle Atom Admin DELETE by calling appropriate handler.
117 */
118 protected void doDelete(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
119 try {
/*
P/P * Method: void doDelete(HttpServletRequest, HttpServletResponse)
*
* Preconditions:
* res != null
* (soft) logger != null
* (soft) org/apache/roller/weblogger/webservices/adminprotocol/Handler$URI.PATHINFO_PATTERN != null
*
* Presumptions:
* javax.servlet.http.HttpServletResponse:getWriter(...)@128 != null
* processDelete(...)@123 != null
*/
+ 120 Handler handler = Handler.getHandler(req);
+ 121 String userName = handler.getUserName();
122
123 EntrySet es = handler.processDelete();
124
125 res.setStatus(HttpServletResponse.SC_OK);
126 res.setContentType("application/xml; charset=utf-8");
127 String s = es.toString();
128 Writer writer = res.getWriter();
129 writer.write(s);
130 writer.close();
131 } catch (HandlerException he) {
132 res.sendError(he.getStatus(), he.getMessage());
133 he.printStackTrace(res.getWriter());
134 logger.error(he);
135 }
136 }
137 }
SofCheck Inspector Build Version : 2.18479
| AdminServlet.java |
2009-Jan-02 14:25:24 |
| AdminServlet.class |
2009-Sep-04 03:12:45 |