Hi Tony,
See inline comment....
On 20.08.2010 22:23, Tony Giaccone wrote:
> Summary:
>
> Using java to post a multipart form with values of "jcr:primaryType" set to
> "nt:unstructured" fails, curl to same address succeeds.
>
>
>
> Details:
>
>
> I'm using httpcomponent/httpclient to send submit a form to sling.
>
> To do this I'm creating a multi-part form, with the fields being sent using
> code like this:
>
>
> public String insertWithAuth(String userId, String password,String url,
> List<BasicNameValuePair> slingData) {
> String retValue = null;
> HttpPost post = new HttpPost(url);
> BasicNameValuePair[] pairs = new BasicNameValuePair[slingData.size()];
> pairs = slingData.toArray(pairs);
> try {
> MultipartEntity anEntity = new MultipartEntity(
> HttpMultipartMode.BROWSER_COMPATIBLE);
> for(BasicNameValuePair entry : pairs)
> {
> anEntity.addPart(entry.getName(), new
> StringBody(entry.getName(),Charset.forName("UTF-8")));
Are you sure this line is correct ?? I would assume the StringBody is
created from the entry's value not its name.
Regards
Felix
> }
> post.setEntity(anEntity);
> HttpResponse theResponse = client.execute(targetHost, post,
> localContext);
>
>
> I've left out the declarations for targetHost and localContent I don't think
> they are significant.
>
> The List of BasicNameValuePairs is created based on the contents of the
> entity that's being posted.
>
> If I don't do anything but set my own values, based on the object I'm trying
> to insert everything works fine.
>
> The document ends up with this property:
>
> "jcr:primaryType":"sling:Folder"
>
>
> However, when I try to set the jcr:primary value with the following code:
>
> key = "jcr:primaryType";
> value = "nt:unstructured";
> entry = new BasicNameValuePair(key,value);
> retValue.add(entry);
>
> return (retValue);
>
> I always get this error message:
>
>
>
> Status
> 500
> Message
> javax.jcr.nodetype.NoSuchNodeTypeException:
> {http://www.jcp.org/jcr/1.0}primaryType
>
>
> Using Curl to set that value works just fine:
>
> curl -F"sling:resourceType=foo/bar" -F"jcr:primaryType=nt:unstructured"
> -F"userId=jsmith"
> http://admin:ad...@localhost:8080/sling/content/Documents/users/jsmith
>
>
> {"sling:resourceType":"foo/bar","userId":"jsmith","jcr:primaryType":"nt:unstructured"}
>
>
>
>