My Java code
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());
}
}
}
Everything works fine except on line where "addAttachment" is called,
error i get is
JavaClient: helma.xmlrpc.XmlRpcException: java.lang.NoSuchMethodException: com.sun.proxy.$Proxy2104.addAttachment(java.lang.String, int, java.util.Vector, [B)
can anyone help me with any other library which i should be using. it seems helma.xmlrpc doesn't have addAttachment method
I used org.apache.xmlrpc.client.XmlRpcClient and not helma but the concepts should be the same. It's not that "helma.xmlrpc doesn't have addAttachment method", it's just that you're calling addAttachment() with the wrong parameters. Try calling it with the proper parameters listed at 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)
so for apache xmlrpc, my partial code looks like:
//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});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.