我的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(字符串令牌,长contentId,附件附件,字节[] annexData)


因此对于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});

09-05 19:30