• 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
  • Ron McLeod
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Rob Spoor
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Carey Brown
Bartenders:

HttpServerErrorException$InternalServerError: 500 with RestTemplate

 
Ranch Hand
Posts: 502
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a Spring Boot application trying to access a REST web service with RestTemplate.
The code in the client is:

The code in the controller is:

The problem is that i am getting the exception
Exception in thread "main" org.springframework.web.client.HttpServerErrorException$InternalServerError: 500 : [{"timestamp":"2020-08-25T19:30:13.149+00:00","status":500,"error":"Internal Server Error","message":"","path":"/resultSet/com.paperless.Select_Conn@4044fb95"}]
Digging in the debugger, it appears that the program is trying to do some JSON mapping, but that is just something I have noticed. I am an experienced Java developer, but I am learning how to program REST clients. I have spend the last two days browsing the net without success.
 
Sheriff
Posts: 22716
129
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It looks as if you're trying to pass a connection to your database file through HTTP to the server. That is not going to work. The connection is local to one machine, and you cannot transfer it to another machine in any way. You can transfer the source, but not the connection itself.

Spring Boot doesn't tell you that clearly though. It tries to convert the connection to a string (for the URL), then back to a connection. The first part works using toString() (the com.paperless.Select_Conn@4044fb95 part), but converting it back fails.

Maybe you could tell us what you're trying to achieve here?


Alejandro Barrero wrote:


Just a side note: you can merge the contenet of @RequestMapping into the @GetMapping; @GetMapping is @RequestMapping with the method pre-filled to GET.
 
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Looks like my post this morning (which said much the same thing) vanished...

There's also the inverse of sending the Connection, which is expecting a ResultSet back.
That won't work either.

Instances of these classes are not designed to be sent across a network.
 
Alejandro Barrero
Ranch Hand
Posts: 502
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your quick response Rob and Dave. Originally I wasn't passing the connection; I wanted to return a ResultSet, but it doesn't work after the connection is closed. It appears I have to construct the list of objects from the ResultSet and return the list.
 
Sheriff
Posts: 27525
88
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Alejandro Barrero wrote:Thanks for your quick response Rob and Dave. Originally I wasn't passing the connection; I wanted to return a ResultSet, but it doesn't work after the connection is closed. It appears I have to construct the list of objects from the ResultSet and return the list.



Well, yes, you can't pass a ResultSet between machines anyway. Constructing a list of objects from a ResultSet is the standard way to do what you're trying to do; it's even the standard way to extract data from a database and pass it along to something else in the same JVM.
 
reply
    Bookmark Topic Watch Topic
  • New Topic