2

I am trying to download contacts from Zimbra using the following code :

public static void getHTTPFile() {

    HttpClient client = new HttpClient();

    List<String> authPrefs = new ArrayList<String>(2);
    authPrefs.add(AuthPolicy.DIGEST);
    authPrefs.add(AuthPolicy.BASIC);
    client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs);

    client.getState().setCredentials(
    new AuthScope(HOST, new Integer(PORT).intValue(), AuthScope.ANY_REALM),
    new UsernamePasswordCredentials(NAME, PASSWORD)
    );

    GetMethod get = new GetMethod("http://"+HOST+":"+PORT+"/home/"+USER+"/contacts?fmt=csv");
    get.setDoAuthentication(true);

    try {
        int status = client.executeMethod(get);

        System.out.println(status + "\n" + get.getResponseBodyAsString());
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        get.releaseConnection();
    }
}

But I obtain an error 404 (Not Found) :

13 juin 2012 08:40:47 org.apache.commons.httpclient.auth.AuthChallengeProcessor selectAuthScheme
INFO: Basic authentication scheme selected
404
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
<title>Error 404 no such item</title>
</head>
<body><h2>HTTP ERROR 404</h2>
<p>Problem accessing /service/home/USER/contacts. Reason:
<pre>    no such item</pre></p><hr /><i><small>Powered by Jetty://</small></i><br/> 

Is my URL wrong? Regarding the documentation it seems not.

Is there a problem with the authentification? I don't obtain an error 401 (Unauthorized).

Any idea?

Thanks for your help.

EDIT:

Is there a limitation of Zimbra on the server side? Like for example we can only access to it through a web browser or a smartphone.

Michaël
  • 3,679
  • 7
  • 39
  • 64

2 Answers2

1

I do not have a clue about Zimbra, but it seems in your URL "http://"+HOST+":"+PORT+"/home/"+USER+"/contacts?fmt=csv" the USER var schould be replaced by a real username for example bob. But in the 404 response the url you are requesting is: /service/home/USER/contacts. Seems to me you want to request contacts from user USER and there is no user with this name. Is it right?

christian.vogel
  • 2,117
  • 18
  • 22
  • I voluntarily replaced my username by `USER`, like `PORT` is in fact 80. `USER` looks like : firstname.lastname@subdomain.domain. – Michaël Jun 15 '12 at 07:27
  • in the documentation for the command format (link: http://wiki.zimbra.com/wiki/ZCS_6.0:Zimbra_REST_API_Reference#Command_Format) shows the format. It can be in the form you describe or shortly `firstname.lastname` (but I think thats in general the username and if the username is firstname.lastname then ok). What happens when you replace `USER` with your `NAME` var? – christian.vogel Jun 15 '12 at 07:45
  • `NAME` and `USER` are the same. – Michaël Jun 15 '12 at 07:54
  • But as you can see in your response: `

    HTTP ERROR 404

    Problem accessing /service/home/USER/contacts.` USER is not replaced by any value you described (`firstname.lastname@subdomain.domain`)

    – christian.vogel Jun 15 '12 at 08:00
  • Let me add an example : `http://94.104.96.103:80/home/bob.john@work.com/contacts?fmt=csv` and the 404 response is `/service/home/bob.john@work.com/contacts` – Michaël Jun 15 '12 at 08:04
  • ok with that there is no mistake with the USER var :) In your example from the qeustion the response URL was different. So I thought there is a mistake with replacing the `USER` var. – christian.vogel Jun 15 '12 at 08:08
1

In a REST service, HTTP messages are part of the protocol and 404 could mean that the service is fine but your user is not found. Have you try with another user ? Or maybe you could have a default test user on the api.

jocelyn
  • 788
  • 6
  • 12
  • I have tried an other URL in my Web browser using a token and it works well. So I don't think the user is the problem. – Michaël Jun 15 '12 at 13:07
  • has your user got any contract? maybe not found means no contracs found. Have you check the accept mime type of the service? – jocelyn Jun 15 '12 at 13:29