getting response back from a Java Servlet to Drupal
To force download, you want to set the proper headers for filename, content-disposition and content-length. In your case, it may need to be set from the Servlet application, but without knowing the details of $response, that's difficult to determine.

In general, though, your headers should look something like this:

'Content-disposition:attachment;filename=foobar.pdf' (content-disposition:inline is the opposite of this)
'Content-length:1234567098'