我正在尝试针对 json-rpc API 编写 confluence(在 java 中)。但是,我得到了 404。我知道我正在访问服务器并通过日志进行身份验证(基本身份验证):
2013-10-08 10:48:59,586 DEBUG [http-8090-2] [atlassian.seraph.filter.BaseLoginFilter] doFilter doFilter : ____ Attempting login for : '/confluence/rpc/json-rpc/confluenceservice-v2'
2013-10-08 10:48:59,586 DEBUG [http-8090-2] [atlassian.seraph.filter.PasswordBasedLoginFilter] login login : No user name or password was returned. No authentication attempt will be made. User may still be found via a SecurityFilter later.
2013-10-08 10:48:59,586 DEBUG [http-8090-2] [atlassian.seraph.filter.BaseLoginFilter] doFilter doFilter : Login completed for 'null' - os_authstatus = 'null'
2013-10-08 10:48:59,587 DEBUG [http-8090-2] [atlassian.seraph.filter.SecurityFilter] doFilter doFilter : Storing the originally requested URL (atlassian.core.seraph.original.url=/confluence/rpc/json-rpc/confluenceservice-v2)
(很好,请参阅 rpc 调用)
2013-10-07 16:25:22,580 DEBUG [http-8090-2] [atlassian.seraph.auth.DefaultAuthenticator] login login : 'george' has been authenticated
2013-10-07 16:25:22,582 DEBUG [http-8090-2] [atlassian.seraph.auth.DefaultAuthenticator] authoriseUserAndEstablishSession authoriseUser : 'george' can login according to the RoleMapper
2013-10-07 16:25:22,584 DEBUG [http-8090-2] [net.sf.hibernate.SQL] log update logininfo set CURFAILED=?, TOTALFAILED=?, SUCCESSDATE=?, PREVSUCCESSDATE=?, FAILEDDATE=?, USERNAME=? where id=?
2013-10-07 16:25:22,586 DEBUG [http-8090-2] [atlassian.seraph.auth.DefaultAuthenticator] getUserFromBasicAuthentication getUserFromSession : Authenticated 'george' via Basic Auth
2013-10-07 16:25:22,587 DEBUG [http-8090-2] [atlassian.seraph.filter.SecurityFilter] doFilter doFilter : Setting Auth Context to be 'george'
但是对 URL 的帖子的响应
http://my.confluence.host.com:8090/confluence/rpc/json-rpc/confluenceservice-v2
与身体
"{ \"jsonrpc\" : \"2.0\", \"方法\" : \"getServerInfo\", \"id\" : 12345}"
返回 404。
下一个日志条目是
2013-10-08 10:48:59,626 DEBUG [http-8090-2] [atlassian.seraph.filter.SecurityFilter] doFilter doFilter : Storing the originally requested URL (atlassian.core.seraph.original.url=/fourohfour.action)
插件已启用。
谢谢你的帮助!
编码:
@Test
public void test() {
RestTemplate rt = new TestRestTemplate();
String url = "http://my.confluence.host.com:8090/confluence/rpc/json-rpc/confluenceservice-v2";
rt.getMessageConverters().add(new MappingJacksonHttpMessageConverter());
rt.getMessageConverters().add(new StringHttpMessageConverter());
String body = "{ \"jsonrpc\" : \"2.0\", \"method\" : \"getServerInfo\", \"id\" : 12345}";
String returnValue = rt.postForObject(url, body, String.class);
}
private static final class TestRestTemplate extends RestTemplate {
@Override
protected ClientHttpRequest createRequest(URI url, HttpMethod method) throws IOException {
ClientHttpRequest request = super.createRequest(url, method);
String authentication = Base64.encode("george:password".getBytes());
request.getHeaders().add("Authorization", "Basic " + authentication);
return request;
}
}