• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

whitelabel 404 error in microservice

 
Ranch Hand
Posts: 1013
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am getting below error while aces below micro service from the browser or postman as attached. I see H2 database getting inserterted with data successfully.  Please advise

I am able to start the spring boot servers and also be able to see the data inserted into the H2 Database.

ACCOUNTS AND CUSTOMER H2

http://localhost:8081/h2-console/login.do?jsessionid=4cfecd0415af0b7a7fb18fb59dda08e2 works fine
CARDS H2

http://localhost:9010/h2-console/ works fine
Loans h2

http://localhost:8099/h2-console  works fine
When I access URLs in the browser I get errors like 404 whitelabel errors. Even postman also giving similar errors not sure of any issues with paths, URLs, mappings.

http://localhost:8081/api/v1/accounts/1
Above gives white label 404 as attached


http://localhost:9010/api/v1/cards/1
Above gives white label 404 as attached

http://localhost:8099/api/v1/loans/1  
Above gives white label 404 as attached


Code is as below


h2-console-coming.JPG
[Thumbnail for h2-console-coming.JPG]
postman_404_bank_app_hw.JPG
[Thumbnail for postman_404_bank_app_hw.JPG]
whitelable-404.JPG
[Thumbnail for whitelable-404.JPG]
Staff note (Ron McLeod) :

srk: I removed a large amount of blank lines from your code which was making it unreadable.

 
Bartender
Posts: 15741
368
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, which endpoint is http://localhost:8081/api/v1/accounts/1 supposed to reach? The mappings in your AccountController class don't match.

Furthermore, even if they did match, the accountService.fetchAccountDetails(customerId) call would fail because accountService is not auto-wired.
 
sai rama krishna
Ranch Hand
Posts: 1013
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
With below url got 500 error. Please advise

http://localhost:8081/api/v1/accounts/fetch/1
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.

Mon Apr 22 22:07:19 EDT 2024
There was an unexpected error (type=Internal Server Error, status=500).
 
Stephan van Hulst
Bartender
Posts: 15741
368
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There's nothing we can do with that error message.

You need to either look in the server logs, use a debugger to step through your code, or provide a custom error page.
 
sai rama krishna
Ranch Hand
Posts: 1013
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How to effectively debug these type of intricate errors involving multiple layers like controller, service, repository, configurations and database etc. ?
Please advise
 
Bartender
Posts: 7645
178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
They all run in the same JVM, right? So a debugger would work well, as Stephan said.
 
sai rama krishna
Ranch Hand
Posts: 1013
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yea, Currently running in my local windows laptop. How to debug paths like below which are given in annotations
api/v1/accounts/fetch/1

I gave wrong path earlier
api/v1/accounts/1

I keep get these type of errors with paths

Multiple hops like browser to app controller and then to database harder to debug I feel especially in enterprise applications
 
Tim Moores
Bartender
Posts: 7645
178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A debugger can set breakpoints in the code, not at particular URLs. So it doesn't matter how code is accessed, only that it does get executed.
 
sai rama krishna
Ranch Hand
Posts: 1013
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Lot of times I am getting access errors. I think i need to put more attention on paths

In log i see below type of error for that 500 error



I do not see this.accountService in below class though



I just uncommented autowired as below


Now I see error like below data error


I do see that data
data-mangodb.JPG
[Thumbnail for data-mangodb.JPG]
 
Stephan van Hulst
Bartender
Posts: 15741
368
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How is Spring JPA to know that a field named customerId is mapped to a column named customer_id?

Use the @Column annotation to map the field to the correct column.
 
sai rama krishna
Ranch Hand
Posts: 1013
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ah got it. Thank you. Let me try once i am able to get to that personal laptop today.
 
sai rama krishna
Ranch Hand
Posts: 1013
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If distributed in multiple JVMs how to debug these type of issues. What are best practices in naming conventions, debugging, avoiding, finding root causes of these type of issues which i have pattern of making similar ones again and again
 
Stephan van Hulst
Bartender
Posts: 15741
368
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When debugging a client and server application simultaneously, I typically just open two separate instances of my IDE and attach each one to a different JVM process.

There are two important pieces of advice I can give you: First, learn how to read log files and stack traces. Second, learn how the debugger works by stepping through your application and experimenting with the call stack and watched variables.

For naming conventions, have your code reviewed by experienced programmers, such as the fine members of the CodeRanch.

