Win a copy of Java XML & JSON this week in the XML and Related Technologies forum!

David Belcher

+ Follow
since Sep 07, 2018
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by David Belcher


My question is: Is it right to convert object before controller in http message converter OR I should do it in my controller calling specific converter manually.

I receive JSON from browser, in this format:

Before I get in controller I want to convert some properties, for example, from id to model [int groupId -> Group group].
So the final object will be like this:

And controller in this case is very small:

For such convertion, I created and registered CreateScheduleDTOConverter:

And in AppConfig that implements WebMvcConfigurer added:

5 days ago

I read this article
And created custom class annotation for multiple fields validation like was written in "9. Custom Class Level Validation".

I wonder how to display class validation error. For field I do:

But I dont know how to bind my validation error with some field or just how to show it in thymeleaf template?
If you know any solution, please reply.

That object with custom annotation @UniqueTranslation:

In debugger I see my error in BindingResult:

In validator I just override isValid() method:

If required (links on github code):
UniqueTranslation annotation
UniqueField annotation
3 weeks ago

Rob Spoor wrote:That's a common problem with HTTP connections - the input stream doesn't end when the body does. You really have to a) use the content length, or b) check for specific markers that are content-type specific.

Assuming you have the content length:

Thank you. It really helped.
I rewrote the whole project to make it more readable. Now all works fine even with high resolution photos.

Here's how I handled contentLength of the input stream:

And I made it easy to get form parameter:

Can you give me advices on the following:
I have RequestProcessor in which I parse request and Request where I store only neccessory fields and methods (very simple methods like getters). Should I do so? Or my Request should extend RequestProcessor?
3 months ago

Dave Tolls wrote:read does not fill up the byte[].
It fills up what it can, based on what is available on the stream.
This is very unlikely (for something large) to be all the data of your file.
The key to that is the number returned by read.  Do not ignore this, as it tells you how much was read in.

So what is happening is you are creating a byte buffer and then doing a read on it, but the stream cannot fill the buffer as not all the data has been received.
You then use what there is in the buffer, ignoring that read has told you it hasn't filled it.

Thank you!
Because I don't know how many bytes I need to read, I tried like this, but this loop never ends.
Browser page loading lasts forever.

3 months ago
@Ron McLeod I knew about this. I didn't found solution how to get all bytes in one time.
I get available bytes to read header 'Content-Length' and then use that parsed integer to read remain bytes to inputBuffer. I do it in checkBufferSize(contentLength) method on line 81.
3 months ago

Tim Nachreiner wrote:What tool are you using to develop the Angular piece?

I use visual studio code!
3 months ago
Hi guys!

I have a project where I have only one class HttpServer.

Every time I try to get binary file data from http request and save it to the file, I get broken photo. (If photo size is big, the top of that photo is normal and the other part is green) (If photo is small it works fine)
I don't understand why!

If I debug code and have AT LEAST ONE BREAKPOINT (So I wait about second or two), then it works well and photo isn't broken!

I couldn't find out how tomcat does it so we can just call request.getParts(). And I want to make the same in a simple way just to understand HOW it works.

The project is packed to ZIP file. You can test the problem just starting Starter.bat (It will show console and open browser on upload page)
3 months ago

Tim Nachreiner wrote:I viewed your source code and was impressed.
Is this a tutorial you are following?
If so, would you share the link?

Thank you!
No, I don't use any specific tutorial. It's my first project on java. I google almost everything that I don't know. Stackoverflow, baeldung, etc.
5 months ago
I did wrong search requests in google. I found a solution. I added

to controller method updateTotal() right before fetching data one more time.
5 months ago
Hello! It's my first topic)

Spring Data JPA | Hibernate

In a nutshell, I get data from one table, do some stuff like inserting or updating data in the bounded tables. Try to fetch data from the first table, but spring returns me old data.

In details.
In my controller I fetch order:

Then I get order products:

I have amount of specific product from HTTP request.
Update order's product amount :

It's okay, I updated amount of product, but I need to count and update total price of order. I try to get order with assosiated products again in another method, but i get old data:

Full code of class is here:

How to tell spring that data was changed and i need to flush old data and fetch new?

5 months ago