Content Server API v.1 - Jersey 1.17 - Creating Versions via POST Method

Options

Hello,

I try to write a REST Applikation in Java with Jersey 1.17 that use the ContentServer Api v.1. I can "Authenticate" via the POST Method, I can GET a Node or create a new Node via the "Node" Post Method, but if I want to create a new version in a node, I got a 400 Response Status Code and the following Error: {"error":"Could not process object, type \u0027Folder\u0027 has no role \u0027versions\u0027"}.

This is what i exactly want to do:

In my Content Server is a Node with the Name "Test" and the ID "26638" there are no Documents/Versions in the Folder. In the Next Step I want to create a new Version/Document via Jersey.

I use following URL: http://localhost/OTCS/cs.exe/api/v1/nodes/26638/versions

Then I run the Unit Test for Creating a "Node" which is successful.

Then I run the Unit Test for creating a Version see following Source Code:

//===========================================================================
// Version - Post
//===========================================================================
public static Versions postVersions(AuthenticationTicketDto authenticationTicket, String versionID){
    logger.info("**** postVersion ****");

    final FormDataMultiPart formDataMultiPart = new FormDataMultiPart();

    final String value ="Hello World";
    final FormDataContentDisposition dispo = FormDataContentDisposition
            .name("file")
            .fileName("test.txt")
            .size(value.getBytes().length)
            .build();

    final FormDataBodyPart bodyPart = new FormDataBodyPart(dispo, value, MediaType.MULTIPART_FORM_DATA_TYPE);
    formDataMultiPart.bodyPart(bodyPart);

    ClientResponse response = CSClient.getInstance()
                                                    .path("nodes/" + versionID + "/versions")
                                                    .accept(MediaType.APPLICATION_JSON_TYPE)
                                                    .entity(formDataMultiPart, MediaType.MULTIPART_FORM_DATA_TYPE)
                                                    .header(CSClientConstants.OTCS_TICKET, authenticationTicket.getTicket())
                                                    .post(ClientResponse.class, formDataMultiPart);

    logger.info("Response Statuscode of postVersion() Request.: " + response.getStatus());

    return response.getEntity(Versions.class);
}


@Test
public void A_CreateVersionInContentServer() {
    logger.info("*************** Test Creating/Posting NODE ***************");

    Versions versions = CSClientVersion.postVersions(authenticationTicket, "26638");

    assertNotNull(versions);
}

The JUnit TestCase gives me an exception: with 400 Statuscode.

I also turned on Jersey logging so I can see the HTTP Requests and the HTTP Response:

HTTP - Request - triggered from JUnit Testcase:
==============================================

Hello World
--Boundary_1_580554322_1402417619923--

Client out-bound request
POST http://localhost/OTCS/cs.exe/api/v1/nodes/26638/versions
Content-Type: multipart/form-data
OTCSTICKET: +6XXX4Pm/5xmY5euqlSZuVFpdV10pzO0jP6ciKvZK5SxcJwCgY3PK+bAmRppw6h1
--Boundary_1_580554322_1402417619923
Content-Type: multipart/form-data
Content-Disposition: form-data; filename="test.txt"; size=11; name="file"

HTTP - Response - triggered from JUnit Testcase:
==============================================

{"error":"Could not process object, type \u0027Folder\u0027 has no role \u0027versions\u0027"}
Client in-bound response
400
Date: Tue, 10 Jun 2014 16:26:59 GMT
Content-Length: 94
OTCSTicket: +6XXX4Pm/5xmY5euqlSZuVFpdV10pzO0jP6ciKvZK5SxcJwCgY3PK+bAmRppw6h1
Expires: 0
Content-Type: application/json; charset=UTF-8
X-Powered-By: ASP.NET
Server: Microsoft-IIS/7.5
Pragma: no-cache
Cache-Control: no-cache, no-store, must-revalidate, max-age=0

I also implemented a Jersey WebService with Multipart functionality by myself, and run a JUnit Test to test my own client side code, but everything works fine.

I also tried to create a new Version via Postman but I got the same Statuscode and the same Error Message.

What's wrong ?

Comments

  • The error is telling you that you cannot create a new version of a folder. (One could argue how legible that error message is...) Folder is not a versionable object.

    Creating a new version means adding a new version to an already existing versionable object. Try a document, for example.

  • Thank you for your quick response.

    I am a little bit confused. I have looked many times on the API and thought this would create a new Document/Version in a particular Folder.

    enter image description here

    I mean if I want to add a new Version to an already existing document I would use the HTTP PUT Method.

  • As a general rule, POST creates and PUT modifies. The resource you refer to is for versions; not for nodes. It creates a new version in a versionable node, which is document, for example. Nodes, which includes documents, are created by POST /nodes.