我的Java代码
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Vector;
import helma.xmlrpc.*;
public class test {
private final static String server_url =
"http://confluence.xyz.com:8080/rpc/xmlrpc";
public static void main (String [] args) {
try {
XmlRpcClient server = new XmlRpcClient(server_url);
Vector<Object> params = new Vector<Object>(2);
params.add("user");
params.add("pass");
String token = (String) server.execute("confluence2.login", params );
System.out.println(token);
Vector<Object> page = new Vector<Object>(3);
page.add(token);
page.add("~username");
page.add("test_page");
Object token1 = server.execute("confluence2.getPage", page );
System.out.println(token1.hashCode());
String fileName = "C:/New folder/a.jpeg";
String contentType = "image/jpeg";
Vector<Object> attachment = new Vector<Object>(2);
attachment.add("a.jpeg");
attachment.add(contentType);
System.out.println(attachment);
byte[] bytes = Files.readAllBytes(Paths.get(fileName));
System.out.println(bytes);
Vector<Object> attach = new Vector<Object>(4);
attach.add(token);
attach.add(token1.hashCode());
attach.add(attachment);
attach.add(bytes);
System.out.println(attach);
server.execute("confluence2.addAttachment", attach);
}
catch (Exception exception) {
System.err.println("JavaClient: " + exception.toString());
}
}
}
一切正常,除了在线&#34; addAttachment&#34;被称为,
我得到的错误是
JavaClient: helma.xmlrpc.XmlRpcException: java.lang.NoSuchMethodException: com.sun.proxy.$Proxy2104.addAttachment(java.lang.String, int, java.util.Vector, [B)
任何人都可以帮助我使用我应该使用的任何其他库。似乎helma.xmlrpc没有addAttachment方法
答案 0 :(得分:0)
我使用的是org.apache.xmlrpc.client.XmlRpcClient而不是helma,但概念应该是相同的。这不是“helma.xmlrpc没有addAttachment方法”,只是你用不正确的参数调用addAttachment()。尝试使用https://developer.atlassian.com/confdev/confluence-rest-api/confluence-xml-rpc-and-soap-apis/remote-confluence-methods
中列出的适当参数调用它addAttachment(String token,long contentId,Attachment attachment,byte [] attachmentData)
所以对于apache xmlrpc,我的部分代码如下:
//add attachment to the page
byte[] bytes = FileUtils.readFileToByteArray(new File(FILE_TO_ATTACH));
Map<String, String> attachInfo = new HashMap<String, String>();
attachInfo.put("fileName", FILENAME);
attachInfo.put("contentType", CONTENT_TYPE);
attachInfo.put("comment", COMMENT);
//actually add it now
client.execute("confluence1.addAttachment", new Object[]{token, PAGEID, attachInfo, bytes});