Other than that, a lot of expertise really comes from making the same mistakes over and over until you learn not to make them anymore.
 
sai rama krishna
Ranch Hand
Posts: 1013
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you.

When I am trying to start intellij standard free edition server on my laptop now I am getting below error. Trying to resolve this.
Error: Could not find or load main class com.je.JeHwAccountApplication
Caused by: java.lang.ClassNotFoundException: com.je.JeHwAccountApplication

After doing maven install now this server issue resolved and started


I added @column customer_id

still getting below error


Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.

Wed Apr 24 21:35:39 EDT 2024
There was an unexpected error (type=Internal Server Error, status=500).





2024-04-24T21:35:39.518-04:00  INFO 19076 --- [JE-HW-Account] [nio-8081-exec-1] com.je.controllers.AccountController     : acct controler ->fetchAccountDetails1
2024-04-24T21:35:39.737-04:00 ERROR 19076 --- [JE-HW-Account] [nio-8081-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed: java.lang.RuntimeException: account not there in db] with root cause

java.lang.RuntimeException: account not there in db
at com.je.service.AccountService.lambda$0(AccountService.java:19) ~[classes/:na]
at java.base/java.util.Optional.orElseThrow(Optional.java:403) ~[na:na]
at com.je.service.AccountService.fetchAccountDetails(AccountService.java:19) ~[classes/:na]
at com.je.controllers.AccountController.fetchAccountDetails(AccountController.java:31) ~[classes/:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na]
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:255) ~[spring-web-6.1.5.jar:6.1.5]
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:188) ~[spring-web-6.1.5.jar:6.1.5]
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:118) ~[spring-webmvc-6.1.5.jar:6.1.5]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:925) ~[spring-webmvc-6.1.5.jar:6.1.5]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:830) ~[spring-webmvc-6.1.5.jar:6.1.5]
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) ~[spring-webmvc-6.1.5.jar:6.1.5]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1089) ~[spring-webmvc-6.1.5.jar:6.1.5]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:979) ~[spring-webmvc-6.1.5.jar:6.1.5]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1014) ~[spring-webmvc-6.1.5.jar:6.1.5]
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:903) ~[spring-webmvc-6.1.5.jar:6.1.5]
at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:564) ~[tomcat-embed-core-10.1.19.jar:6.0]
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:885) ~[spring-webmvc-6.1.5.jar:6.1.5]
at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:658) ~[tomcat-embed-core-10.1.19.jar:6.0]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:205) ~[tomcat-embed-core-10.1.19.jar:10.1.19]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:149) ~[tomcat-embed-core-10.1.19.jar:10.1.19]
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51) ~[tomcat-embed-websocket-10.1.19.jar:10.1.19]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:174) ~[tomcat-embed-core-10.1.19.jar:10.1.19]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:149) ~[tomcat-embed-core-10.1.19.jar:10.1.19]
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100) ~[spring-web-6.1.5.jar:6.1.5]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116) ~[spring-web-6.1.5.jar:6.1.5]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:174) ~[tomcat-embed-core-10.1.19.jar:10.1.19]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:149) ~[tomcat-embed-core-10.1.19.jar:10.1.19]
at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93) ~[spring-web-6.1.5.jar:6.1.5]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116) ~[spring-web-6.1.5.jar:6.1.5]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:174) ~[tomcat-embed-core-10.1.19.jar:10.1.19]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:149) ~[tomcat-embed-core-10.1.19.jar:10.1.19]
at org.springframework.web.filter.ServerHttpObservationFilter.doFilterInternal(ServerHttpObservationFilter.java:109) ~[spring-web-6.1.5.jar:6.1.5]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116) ~[spring-web-6.1.5.jar:6.1.5]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:174) ~[tomcat-embed-core-10.1.19.jar:10.1.19]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:149) ~[tomcat-embed-core-10.1.19.jar:10.1.19]
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201) ~[spring-web-6.1.5.jar:6.1.5]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116) ~[spring-web-6.1.5.jar:6.1.5]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:174) ~[tomcat-embed-core-10.1.19.jar:10.1.19]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:149) ~[tomcat-embed-core-10.1.19.jar:10.1.19]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:167) ~[tomcat-embed-core-10.1.19.jar:10.1.19]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:90) ~[tomcat-embed-core-10.1.19.jar:10.1.19]
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:482) ~[tomcat-embed-core-10.1.19.jar:10.1.19]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:115) ~[tomcat-embed-core-10.1.19.jar:10.1.19]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:93) ~[tomcat-embed-core-10.1.19.jar:10.1.19]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74) ~[tomcat-embed-core-10.1.19.jar:10.1.19]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:344) ~[tomcat-embed-core-10.1.19.jar:10.1.19]
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:391) ~[tomcat-embed-core-10.1.19.jar:10.1.19]
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:63) ~[tomcat-embed-core-10.1.19.jar:10.1.19]
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:896) ~[tomcat-embed-core-10.1.19.jar:10.1.19]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1744) ~[tomcat-embed-core-10.1.19.jar:10.1.19]
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:52) ~[tomcat-embed-core-10.1.19.jar:10.1.19]
at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191) ~[tomcat-embed-core-10.1.19.jar:10.1.19]
at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659) ~[tomcat-embed-core-10.1.19.jar:10.1.19]
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:63) ~[tomcat-embed-core-10.1.19.jar:10.1.19]
at java.base/java.lang.Thread.run(Thread.java:833) ~[na:na]

