Domanda

I'm attempting to write against the json-rpc API for confluence (in java). However, I'm getting a 404. I know that I'm getting to the server and authenticating (Basic auth) via the logs:

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)

(that's good, see the rpc call)

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'

But the response to a post to the URL

http://my.confluence.host.com:8090/confluence/rpc/json-rpc/confluenceservice-v2

with a body of

"{ \"jsonrpc\" : \"2.0\", \"method\" : \"getServerInfo\", \"id\" : 12345}"

returns with a 404.

The next log entry is

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)

Plugin is enabled.

Thanks for any help!

The code:

@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;
  }
}
È stato utile?

Soluzione

Turns out the #(&*$ documentation was wrong and the reason why I was getting a 404 was because the url was not

http://host:port/confluence/rpc/json-rpc/confluenceservice-v2

but

http://host:port/rpc/json-rpc/confluenceservice-v2

So.. I was getting a 404 because... it was a 404. Code works great except that I had to add a content-type header for application/json.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top