xml-rpc method invocation
public Vector execute(UserProfile user, String methodName) throws XmlRpcException, IOException
{
Vector constants = null
Hashtable constant = null;
Vector params = new Vector(1);
XmlRpcClient xmlrpc = new XmlRpcClient(user.getUrl()+
EclipseJIRAConstants.XMLRPC_URL);
String loginToken = login(user);
params.add(loginToken);
constants = (Vector)xmlrpc.execute (EclipseJIRAConstants.JIRA_PREFIX+methodName, params);
logout(user, loginToken);
return constants;
}
private String login(UserProfile user)throws
XmlRpcException, IOException
{
XmlRpcClient xmlrpc = null;
Vector params = new Vector(2);
String loginToken = null;
xmlrpc = new XmlRpcClient (user.getUrl()+
EclipseJIRAConstants.XMLRPC_URL);
params.add(user.getUserID()); // userid
params.add(user.getPassword()); // password
// this method returns a string
loginToken = (String)xmlrpc.execute(EclipseJIRAConstants.JIRA_PREFIX+
EclipseJIRAConstants.LOGIN_METHOD , params);
returnloginToken;
}
private void logout(UserProfile user, String loginToken)
throws
XmlRpcException, IOException
{
XmlRpcClient xmlrpc = null;
Vector params = new Vector(1);
xmlrpc = new XmlRpcClient (user.getUrl()+
EclipseJIRAConstants.XMLRPC_URL);
params.add(loginToken); // token
// this method returns a string
xmlrpc.execute(EclipseJIRAConstants.JIRA_PREFIX+ EclipseJIRAConstants.LOGOUT_METHOD, params);
}
RSS Feed Processing Using Java
This section describes how to process RSS Feed using Java
Step 1: First get the RSS feed by reading the appropriate URL
public String sendURL(String location) throwsIOException
{
URL url;
StringBuffer stringBuf = new StringBuffer();
url =new URL(location);
BufferedReader in = new BufferedReader( new InputStreamReader( url.openStream(),"UTF-8"));
String inputLine;
boolean foundRSS = false;
boolean isRSSEnd = false;
while((inputLine = in.readLine()) != null)
{
if(inputLine.matches(".*<rss.*"))
{
foundRSS = true;
}
if(foundRSS)
{
inputLine = unicodeToStr(inputLine);
inputLine = replaceHTMLEncoding(inputLine);
stringBuf.append(inputLine);
// System.out.println(inputLine);
if(inputLine.matches(".*</rss>.*"))
{
isRSSEnd = true
}
}
if (isRSSEnd)
{
break;
}
}
in.close();
}
Step 2: Use the RSSDigester Class (provided by Apache, http://jakarta.apache.org/commons/digester/)to parse the RSS feed.
RSSDigester rssDigester = null;
String rssString = null;
Channel rssChannel = null;
Item[] issues = null;
StringReader stringReader = null;
rssString = sendURL(location);
rssDigester = new RSSDigester();
addItemProperties(rssDigester);
stringReader = new StringReader(rssString);
rssChannel = (Channel)rssDigester.parse(stringReader);
stringReader.close();
issues = rssChannel.getItems();
Step 3: If the item in the RSS is different from what is supported by RSSDigester, Define your own Item class
public class IssueItem extends Item {
protectedString environment;
protected String key;
protected String keyID;
protected String summary;
protected String type;
protectedint typeID;
protected String priority;
protectedint priorityID;
protected String status;
protected int statusID;
protected String resolution;
protected String assignee;
protected String assigneeUsername;
protected String reporter;
protected String reporterUsername;
protected String created;
protected String updated;
protected String version;
protected String fixVersion;
protected String component;
protected String due;
protected String customfields;
Step 4: If you have your own Item class, make sure the properties are set in the RSSDigester
protected void addItemProperties(RSSDigester rssDigester)
{
rssDigester.setItemClass(EclipseJIRAConstants.ISSUE_ITEM);
rssDigester.addBeanPropertySetter("rss/channel/item/key","key");
rssDigester.addSetProperties("rss/channel/item/key",
"id", "keyID");
rssDigester.addBeanPropertySetter("rss/channel/item/environment",
"environment");
rssDigester.addBeanPropertySetter("rss/channel/item/summary",
"summary");
rssDigester.addBeanPropertySetter("rss/channel/item/type",
"type");
rssDigester.addSetProperties("rss/channel/item/type",
"id", "typeID");
rssDigester.addBeanPropertySetter("rss/channel/item/priority",
"priority");
rssDigester.addSetProperties("rss/channel/item/priority",
"id", "priorityID");
rssDigester.addBeanPropertySetter("rss/channel/item/status",
"status");
rssDigester.addSetProperties("rss/channel/item/status",
"id", "statusID");
rssDigester.addBeanPropertySetter("rss/channel/item/resolution",
"resolution");
rssDigester.addBeanPropertySetter("rss/channel/item/assignee",
"assignee");
rssDigester.addSetProperties("rss/channel/item/assignee",
"username", "assigneeUsername");
rssDigester.addBeanPropertySetter("rss/channel/item/reporter",
"reporter");
rssDigester.addSetProperties("rss/channel/item/reporter",
"username", "reporterUsername");
rssDigester.addBeanPropertySetter("rss/channel/item/created",
"created");
rssDigester.addBeanPropertySetter("rss/channel/item/updated",
"updated");
rssDigester.addBeanPropertySetter("rss/channel/item/version",
"version");
rssDigester.addBeanPropertySetter("rss/channel/item/fixVersion",
"fixVersion");
rssDigester.addBeanPropertySetter("rss/channel/item/component",
"component");
rssDigester.addBeanPropertySetter("rss/channel/item/due",
"due");
rssDigester.addB../../eanPropertySetter("rss/channel/item/customfields",
"customfields");
}