Jason Chan
Jason Chan

Reputation: 389

Spring Endpoints Returning Blank (not error 404)

Recently, I updated my spring to extend JPARepository and added an actuator and logging, and now my REST endpoints take 10 seconds to load, and return a blank page. Please note, the methods associated with the endpoints run successfully, so when I put in a system.out.print and other DB queries, they execute successfully, but none of the method return to the api endoint. Here are some examples of how my project looks for the entity, repository, service, controller, and application.properties:

Entity:

@Entity
@Table(name = "Example")
@Getter
@Setter
public class ExampleEntity {

//specific code removed for security

}

Repository:

@RepositoryRestResource(exported = false)
public interface ExapleRepository extends JPARepository<ExampleEntity, String> {

}

Service:

   @Service
public class ExampleService {
    @Autowired
    ExampleRepository exampleRepository;
//methods in here
}

Controller:

@RestController
public class ExampleController {

    @GetMapping("/test")
    public String test() {
        System.out.println("running");
return "Test Successful";
//when going to localhost:8081/test, this method will system.out.println running, but postman will run for like 10 seconds, and return nothing
    }

}

Application.properties:

spring.data.jdbc.repositories.enabled=false
#Basic Server IP Settings
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/{dbname}
spring.datasource.username={hidden}
spring.datasource.password={hidden}
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
#server.address=10.0.0.78
#insert ifconfig inet ip
server.port=8081

#Flyway Settings
spring.flyway.baseline-on-migrate=true

#Actuator Settings
management.endpoints.web.base-path=/{hidden}
management.endpoint.health.show-details=always
management.endpoints.web.exposure.include=*

Here are some images for reference...

enter image description here

enter image description here

As you can see, when I go to the endpoint, the method runs successfully, but the string is never successfully returned to the rest endpoint.

enter image description here

Upvotes: 0

Views: 701

Answers (2)

Jason Chan
Jason Chan

Reputation: 389

I got it figured out! thank you guys for your help so much! It turns out I had a logging service that was intercepting and causing my response to never finish returning. It looked like this

@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
throws ServletException, IOException {
//code to log
}

I will need to find another way to log inputs but I think we should be set otherwise! Thank you so much guys! Sending upvotes your way!

Upvotes: 0

SARATHI
SARATHI

Reputation: 124

I have cloned your controller and it's working fine in my application, it prints both the console and the output on the screen. Try removing the (exported=false) from your repository as @Lakshman Kumar suggests may be that works. I'm attaching the screen shots of your code and its output in my server for your reference,

Output in browser Code snippet and output in console API response in postman

Upvotes: 1

Related Questions