1

I'm getting gitlab private token in request param. How to validate this token valid or not.

I have used gitlab4j-api maven dependency but getting error:

java.lang.ClassNotFoundException: javax.ws.rs.core.StreamingOutput

tried below code:

 @PostMapping("/validate-token")
    public void validateToken(@RequestParam String token, @RequestBody Object json) {
        System.out.printf("json " + json);
        System.out.println("Token " + token);


        //TODO need to fix error on below line.
        GitLabApi gitLabApi = new GitLabApi("https://gitlab.com", token);


        System.out.println("gitLabApi " + gitLabApi.toString());
        UserApi userApi = gitLabApi.getUserApi();
        System.out.println("UserApi " + userApi);
        if (userApi != null) {
            System.out.println("token is valid");
        } else {
            System.out.println("token is not valid");
        }

    }

Error -> Stack Trace

Exception Details:
  Location:
    org/gitlab4j/api/GitLabApiClient.createApiClient()Ljavax/ws/rs/client/Client; @18: invokevirtual
  Reason:
    Type 'org/glassfish/jersey/client/JerseyClientBuilder' (current frame, stack[0]) is not assignable to 'javax/ws/rs/client/ClientBuilder'
  Current Frame:
    bci: @18
    flags: { }
    locals: { 'org/gitlab4j/api/GitLabApiClient', 'org/glassfish/jersey/client/JerseyClientBuilder' }
    stack: { 'org/glassfish/jersey/client/JerseyClientBuilder', 'java/lang/Class' }
  Bytecode:
    0000000: bb00 7d59 b700 7e2a b400 1ab6 007f 4c2b
    0000010: 122d b600 8057 2b12 2fb6 0080 572a b400
    0000020: 8199 0013 2b2a b400 82b6 0083 2ab4 0084
    0000030: b600 8557 2a2b b600 86b5 0031 2ab4 0031
    0000040: b0                                     
  Stackmap Table:
    append_frame(@52,Object[#374])
] with root cause

java.lang.VerifyError: Bad type on operand stack
Exception Details:
  Location:
    org/gitlab4j/api/GitLabApiClient.createApiClient()Ljavax/ws/rs/client/Client; @18: invokevirtual
  Reason:
    Type 'org/glassfish/jersey/client/JerseyClientBuilder' (current frame, stack[0]) is not assignable to 'javax/ws/rs/client/ClientBuilder'
  Current Frame:
    bci: @18
    flags: { }
    locals: { 'org/gitlab4j/api/GitLabApiClient', 'org/glassfish/jersey/client/JerseyClientBuilder' }
    stack: { 'org/glassfish/jersey/client/JerseyClientBuilder', 'java/lang/Class' }
  Bytecode:
4
  • 1
    Do you have: <dependency> <groupId>javax.ws.rs</groupId> <artifactId>javax.ws.rs-api</artifactId> </dependency> in your pom.xml? ClassNotFoundException's are usually due to dependency problems Commented Apr 10, 2024 at 21:50
  • @EthanConrad: Still getting error. I have added stack trace in question. Commented Apr 12, 2024 at 14:15
  • Errors are gone after fixing the dependency error, but validation is not working. Commented Apr 12, 2024 at 16:40
  • If I passed invalid token, then userApi is not null, in all the cases always getting some some string value in userApi, Not understanding about GitlabApi working. Commented Apr 12, 2024 at 16:41

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.