File Source: xmlrpccontroller.java

         /* 
    P/P   *  Method: net.sourceforge.pebble.web.controller.XmlRpcController__static_init
          */
     1  /*
     2   * Copyright (c) 2003-2006, Simon Brown
     3   * All rights reserved.
     4   *
     5   * Redistribution and use in source and binary forms, with or without
     6   * modification, are permitted provided that the following conditions are met:
     7   *
     8   *   - Redistributions of source code must retain the above copyright
     9   *     notice, this list of conditions and the following disclaimer.
    10   *
    11   *   - Redistributions in binary form must reproduce the above copyright
    12   *     notice, this list of conditions and the following disclaimer in
    13   *     the documentation and/or other materials provided with the
    14   *     distribution.
    15   *
    16   *   - Neither the name of Pebble nor the names of its contributors may
    17   *     be used to endorse or promote products derived from this software
    18   *     without specific prior written permission.
    19   *
    20   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    21   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    22   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    23   * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
    24   * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    25   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    26   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    27   * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    28   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    29   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    30   * POSSIBILITY OF SUCH DAMAGE.
    31   */
    32  package net.sourceforge.pebble.web.controller;
    33  
    34  import net.sourceforge.pebble.webservice.BloggerAPIHandler;
    35  import net.sourceforge.pebble.webservice.MetaWeblogAPIHandler;
    36  import net.sourceforge.pebble.webservice.PebbleAPIHandler;
    37  import net.sourceforge.pebble.webservice.SearchAPIHandler;
         /* 
    P/P   *  Method: void net.sourceforge.pebble.web.controller.XmlRpcController()
          */
    38  import org.apache.xmlrpc.XmlRpcServer;
    39  import org.springframework.context.ApplicationContext;
    40  import org.springframework.web.context.support.WebApplicationContextUtils;
    41  
    42  import javax.servlet.ServletException;
    43  import javax.servlet.http.HttpServlet;
    44  import javax.servlet.http.HttpServletRequest;
    45  import javax.servlet.http.HttpServletResponse;
    46  import java.io.IOException;
    47  import java.io.OutputStream;
    48  
    49  /**
    50   * Single entry point for all XML-RPC requests (e.g. Blogger API).
    51   *
    52   * @author    Simon Brown
    53   */
    54  public class XmlRpcController extends HttpServlet {
    55  
    56    /**
    57     * Initialises this instance.
    58     */
           /* 
    P/P     *  Method: void init()
            */
    59    public void init() {
    60    }
    61  
    62    /**
    63     * Processes the request - this is delegated to from doGet and doPost.
    64     *
    65     * @param request   the HttpServletRequest instance
    66     * @param response   the HttpServletResponse instance
    67     */
    68    protected void processRequest(HttpServletRequest request,
    69                                  HttpServletResponse response)
    70        throws ServletException, IOException {
    71  
    72      try {
               /* 
    P/P         *  Method: void processRequest(HttpServletRequest, HttpServletResponse)
                * 
                *  Preconditions:
                *    request != null
                *    response != null
                * 
                *  Presumptions:
                *    javax.servlet.http.HttpServletResponse:getOutputStream(...)@91 != null
                *    org.apache.xmlrpc.XmlRpcServer:execute(...)@88 != null
                *    org.springframework.web.context.support.WebApplicationContextUtils:getWebApplicationContext(...)@74 != null
                *    result.length@88 <= 232-1
                */
    73        XmlRpcServer xmlrpc = new XmlRpcServer();
    74        ApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
    75  
    76        BloggerAPIHandler bloggerApi = (BloggerAPIHandler)ctx.getBean("bloggerApiHandler");
    77        xmlrpc.addHandler("blogger", bloggerApi);
    78  
    79        MetaWeblogAPIHandler metaweblogApi = (MetaWeblogAPIHandler)ctx.getBean("metaweblogApiHandler");
    80        xmlrpc.addHandler("metaWeblog", metaweblogApi);
    81  
    82        PebbleAPIHandler pebbleApi = (PebbleAPIHandler)ctx.getBean("pebbleApiHandler");
    83        xmlrpc.addHandler("pebble", pebbleApi);
    84  
    85        SearchAPIHandler searchApi = (SearchAPIHandler)ctx.getBean("searchApiHandler");
    86        xmlrpc.addHandler("search", searchApi);
    87  
    88        byte[] result = xmlrpc.execute(request.getInputStream());
    89        response.setContentType("text/xml; charset=UTF-8");
    90        response.setContentLength(result.length);
    91        OutputStream out = response.getOutputStream();
    92        out.write(result);
    93        out.flush();
    94      } catch (Exception e) {
    95        e.printStackTrace();
    96        throw new ServletException(e);
    97      }
    98    }
    99  
   100    /**
   101     * A default implementation of doGet that delegates to the processRequest method.
   102     *
   103     * @param req   the HttpServletRequest instance
   104     * @param res   the HttpServletResponse instance
   105     */
   106    protected void doGet(HttpServletRequest req, HttpServletResponse res)
   107        throws ServletException, IOException {
   108  
             /* 
    P/P       *  Method: void doGet(HttpServletRequest, HttpServletResponse)
              * 
              *  Preconditions:
              *    req != null
              *    res != null
              */
   109      processRequest(req, res);
   110    }
   111  
   112    /**
   113     * A default implementation of doPost that delegates to the processRequest method.
   114     *
   115     * @param req   the HttpServletRequest instance
   116     * @param res   the HttpServletResponse instance
   117     */
   118    protected void doPost(HttpServletRequest req, HttpServletResponse res)
   119        throws ServletException, IOException {
   120  
             /* 
    P/P       *  Method: void doPost(HttpServletRequest, HttpServletResponse)
              * 
              *  Preconditions:
              *    req != null
              *    res != null
              */
   121      processRequest(req, res);
   122    }
   123  
   124  }








SofCheck Inspector Build Version : 2.22510
xmlrpccontroller.java 2010-Jun-25 19:40:32
xmlrpccontroller.class 2010-Jul-19 20:23:38