Jaspersoft / jrs-rest-java-client

Java Rest Client for JasperReports Server
GNU Lesser General Public License v3.0
100 stars 101 forks source link

Return of Deleting Resources #93

Closed guilherme1603 closed 9 years ago

guilherme1603 commented 9 years ago

Hello, I have a issue with the return of the OperationResult. The return value of 'result' is null, but the operation is accomplished with success. When the folder or file not exist, the result also is null.

   OperationResult result = client
        .authenticate("jasperadmin", "jasperadmin")
        .resourcesService()
        .resource("/reports/testFolder")
        .delete();

Thanks.

Krasnyanskiy commented 9 years ago

@guilherme1603 You can download a new version (with fixed bug) from Artifactory. Or use Maven to grab dependencies automatically:

<dependency>
   <groupId>com.jaspersoft</groupId>
   <artifactId>jrs-rest-java-client</artifactId>
   <version>6.0.4</version>
</dependency>

And don't forget to add a link to our binary repository in your pom file:

<repositories>
     <repository>
        <id>jrs-ce-releases</id>
        <name>JasperReports Server CE releases repository</name>
        <url>http://jaspersoft.artifactoryonline.com/jaspersoft/jaspersoft-clients-releases/</url>
   </repository>
</repositories>
guilherme1603 commented 9 years ago

Hello, thanks for quick response, but I think that the bug not was fixed, because yet the response is null. My code:

        OperationResult result = session
                .resourcesService()
                .resource("/images/Teste2.png")
                .delete();

        System.out.println(result.getEntity());
        System.out.println(result.getResponse().getStatusInfo());

Response: null No Content

Thanks

Krasnyanskiy commented 9 years ago

Do you use the latest version of the client? Because I can see the response. Please find the test here. It works fine and retrieves not null response.

I suppose you didn't add a new client dependency 6.0.4 to your project. That why you get null instead Response instance.

In addition, If you'll try to get entity vie getEntity() method, you'll get null, since we wrap 204 No Content to null.

guilherme1603 commented 9 years ago

Yes, i am using the 6.0.4 with dependencies.

Now, I used your code, there is a response, but it always is the same. For example, if the folder exist and I delete it, the response is 204, and if the folder does not exist and I delete, the response also is 204.

So I can not know whether deleted or not deleted.

Krasnyanskiy commented 9 years ago

It is expected REST behaviour.

If there's nothing to delete, use 204 or 404 (DELETE operation is idempotent, delete an already deleted item is operation successful, so you can return 204, but it's true that idempotent doesn't implies necessarily the response)

If there is no resource with such URI, then it's ok. You were trying to delete a nonexistent resource.

guilherme1603 commented 9 years ago

Ok so, thank you very much.

Krasnyanskiy commented 9 years ago

However, we can add some method to check resource availability:

boolean isResourceAvailable = session
        .resourcesService()
        .resource("/reports/SomeReport")
        .isAvailable();

Do you think it will be useful for you?