Jaspersoft / jrs-rest-java-client

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

delete of folder gives me 403.. #48

Closed mortias closed 10 years ago

mortias commented 10 years ago

Hello,

Any idea how to enable the DELETE rest command on the jasperserver? when i try to delete a created folder via the api i get this response.. or i'm missing something? The user used is the admin so..

InboundJaxrsResponse{ ClientResponse{method=DELETE, uri=http://path_to_server/jasperserver/rest_v2/resources, status=403, reason=Forbidden}}

mortias commented 10 years ago

in the singleResourceAdapter the delete works public OperationResult delete() { JerseyRequest request = buildRequest(sessionStorage, Object.class, new String[]{"/resources", resourceUri}); return request.delete(); }

however if i use the batchadapter

public OperationResult delete(){ 
    return getBuilder(Object.class).delete();
}

i get the permission denied error..

mortias commented 10 years ago

Is this correct to delete multiple items? //multiple OperationResult result = client .authenticate("jasperadmin", "jasperadmin") .resourcesService() .resources() .parameter(ResourceSearchParameter.RESOURCE_URI, "/some/resource/uri/1") .parameter(ResourceSearchParameter.RESOURCE_URI, "/some/resource/uri/2") .delete();

if i dig into the code it adds parameters instead of paths, so the targetUri becomes ..... [path to server] jasperserver/rest_v2/resources?resourceUri=integration/reports/testreport instead of [path to server] jasperserver/rest_v2/resources/integration/reports/testreport

as far as i'm aware the get function on resources?resourceUri doesn't exist..

Actine commented 10 years ago

@mortias Yes, deleting multiple resources is done by supplying URI's via resourceUri parameter. Regarding the issue with the client — can't help much, let's wait for the dev

mortias commented 10 years ago

ok i see http://community.jaspersoft.com/documentation/jasperreports-server-web-services-guide/v56/deleting-resources.. maybe that isn't the issue then.. so why can i delete a resource with the resource("a").delete method but not in batch ..

Actine commented 10 years ago

@mortias One guess would be trying to delete resources (or a folder of resources) that are interdependent. e.g. trying to delete a folder with domain and report based on it could fail if JRS tries to delete the domain first.

mortias commented 10 years ago

i'm just trying to delete a folder with nothing in it which i"ve just created..

mortias commented 10 years ago

So this in batch doesn't work: OperationResult result = session.resourcesService().resources().parameter(ResourceSearchParameter.FOLDER_URI, folder.getUri()).delete();

but this is .. for the same folder OperationResult result = session.resourcesService().resource(folder.getUri()).delete();

mortias commented 10 years ago

same thing with a report, in batch i can't, so i get the forbidden error, with the normal singleresourceadapter it works..

Krasnyanskiy commented 10 years ago

Ok, I see the problem.

mortias commented 10 years ago

@Krasnyanskiy so you can reproduce the error? do you see a solution :) i have the impression he takes it as a server path rather then a request string.. maybe it needs urlencoding.. ? don't know..

Krasnyanskiy commented 10 years ago

@mortias Yes, I can reproduce it.

mortias commented 10 years ago

i don't want to be a pain, but i think you miss some tests to assert all functionalities..

Krasnyanskiy commented 10 years ago

No, I checked it one more time, and it's OK with web service.

mortias commented 10 years ago

ah, ok, let me first say thank you for sorting things out with me.   so then there is something fishy with the client ?    

----- Oorspronkelijk bericht -----

Van: "Alexander Krasnyanskiy" notifications@github.com Aan: "Jaspersoft/jrs-rest-java-client" jrs-rest-java-client@noreply.github.com Cc: "mortias" mortier@telenet.be Verzonden: Donderdag 18 september 2014 22:00:07 Onderwerp: Re: [jrs-rest-java-client] delete of folder gives me 403.. (#48)

No, I checked one more time. And it's OK with web service.

— Reply to this email directly or view it on GitHub .

Krasnyanskiy commented 10 years ago

Maybe, I need to check it more deeply.

mortias commented 10 years ago

are you sure it is a supported (new/old) feature of the jrs 5.0 ? because if you google on "rest_v2/resources ?resourceUri" i only find one or two references..

----- Oorspronkelijk bericht -----

Van: "Alexander Krasnyanskiy" notifications@github.com Aan: "Jaspersoft/jrs-rest-java-client" jrs-rest-java-client@noreply.github.com Cc: "mortias" mortier@telenet.be Verzonden: Donderdag 18 september 2014 22:07:59 Onderwerp: Re: [jrs-rest-java-client] delete of folder gives me 403.. (#48)

Maybe, I need to check it more deeply.

— Reply to this email directly or view it on GitHub .

Actine commented 10 years ago

@mortias I think you were right when you said "maybe it needs urlencoding". In debugging mode I see that the request goes to URL http://localhost:8080/jasperserver-pro/rest_v2/resources?resourceURI=/some/resource/uri/1&resourceURI=/some/resource/uri/2, whereas slashes must be urlencoded for the endpoint to consume it correctly. As a temp workaround try urlencoding them before feeding to the client (IIRC %2F is slash)

With regard to JRS version — in fact RESTv2 Repository service was introduced in 5.5, if I'm not mistaken; it's absent in 5.0 totally, so neither way to delete a resource would work for you in that case.

Krasnyanskiy commented 10 years ago

I checked it on 5.6.0.

mortias commented 10 years ago

well i'm at home so i wasn't sure of the versions but if you checked it that is something we can exclude :) i have the impression that it tells me i don't have the permission on that path which is correct because this path doesn't exist, however it doesn't interprete the string as a urlencoded one, i need to test this tomorrow if you are not first..

mortias commented 10 years ago

or maybe you see something in the logs of the server?

Krasnyanskiy commented 10 years ago

I tried to delete folders via pure Jersey

Client client = ClientBuilder
        .newClient()
        .register(HttpAuthenticationFeature.basic("superuser", "superuser"))
        .register(JacksonFeature.class);

WebTarget target = client.target("http://54.196.19.224:8080/jasperserver-pro/");

Response resp = target
        .path("/rest_v2/resources/?resourceURI=/public/Samples/NewFolder1&resourceURI=/public/Samples/NewFolder2")
        .request()
        .delete();

But result is the same. Even if I change slash with %2F in URIs.

Actine commented 10 years ago

OK, I got it. The parameter's name is wrong. It must be resourceUri instead of resourceURI. (source: internal wiki page. but must be in the public docs too)

mortias commented 10 years ago

isnt it (without the "/" slash after /resources ("/rest_v2/resources?resourceURI=/public/Samples/NewFolder1&resourceURI=/public/Samples/NewFolder2

Krasnyanskiy commented 10 years ago

Oh, but it works with

Response resp = target
        .path("/rest_v2/resources")
        .queryParam("resourceUri", "/public/Samples/NewFolder1")
        .queryParam("resourceUri", "/public/Samples/NewFolder2")
        .request()
        .delete();
Actine commented 10 years ago

@Krasnyanskiy well I'm testing with Postman, and it worked for me even without urlencoding: http://localhost:8080/jasperserver-pro/rest_v2/resources?resourceUri=/qa_automation/fld1&resourceUri=/qa_automation/fld2 worked, whereas resourceURI failed with access denied

mortias commented 10 years ago

ha! so then the resourcesearchparameter enum RESOURCE_URI("resourceURI") should be resourceUri which explains why FOLDER_URI("folderUri") works in the searches ..

OperationResult result = client .authenticate("jasperadmin", "jasperadmin") .resourcesService() .resources() .parameter(ResourceSearchParameter.RESOURCE_URI, "/some/resource/uri/1") .parameter(ResourceSearchParameter.RESOURCE_URI, "/some/resource/uri/2") .delete();

mortias commented 10 years ago

i'll test it tomorrow but i'm quite sure it's this! nice teamwork guys ! (if it works :) )

Krasnyanskiy commented 10 years ago

Fixed (see develop branch).

mortias commented 10 years ago

confirmed ! i've also send them a request to change their documentation https://community.jaspersoft.com/documentation/jasperreports-server-web-services-guide/v56/deleting-resources