Shouldn't you be closing the response output stream on the server side, rather than the exchange itself?
i.e.
public class SMPBClientHandler implements HttpHandler {
@Override
public void handle(final HttpExchange exchange) throws IOException {
OutputStream os = exchange.getResponseBody();
os.write("response".getBytes());
os.close();
}
}
And on client-side
HttpURLConnection retHttpURLConnection = (HttpURLConnection) urlToConnect.openConnection();
retHttpURLConnection.setRequestMethod("POST");
retHttpURLConnection.setRequestProperty("Connection", "keep-alive");
//Some work code and then
os = connection.getOutputStream();
//Some work with response
os.close();