我的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());
}
}
}
除了调用“addAttachment”的行之外,一切正常,
我得到的错误是
JavaClient: helma.xmlrpc.XmlRpcException: java.lang.NoSuchMethodException: com.sun.proxy.$Proxy2104.addAttachment(java.lang.String, int, java.util.Vector, [B)
任何人都可以帮助我使用我应该使用的任何其他库。看来 helma.xmlrpc 没有 addAttachment 方法
最佳答案
我使用了 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});
关于java - 使用 Java 时 XML-RPC 中的 addAttachment 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22612601/