How do you post via XMLRPC?

How on earth do you setup a page to post over XMLRPC using the Apache XMLRPC classes?

Miles found me this page but I swear, I can not get it to work at all. Anyway I tried to adopt the blojsom admin edit plugin to fit the purpose but still cant get that working either. So I'm stuck now…

Been doing more research into the whole problem.
apache xml-rpc metaWeblog api

Miles solves it…
Variables needed for it work, title, description, category. Stick these in html form elements with a form method=”post”, action=”thexmlrpc.jsp” and submit button and your away. Oh dont forget the Apache XMLRPC classes.

<%@ page import="org.apache.xmlrpc.*,
                java.util.*"%>
< ?xml version="1.0" encoding="UTF-8"? >
< !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" >
< html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en" >
< head >
< title >Blogging using XMLRPC from a JSP based webclient< /title >
< /head >


<% // Grab the variables from the form before. String title = request.getParameter("title"); String description = request.getParameter("description"); String category = request.getParameter("category"); String blogServer = "http://something/blojsom/xmlrpc/blog"; // This is crap as we should really not use a hard-coded path //String errorUrl = "http://a/url/that/you/post/from"; // Slightly less crap... String errorUrl = request.getHeader("Referer"); Vector params=null; if ((title == null) || (title.length() < 1)) { response.sendRedirect(response.encodeRedirectURL(errorUrl )); } if ((description == null) || (description.length() < 1)) { response.sendRedirect(response.encodeRedirectURL( errorUrl )); } if ((category == null) || (category.length() < 1)) { response.sendRedirect(response.encodeRedirectURL( errorUrl )); } // Create XML RPC Client object XmlRpcClient xmlrpc=new XmlRpcClient(blogServer); Hashtable structContents=new Hashtable(); structContents.put("category", category); structContents.put("title", title); structContents.put("description", description); Boolean Booly = new Boolean(true); params=new Vector(); // Dummy for blojsom params.add("1"); params.add("username"); params.add("password"); params.add(structContents); // Publish this post params.add(Booly); String created = (String)xmlrpc.execute("metaWeblog.newPost",params); out.println("< p >This is the result: " + created + ".< /p >");
out.println("< p >This is the title: " + title + ".< /p >");
out.println("< p >This is the description: " + description + ".< /p >");
out.println("< p >This is the category: " + category + ".< /p >");
%>
< /body >
< /html >

Comments [Comments]
Trackbacks [0]

Author: Ianforrester

Senior firestarter at BBC R&D, emergent technology expert and serial social geek event organiser. Can be found at cubicgarden@mas.to, cubicgarden@twit.social and cubicgarden@blacktwitter.io