Hi all,

I have some trouble with my Java post request. Sling issues a 500
error when I try to post my JPG to /images.

I can find following line in the log file in Sling:
11.07.2012 10:09:54.604 *ERROR* [127.0.0.1 [1341965394583] POST
/images/tubu2.jpg HTTP/1.1]
org.apache.sling.servlets.post.impl.operations.ModifyOperation Access
Denied Access denied.

Below is my Java code. Any help is much appreciated.


public static void main(String[] args) throws HttpException, IOException {
        
           Credentials credentials = new UsernamePasswordCredentials("admin", 
"admin");
           HttpClient httpClient = new HttpClient();
           httpClient.getState().setCredentials(AuthScope.ANY, credentials);

           String url = "http://localhost:8080/images/tubu2.jpg";;
           String fieldName = "./";
           File localFile = new File("C:/temp/test.jpg");
           String typeHint = "nt:file";
        
           final Part[] parts = new Part[typeHint == null ? 1 : 2];
       parts[0] = new FilePart(fieldName, localFile);
       if (typeHint != null) {
           parts[1] = new StringPart(fieldName + "@TypeHint", typeHint);
       }
        
       final PostMethod post = new PostMethod(url);
       post.setFollowRedirects(false);
       post.setRequestEntity(new MultipartRequestEntity(parts,
post.getParams()));
       final int status = httpClient.executeMethod(post);
        
       System.out.println(Integer.toString(status));
        
    }

}



Thanks,

Andre

Reply via email to