Skip to content
Advertisement

java.lang.ClassNotFoundException: org.glassfish.jersey.internal.RuntimeDelegateImpl , when throwing BadRequestException

I have a handler class in my springbootapp that performs some validation on incoming REST requests and throws BadRequestException back to the controller class.

But instead of controller catching the BadRequestException, it catches Exception and throws

java.lang.ClassNotFoundException: org.glassfish.jersey.internal.RuntimeDelegateImpl

I spend some time looking around for solution but dont seem to find any.

Here is my validation code in handler

    private void validateSignUpRequest(String phone) {
    if(StringUtils.isEmpty(phone))
        throw new BadRequestException("Phone Number can't be empty");
}

Here is the controller

@PostMapping(path = "/users/sign-up")
public ResponseEntity<UserData> signUpUser(@RequestBody Users user) {
    UserData userData = null;
    HttpStatus httpStatus = null;
    boolean flag = false;
    try {
        userData = userHandler.fetchByPhone(user.getPhoneNumber());
        if (userData == null) {
            flag = userHandler.saveUser(user);
            httpStatus = HttpStatus.CREATED;
        } else {
            userData = UserData.failureResponse("User Already Exist");
            httpStatus = HttpStatus.CONFLICT;
        }
    }catch(BadRequestException e) {
        userData = UserData.failureResponse(e.getMessage());
        httpStatus = HttpStatus.BAD_REQUEST;
    }
    catch (Exception e) {
        userData = UserData.failureResponse(e.getMessage());
        httpStatus = HttpStatus.INTERNAL_SERVER_ERROR;
    }
    return new ResponseEntity<>(userData,httpStatus);
}

pom.xml

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.1.4.RELEASE</version>
</parent>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-data-rest -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-rest</artifactId>
        <version>2.1.6.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <version>2.1.6.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
        <version>2.1.6.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <version>2.1.6.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.apache.tomcat.embed</groupId>
        <artifactId>tomcat-embed-jasper</artifactId>
        <version>9.0.21</version>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.datatype</groupId>
        <artifactId>jackson-datatype-jsr310</artifactId>
        <version>2.9.9</version>
    </dependency>
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
    </dependency>
    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupId>org.codehaus.jackson</groupId>
        <artifactId>jackson-mapper-asl</artifactId>
        <version>1.9.13</version>
    </dependency>
    <dependency>
        <groupId>com.googlecode.json-simple</groupId>
        <artifactId>json-simple</artifactId>
        <version>1.1.1</version>
    </dependency>
    <dependency>
        <groupId>javax.ws.rs</groupId>
        <artifactId>javax.ws.rs-api</artifactId>
        <version>2.1.1</version>
    </dependency>
</dependencies>


<properties>
    <java.version>11</java.version>
</properties>

Advertisement

Answer

This class https://github.com/jersey/jersey/blob/master/core-common/src/main/java/org/glassfish/jersey/internal/RuntimeDelegateImpl.java is under jersey-common.

You are missing jersey-common https://mvnrepository.com/artifact/org.glassfish.jersey.core/jersey-common

    <dependency>
       <groupId>org.glassfish.jersey.core</groupId>
       <artifactId>jersey-common</artifactId>
       <version>.....</version>
    </dependency>
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement