Hello,

I'm trying to create a directory using Apaches HTTP components HTTPClient.

I've tried for a couple of days now to figure out how authentication is meant to be used but keep getting Access Denied Errors.

Here's my code:

package de.kmmd.jcr;

import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.mime.HttpMultipartMode;
import org.apache.http.entity.mime.MultipartEntity;
import org.apache.http.entity.mime.content.StringBody;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.DefaultHttpClient;

public class ClientTest {


    public static void main(String[] args) {

        DefaultHttpClient httpClient = new DefaultHttpClient();
        HttpPost httpPost = new HttpPost("http://localhost:8080/testDir";);
MultipartEntity mp = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);

        httpClient.getCredentialsProvider().setCredentials(
                AuthScope.ANY,
                new UsernamePasswordCredentials("admin", "admin"));

        try {
            mp.addPart("jcr:primaryType", new StringBody("nt:folder"));
            httpPost.setEntity(mp);
            httpClient.execute(httpPost, new BasicResponseHandler());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}

The apache sling's code base is so complex that I was unable so far to figure out how to use the test cases. In some of the test scenarios DefaultHttpClient with authentication is also used but I'm unable to follow the code so that I could use it as a guide.

Günther

Reply via email to