I put debug break point in controller class then service class then repository class.

I tried to start application in debug mode but I do not see that option

I put log statement in Controller and SErvice which are prinitng 1 as well as below. But in repository layer failing. How to print the query the is being executed?



Please advise


ACCOUNT-NOT-IN-DB.JPG
[Thumbnail for ACCOUNT-NOT-IN-DB.JPG]
debug-mode.JPG
[Thumbnail for debug-mode.JPG]
customerid1.JPG
[Thumbnail for customerid1.JPG]
 
sai rama krishna
Ranch Hand
Posts: 1013
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I printed the SQL as below by including below line application.properties file
spring.jpa.show-sql=true

Also in boot debugger view I am able to start server in debug mode as well
Looks like query expecting account_number not customer Id. Please advise





Loans worked as attached





loansworks.jpg
[Thumbnail for loansworks.jpg]
loans_working.JPG
[Thumbnail for loans_working.JPG]
loans-db.JPG
[Thumbnail for loans-db.JPG]
 
sai rama krishna
Ranch Hand
Posts: 1013
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also cards worked as below, attached.  Both cards and loans working does not have service layer. Accounts not working has service layer not sure any issue with that



cards_works.jpg
[Thumbnail for cards_works.jpg]
cardssworks.JPG
[Thumbnail for cardssworks.JPG]
cards_db.JPG
[Thumbnail for cards_db.JPG]
 
sai rama krishna
Ranch Hand
Posts: 1013
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I will try to  remember not to edit posts. Mostly I am editing to correct typos and attach forgotten images. I updated my code as below by removing customerId variable reference and adding accountNumber variable as reference as dealing with accounts here. Below is the query generated by intellij idea when i put hibernate query as true in configuration


select a1_0.account_number,a1_0.account_type,a1_0.branch_address,a1_0.create_dt,a1_0.customer_id from account a1_0 where a1_0.account_number=1

I get below same error no records found in database as below



When I try to execute same query in h2o console there also i get results found even though there is record with account number 1 as attached when I use below query

SELECT * FROM ACCOUNT

My complete updated code of this accounts micro service as below. Please advise


select-star-accounts-works-fine..JPG
[Thumbnail for select-star-accounts-works-fine..JPG]
same-query-from-h2o-console-yields-no-results.JPG
[Thumbnail for same-query-from-h2o-console-yields-no-results.JPG]
query-generated-in-idea.JPG
[Thumbnail for query-generated-in-idea.JPG]
 
sai rama krishna
Ranch Hand
Posts: 1013
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you all for your help, guidance. It finally worked when I give account number value (instead of customerId) in the query as that is primary key. Latest working code, working screenshots attached




accounts_working_from_browser.JPG
[Thumbnail for accounts_working_from_browser.JPG]
accounts_working.JPG
[Thumbnail for accounts_working.JPG]
 
Marshal
Posts: 80740
485
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

sai rama krishna wrote:I will try to  remember not to edit posts. Mostly I am editing to correct typos and attach forgotten images. . . .

That is not too bad; it doesn't usually cause confusion later.
 
sai rama krishna
Ranch Hand
Posts: 1013
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agree. Thank you.
 
reply
    Bookmark Topic Watch Topic
  • New Topic