2006/04/01 13:17 Developer
XML-RPC로 이글루스에 글등록하기 - JAVA버젼
[CODE]
/*
* @File Name : EGLOOSRpcClient.java
* @Author : 윤주선 , ologist
* @Date : 2006. 1. 13.
* @Copyright : Copyright ⓒ XXX Corp. All Rights Reserved.
*/
package com.XXX.common.xmlrpc.client;
import java.io.IOException;
import java.net.URL;
import java.util.Hashtable;
import java.util.StringTokenizer;
import java.util.Vector;
import org.apache.xmlrpc.XmlRpcClient;
import org.apache.xmlrpc.XmlRpcException;
public class EGLOOSRpcClient {
public EGLOOSRpcClient() {
super();
}
// The location of our server.
private final static String server_url = "http://rpc.egloos.com/rpc1";
public static void main (String [] args) {
try {
long start = System.currentTimeMillis();
URL url = new URL(server_url);
XmlRpcClient server = new XmlRpcClient(url);
//insertPost(server);
getPost(server);
long end = System.currentTimeMillis();
System.out.println("[MAIN] RUNNING TIME : " + (end - start)/1000f+ " secs");
}catch (Exception exception) {
if (exception instanceof XmlRpcException) {
System.err.println("[EGLOOSRpcClient ] Exception closing URLConnection");
}else if (exception instanceof IOException) {
System.err.println("[EGLOOSRpcClient ] Server returned HTTP response code: 500 for URL: http://rpc.egloos.com/rpc1");
}
System.err.println("EGLOOSRpcClient : " + exception.toString());
}
}
public static void insertPost(XmlRpcClient server) throws XmlRpcException, IOException{
String category = "[lab] IT";
String subject = "Posting with MetaWeblog API!!";
String content = "본문 테스트!!";
content = "" + content;
Vector params = new Vector();
params.add("ologist");
params.add("ologist");
params.add("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
Hashtable struct = new Hashtable();
struct.put("title", subject);
struct.put("description", content );
//struct.put( "dateCreated", "20050716T19:20:30" );
Vector categories = new Vector();
if (category != null) {
StringTokenizer tok = new StringTokenizer(category, ",");
while (tok.hasMoreTokens()) {
categories.add(tok.nextToken().trim());
}
}
struct.put("categories", categories);
params.add(struct);
params.add(Boolean.TRUE);
String postId = (String) server.execute("metaWeblog.newPost", params);
System.out.println("value: " + postId);
}
public static Hashtable getPost(XmlRpcClient server) throws XmlRpcException, IOException{
Vector params = new Vector();
params.addElement(new String("1220385"));
params.addElement(new String("ologist"));
params.addElement(new String("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"));
Hashtable value = (Hashtable) server.execute("metaWeblog.getPost", params);
return value;
}
}
[/CODE]
간단하게 자바로 이글루스API중에 하나인 metaWeblog API를 이용해서 구현한 코드이다.
가장 기본적인 코드로 구성을 했기때문에 어렵지 않을것이다.
TAG XML-RPC