0

I am trying to use mockwebserver to test POSTing via a Jakarta-based activation URLDataSource's outputStream.

In the jakarta.activation.DataSource, you only have "getInputStream()/getOutputStream()".

The 'getOutputStream()' method internally opens a URLConnection and gets and returns its OutputStream().

  @Override
  public OutputStream getOutputStream() throws IOException {
    URLConnection connection = this.uri.toURL().openConnection();
    connection.setDoOutput(true);
    return connection.getOutputStream();
  }

I can write to the output-stream with no problem. But closing the output-stream does not trigger the MockWebServer dispatcher. Since I don't have the connection in the caller, I can't call "getResponseCode()" to make the request hit the server (as in some examples I have seen).

try (OutputStream os = (new URIDataSource(mockWebServerUri)).getOutputStream()) {
  IOUtils.write(testMessage, os, StandardCharsets.UTF_8);
} catch (IOException ex) {
  fail ("Unable to obtain OutputStream from URIDataSource.");
}

Any suggestions on how / if I can trigger the dispatcher after closing the output-stream without having the connection?

Cheers, Jeff

JWT
  • 143
  • 1
  • 6

0 Answers0