Search in sources :

Example 1 with XmlRpcContext

use of org.apache.xmlrpc.XmlRpcContext in project jspwiki by apache.

the class RPCServlet method doPost.

/**
 *  Handle HTTP POST.  This is an XML-RPC call, and we'll just forward
 *  the query to an XmlRpcServer.
 */
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException {
    log.debug("Received POST to RPCServlet");
    try {
        WikiContext ctx = m_engine.createContext(request, WikiContext.NONE);
        XmlRpcContext xmlrpcContext = new WikiXmlRpcContext(m_xmlrpcServer.getHandlerMapping(), ctx);
        byte[] result = m_xmlrpcServer.execute(request.getInputStream(), xmlrpcContext);
        // 
        // I think it's safe to write the output as UTF-8:
        // The XML-RPC standard never creates other than USASCII
        // (which is UTF-8 compatible), and our special UTF-8
        // hack just creates UTF-8.  So in all cases our butt
        // should be covered.
        // 
        response.setContentType("text/xml; charset=utf-8");
        response.setContentLength(result.length);
        OutputStream out = response.getOutputStream();
        out.write(result);
        out.flush();
    // log.debug("Result = "+new String(result) );
    } catch (IOException e) {
        throw new ServletException("Failed to build RPC result", e);
    }
}
Also used : ServletException(javax.servlet.ServletException) WikiContext(org.apache.wiki.WikiContext) XmlRpcContext(org.apache.xmlrpc.XmlRpcContext) OutputStream(java.io.OutputStream) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 ServletException (javax.servlet.ServletException)1 WikiContext (org.apache.wiki.WikiContext)1 XmlRpcContext (org.apache.xmlrpc.XmlRpcContext)1