我尝试使用Apache的Xml-Rpc库在Java中进行方法调用时出现了一个奇怪的错误。这是设置:
XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
URL url = null;
try {
url = new URL(Config.getInstance().getProperty("foo.host"));
} catch (MalformedURLException e) {
e.printStackTrace();
}
config.setServerURL(url);
client = new XmlRpcClient();
client.setConfig(config);
//Generate Token for all admin calls
try {
token = (String) client.execute("confluence2.login",
new Object[]{ADMIN_USER, ADMIN_PASS});
} catch (XmlRpcException e) {
log.error("There was a problem getting the rpc token", e);
}
多个其他方法使用的辅助方法适用于除有问题之外的所有其他方法:
private <T> T executeWikiMethod(String method, Object[] params) throws WikiException {
try {
Object[] args = new Object[params.length + 1];
args[0] = token;
System.arraycopy(params, 0, args, 1, args.length - 1);
long startTime = System.currentTimeMillis();
T t = (T) client.execute(method, args);
log.debug(String.format("Wiki RPC call to method: %s and params: %s. Request completed in %dms", method, Arrays.toString(args), System.currentTimeMillis() - startTime));
return t;
} catch (XmlRpcException e) {
throw new WikiException(e.getMessage());
} catch (Exception e) {
log.error(e.getMessage());
throw new WikiException("An unexpected error occurred.");
}
}
最后,这里的方法打破了错误消息&#34;无法解析服务器响应:意外的非空白字符数据&#34;:
public Object getWikiUpdates(String wikiSpaceKey) throws WikiException {
Object result;
result = executeWikiMethod("recentupdate.getRecentUpdate", new Object[]{wikiSpaceKey, "10"});
return result;
}
堆栈跟踪:
Failed to parse servers response: Unexpected non-whitespace character data
at org.junit.Assert.fail(Assert.java:93)
at miniWikiTest.updatesTest(miniWikiTest.java:21)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at play.test.PlayJUnitRunner$StartPlay$2$1.evaluate(PlayJUnitRunner.java:114)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at play.test.PlayJUnitRunner.run(PlayJUnitRunner.java:58)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:24)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
at org.junit.runner.JUnitCore.run(JUnitCore.java:136)
at org.junit.runner.JUnitCore.run(JUnitCore.java:117)
at play.test.TestEngine.run(TestEngine.java:112)
at controllers.TestRunner$1.doJobWithResult(TestRunner.java:71)
at controllers.TestRunner$1.doJobWithResult(TestRunner.java:1)
at play.jobs.Job.call(Job.java:146)
at play.jobs.Job$1.call(Job.java:66)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:98)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:206)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
at java.lang.Thread.run(Thread.java:695)
应该有来自服务器的xml响应,使用RPC库将其解析为JSON对象。 getWikiUpdates()方法应该返回一个JSON块,表示维基页面的几种不同类型的更新(例如新注释等),其格式目前是未知的,因为调用返回错误而没有xml响应或任何JSON。我正在使用Object,希望能够捕获从方法调用返回的内容,并能够从那里格式化结果。这一切都在Play中完成!框架。如果我需要进一步澄清,请告诉我。谢谢。
编辑 - 服务器响应是&#34;意外的非空白字符数据&#34;,没有别的
答案 0 :(得分:0)
两件事 - 方法参数应该以confluence2开头,例如confluence2.getRecentUpdate。但这导致第二个问题......
“recentupdate.getRecentUpdate”不是有效的方法。我没有在这里看到任何类似的内容:https://developer.atlassian.com/confdev/confluence-rest-api/confluence-xml-rpc-and-soap-apis/remote-confluence-methods
查看你的代码,我认为你想要的可能是搜索方法之一,如矢量搜索(String token,String query,Map parameters,int maxResults),你可以在其中指定空间和限制等。
您可以使用方法名称“confluence2.search”
来调用它