-
Notifications
You must be signed in to change notification settings - Fork 12
Intermediate commit: #65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Intermediate commit: #65
Conversation
| @Controller | ||
| public class LogsController { | ||
| private final RetrievalService retrievalService; | ||
| public LogsController(RetrievalService retrievalService) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is supposed to be a REST controller, you should not be returning a view name like the with the controllers serving thymeleaf html files. The REST controllers will be returning JSON instead of view names (string)
REST Controller vs. Web Controller
It looks like you're using a REST controller, but you're returning a view name (like "home" or "dashboard"), which is meant for HTML templates such as those rendered by Thymeleaf.
🚫 In REST controllers:
- You should not return a view name (e.g.,
"home"). - Instead, you should return data (typically in JSON format).
✅ What you should do:
- Use
@RestControllerif your endpoint is meant to return data. - Return an object or a collection, not a view name.
✅ Example:
@RestController
public class UserController {
@GetMapping("/api/users")
public List<User> getUsers() {
return userService.getAllUsers(); // Spring automatically converts this to JSON
}
}🧠 Quick Tip:
- Use
@Controllerwhen returning HTML views (with Thymeleaf, JSP, etc.). - Use
@RestControllerwhen returning JSON (typical for APIs).
Here are some resources you can use to better learn about REST controllers
📘 Official & Introductory Resources
-
Spring Boot Reference Docs (REST Controllers)
- 📖 https://docs.spring.io/spring-boot/docs/current/reference/html/web.html#web.spring-web
- Focus:
@RestController,@ResponseBody, JSON responses
-
Spring.io: Building a RESTful Web Service
- 📘 https://spring.io/guides/gs/rest-service/
- Hands-on guide: Build a REST API step by step
-
Spring.io: Serving Web Content with Spring MVC
- 📘 https://spring.io/guides/gs/serving-web-content/
- Covers traditional MVC with
@Controllerand Thymeleaf
📺 Video Tutorials
-
Spring Boot REST API Tutorial (Amigoscode)
- 🎥 https://www.youtube.com/watch?v=9SGDpanrc8U
- Great for visual learners and beginners
-
Java Brains – Spring Boot Quick Start
- 🎥 https://www.youtube.com/playlist?list=PLqq-6Pq4lTTZSKAFG6aCDVDP86Qx4lNas
- Breaks down REST concepts with clear examples
📚 Articles & Blog Posts
-
Baeldung: Difference Between @controller and @RestController
- 📄 https://www.baeldung.com/spring-controller-vs-restcontroller
- Excellent explanation with code examples
-
Baeldung: Introduction to Spring REST Controllers
- 📄 https://www.baeldung.com/building-a-restful-web-service-with-spring-and-java-based-configuration
- Covers REST design and configuration in-depth
Tools You Can Test With
- Postman – Use this to send HTTP requests to your REST API and inspect JSON responses.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@samuelowino I am trying to access the end point via postman or swagger. but I end up getting 403 forbidden, any pointers to how to get this working will be helpful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@samuelowino I am trying to access the end point via postman or swagger. but I end up getting 403 forbidden, any pointers to how to get this working will be helpful.
You need to include credentials in your request. Postman allows you to include a user account for your tests. Refer to this guide: https://learning.postman.com/docs/sending-requests/authorization/specifying-authorization-details/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@samuelowino
I did add the basic auth on the Authorization tab and respond back with 403 forbidden. Same with the dummy rest controller
I commented the MockTest as they were failing, will fix it.

Could this be due to the form-login only allowed in the securityconfig?
| String uuid, | ||
| @NotNull(message = "timestamp cannot be null") | ||
| LocalDateTime timestamp, | ||
| @NotNull(message = "severity cannot be null") | ||
| @NotBlank(message = "severity cannot be blank") | ||
| String severity, | ||
| @NotNull(message = "applicationId cannot be null") | ||
| @NotBlank(message = "applicationId cannot be blank") | ||
| String applicationId, | ||
| String logSource, | ||
| @NotBlank(message = "message cannot be null") | ||
| @NotNull(message = "message cannot be blank") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This are awesome 🔥
| } | ||
|
|
||
|
|
||
| @PostMapping("/logs/ingest") | ||
| @PreAuthorize("hasAnyRole('admin','datasource')") | ||
| public String createLogs(@Valid @RequestBody AppLog appLog){ | ||
| var optionalLog = retrievalService.findLogsById(appLog.uuid()); | ||
| if (optionalLog.isPresent()) { | ||
| throw new RuntimeException("Log with id " + appLog.uuid() + " already exists"); | ||
| } else { | ||
| //ingestionService.saveNewLogs(appLog); | ||
| return "logs-created"; | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After implementing these controller(s), consider adding some mockmvc tests for them
📘 Official Documentation
-
Spring Docs – Testing the Web Layer
- 📖 https://docs.spring.io/spring-boot/docs/current/reference/html/features.html#features.testing.spring-boot-applications.testing-with-mockmvc
- Covers how to test controllers using
@WebMvcTestandMockMvc.
-
Spring Framework Testing Docs
- 📖 https://docs.spring.io/spring-framework/docs/current/reference/html/testing.html#spring-mvc-test-framework
- Deeper dive into how
MockMvcworks under the hood.
🎓 Beginner-Friendly Guides and Tutorials
-
Baeldung: Introduction to MockMvc
- 📄 https://www.baeldung.com/spring-mvc-test-examples
- The go-to guide: explains setup, common use cases, and assertions.
-
Spring Boot Guide: Unit Testing with MockMvc
- 📄 https://www.javaguides.net/2019/06/spring-boot-2-unit-testing-crud-rest-api-using-junit-5-and-mockito.html
- Step-by-step testing of CRUD operations with
MockMvc.
-
Amigoscode - Spring Boot REST API Testing (YouTube)
- 🎥 https://www.youtube.com/watch?v=_yN4b3Jc6C4
- Very clear and beginner-friendly walk-through of
MockMvc.
📄 Example Code Snippet (Basic Test)
@WebMvcTest(UserController.class)
class UserControllerTest {
@Autowired
private MockMvc mockMvc;
@MockBean
private UserService userService;
@Test
void shouldReturnListOfUsers() throws Exception {
List<User> users = List.of(new User(1, "Alice"));
when(userService.getAllUsers()).thenReturn(users);
mockMvc.perform(get("/api/users"))
.andExpect(status().isOk())
.andExpect(jsonPath("$[0].name").value("Alice"));
}
}🧰 Tools & Concepts to Learn Alongside MockMvc
@WebMvcTest– for testing just the controller layer@MockBean– for mocking dependencies like servicesjsonPath()– for validating JSON contentMockHttpServletRequestBuilder– for customizing request headers, body, etc.
Have added the LogsIngestionController to facilitate the log ingestion.
Have added the LogsIngestionController to facilitate the log ingestion.
Have added the LogsIngestionController to facilitate the log ingestion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code looks good, just need proper tests
| //@WebMvcTest(LogsIngestionController.class) | ||
| class LogsIngestionControllerTest { | ||
|
|
||
| @Autowired | ||
| private MockMvc mockMvc; | ||
|
|
||
|
|
||
| @Mock | ||
| IIngestionService ingestionService; | ||
|
|
||
| private AppLog appLog; | ||
|
|
||
| //@BeforeEach | ||
| void setUp() { | ||
| appLog = new AppLog( | ||
| "test-uuid", | ||
| DateTimeUtils.convertZonedUTCTimeStringToLocalDateTime("2025-08-11 11:09:22 UTC") , | ||
| "ERROR", | ||
| "app-123", | ||
| "", | ||
| "Test message" | ||
| // add other fields as needed | ||
| ); | ||
| } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@CoderRamya Can you enable the tests?
Have added the LogsIngestionController to facilitate the log ingestion.
|
@samuelowino : Please have a look Have tested with swagger and postman. @samuelowino |
|
still not resolved? @samuelowino |
I'll look at it in a bit |
let me know ! ASAP |
@kiranraoboinapally this is not yet resolved, if you can work on it, please go ahead. |
Have added the LogsIngestionController to facilitate the log ingestion with Basic Authentication
|
@samuelowino |
Hey @CoderRamya , I have been held up a bit lately, be rest assured I will take time and review it sometime this week or next. Thanks for you patience. In the meantime feel free to work on another issue as I review this |
No description provided.