503 service unavailable

crio-user@suyash-sreekumar:~/workspace/annual-return-app$ python3 dashboard.py --json trades.json
Namespace(json=‘trades.json’)
http://localhost:8081/portfolio/analyze {
“name”: “Anand”,
“portfolioTrades”: [
{
“symbol”: “AAPL”,
“quantity”: 100,
“tradeType”: “BUY”,
“purchaseDate”: “2019-01-02”
},
{
“symbol”: “MSFT”,
“quantity”: 10,
“tradeType”: “BUY”,
“purchaseDate”: “2019-01-02”
},
{
“symbol”: “GOOGL”,
“quantity”: 50,
“tradeType”: “BUY”,
“purchaseDate”: “2019-01-02”
}
]
}
<Response [503]>
{
“timestamp”: “2020-03-03T17:14:57.632+0000”,
“status”: 503,
“error”: “Service Unavailable”,
“message”: “Provider error”,
“trace”: “org.springframework.web.server.ResponseStatusException: 503 SERVICE_UNAVAILABLE “Provider error”; nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of com.crio.warmup.stock.dto.Candle (no Creators, like default construct, exist): abstract types either need to be mapped to concrete types, have custom deserializer, or contain additional type information\n at [Source: (StringReader); line: 1, column: 2] (through reference chain: java.util.ArrayList[0])\n\tat com.crio.stock.annualreturnapp.AnnualReturnsController.calculateReturns(AnnualReturnsController.java:46)\n\tat sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\n\tat sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)\n\tat sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\n\tat java.lang.reflect.Method.invoke(Method.java:498)\n\tat org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:190)\n\tat org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138)\n\tat org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:106)\n\tat org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:888)\n\tat org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:793)\n\tat org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)\n\tat org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1040)\n\tat org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943)\n\tat org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)\n\tat org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909)\n\tat javax.servlet.http.HttpServlet.service(HttpServlet.java:660)\n\tat org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)\n\tat javax.servlet.http.HttpServlet.service(HttpServlet.java:741)\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)\n\tat org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)\n\tat org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100)\n\tat org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)\n\tat org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93)\n\tat org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)\n\tat org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201)\n\tat org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)\n\tat org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202)\n\tat org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)\n\tat org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:526)\n\tat org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)\n\tat org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)\n\tat org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)\n\tat org.apache.catalina.valves.RemoteIpValve.invoke(RemoteIpValve.java:747)\n\tat org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)\n\tat org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:367)\n\tat org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)\n\tat org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:860)\n\tat org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1591)\n\tat org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)\n\tat java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)\n\tat java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)\n\tat org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)\n\tat java.lang.Thread.run(Thread.java:748)\nCaused by: com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of com.crio.warmup.stock.dto.Candle (no Creators, like default construct, exist): abstract types either need to be mapped to concrete types, have custom deserializer, or contain additional type information\n at [Source: (StringReader); line: 1, column: 2] (through reference chain: java.util.ArrayList[0])\n\tat com.fasterxml.jackson.databind.exc.InvalidDefinitionException.from(InvalidDefinitionException.java:67)\n\tat com.fasterxml.jackson.databind.DeserializationContext.reportBadDefinition(DeserializationContext.java:1589)\n\tat com.fasterxml.jackson.databind.DeserializationContext.handleMissingInstantiator(DeserializationContext.java:1055)\n\tat com.fasterxml.jackson.databind.deser.AbstractDeserializer.deserialize(AbstractDeserializer.java:265)\n\tat com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:286)\n\tat com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:245)\n\tat com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:27)\n\tat com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4202)\n\tat com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3205)\n\tat com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3188)\n\tat com.crio.warmup.stock.portfolio.PortfolioManagerImpl.getStockQuote(PortfolioManagerImpl.java:157)\n\tat com.crio.warmup.stock.portfolio.PortfolioManagerImpl.calculateAnnualizedReturn(PortfolioManagerImpl.java:88)\n\tat com.crio.stock.annualreturnapp.AnnualReturnsController.calculateReturns(AnnualReturnsController.java:40)\n\t… 51 more\n”,
“path”: “/portfolio/analyze”
}

My error is not in the builduri template but in the getStockQuotes.
   
        List<Candle> co = s.readValue(ting, new TypeReference<ArrayList<Candle>>() {}

This is inside and getStockQuotes
The return type of the function is of type list Candle so I cannot change that.
So can someone give me a hint on how to resolve this issue.

Hey @Suyash, we can not instantiate an interface.
Candle is an interface and it has not any constructor (obvious) but Jackson ObjectMapper requires setters, getters, and a constructor to map corresponding data members (serialization).

Solution Hint: Use interface implementing class
List<TiingoCandle> co = s.readValue(ting, new TypeReference<ArrayList<TiingoCandle>>()
1 Like

@imbipulkumar I did try using TiingoCandle but the return type is of type candle and because of that it throws an error of type mismatch.

@Suyash then change the return type also.
Note: Rebuild the project after making necessary changes.

But @imbipulkumar they had clearly mentioned not to modify method signature explicitly.
Wouldnt I be violating the rule then.

@Suyash I guess the code section you are referring is a part of TODO: and one can make necessary changes.

Okay will modify accordingly then
and let you know.

Hey @Suyash, another way around is to create anonymous class implementing Candle interface. Thus you will retain the return type.

Hey @Suyash, Hope the suggestion help. Kindly mark the solution and close the post.

@imbipulkumar thanks for the suggestion.
Will have to look into anonymous class.
DId you implement using that or changing candle to TiingoCandle as the return type?

Yes @Suyash, from the beginning.

how to implement using anonymous class for Candle Interface

Hey @MaheshThalluri, you can implement using anonymous inner class.
Hint: https://www.geeksforgeeks.org/anonymous-inner-class-java/

Hope this helps!