Also, can you clarify if you're using any existing libraries, and if not why not (just as an academic exercise, or in an attempt to solve some problem the existing libraries don't, or something else?)
I would have expected more options to already exist, but the ACME Client List does point out one existing library that might be helpful, called acme4j.