Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@bbpennel
Last active November 30, 2018 20:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bbpennel/4e4ca81d5a6cc406404bd79d2dca5691 to your computer and use it in GitHub Desktop.
Save bbpennel/4e4ca81d5a6cc406404bd79d2dca5691 to your computer and use it in GitHub Desktop.
Testing changing interaction model of binary

Create binary without type

curl -v -XPOST -ufedoraAdmin:fedoraAdmin -H"Content-Disposition: attachment; filename=\"postCreate.txt\"" -H"Slug: binary_change_test1" --data-binary "TestString." http://localhost:8080/rest/


curl -v -ufedoraAdmin:fedoraAdmin http://localhost:8080/rest/binary_change_test1

< HTTP/1.1 200 OK
< Set-Cookie: rememberMe=deleteMe; Path=/; Max-Age=0; Expires=Thu, 29-Nov-2018 19:40:56 GMT
< Content-Type: application/x-www-form-urlencoded
< Content-Disposition: attachment; filename="postCreate.txt"; creation-date="Fri, 30 Nov 2018 19:40:34 GMT"; modification-date="Fri, 30 Nov 2018 19:40:34 GMT"; size=11
< Link: <http://www.w3.org/ns/ldp#Resource>;rel="type"
< Link: <http://www.w3.org/ns/ldp#NonRDFSource>;rel="type"
< Link: <http://localhost:8080/rest/binary_change_test1/fcr:metadata>; rel="describedby"
< Accept-External-Content-Handling: copy,redirect,proxy
< Allow: DELETE,HEAD,GET,PUT,OPTIONS
< Link: <http://localhost:8080/rest/binary_change_test1/fcr:acl>; rel="acl"
< Cache-Control: no-transform, must-revalidate, max-age=0
< Content-Length: 11

Try to change type to a BasicContainer while also providing binary content

curl -v -XPUT -ufedoraAdmin:fedoraAdmin -H"Content-Disposition: attachment; filename=\"putCreate.txt\"" -H'Link: <http://www.w3.org/ns/ldp#BasicContainer>;rel="type"' --data-binary "TestString2." http://localhost:8080/rest/binary_change_test1

< HTTP/1.1 204 No Content

Check what the result was, which appears to be no change to the type

curl -v -ufedoraAdmin:fedoraAdmin http://localhost:8080/rest/binary_change_test1

< HTTP/1.1 200 OK
< Content-Type: application/x-www-form-urlencoded
< Content-Disposition: attachment; filename="putCreate.txt"; creation-date="Fri, 30 Nov 2018 19:40:34 GMT"; modification-date="Fri, 30 Nov 2018 19:46:08 GMT"; size=12
< Link: <http://www.w3.org/ns/ldp#Resource>;rel="type"
< Link: <http://www.w3.org/ns/ldp#NonRDFSource>;rel="type"
< Link: <http://localhost:8080/rest/binary_change_test1/fcr:metadata>; rel="describedby"
# TestString2.

Try to change type to RDFSource while also providing binary content

curl -v -XPUT -ufedoraAdmin:fedoraAdmin -H"Content-Disposition: attachment; filename=\"putCreate2.txt\"" -H'Link: <http://www.w3.org/ns/ldp#RDFSource>;rel="type"' --data-binary "TestString3." http://localhost:8080/rest/binary_change_test1

< HTTP/1.1 400 Bad Request
Invalid interaction model: http://www.w3.org/ns/ldp#RDFSource

Change type to RDFSource without binary

curl -v -XPUT -ufedoraAdmin:fedoraAdmin -H'Link: <http://www.w3.org/ns/ldp#RDFSource>;rel="type"' http://localhost:8080/rest/binary_change_test1

< HTTP/1.1 400 Bad Request
# Invalid interaction model: http://www.w3.org/ns/ldp#RDFSource

Try to change type to BasicContainer without any binary related info

curl -v -XPUT -ufedoraAdmin:fedoraAdmin -H'Link: <http://www.w3.org/ns/ldp#BasicContainer>;rel="type"' http://localhost:8080/rest/binary_change_test1

< HTTP/1.1 204 No Content


curl -v -ufedoraAdmin:fedoraAdmin http://localhost:8080/rest/binary_change_test1

< HTTP/1.1 200 OK
< Link: <http://www.w3.org/ns/ldp#Resource>;rel="type"
< Link: <http://www.w3.org/ns/ldp#NonRDFSource>;rel="type"
< Link: <http://localhost:8080/rest/binary_change_test1/fcr:metadata>; rel="describedby"
< Content-Type: application/octet-stream
< Content-Length: 0

Also worth noting is that the Content-Type is no longer

Try to change to a DirectContainer

curl -v -XPUT -ufedoraAdmin:fedoraAdmin -H'Link: <http://www.w3.org/ns/ldp#DirectContainer>;rel="type"' http://localhost:8080/rest/binary_change_test1

< HTTP/1.1 409 Conflict
# Changing the interaction model ldp:BasicContainer to ldp:DirectContainer is not allowed!

What?? Its supposed to be a NonRdfSource, not a basic container

I also got a 204 response and the same behavior for NonRDFSource to IndirectContainer and DirectContainer. It did not matter if I explicitly provided the NonRDFSource type when creating the binary.

And just to be safe... lets see what happens if creating a child in our NonRDFSource that thinks its a BasicContainer

curl -v -XPUT -ufedoraAdmin:fedoraAdmin http://localhost:8080/rest/binary_change_test1/child

< HTTP/1.1 409 Conflict
Unable to add child /child to resource /binary_change_test1

phew...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment