0

This I'm trying to achieve, but with Java code. The form is this:

<form method="post" action="HtmlAdaptor">
  <input type="hidden" name="action" value="invokeOp">
  <input type="hidden" name="name" value="dcm4chee.archive:service=ContentEditService">
  <input type="hidden" name="methodIndex" value="29">
  <hr align='left' width='80'>
  <h4>void purgeStudy()</h4>
  <p>Purge study. (Files will be removed from FilesystemMgt service see</p>

  <table cellspacing="2" cellpadding="2" border="1">
    <tr class="OperationHeader">
      <th>Param</th>
      <th>ParamType</th>
      <th>ParamValue</th>
      <th>ParamDescription</th>
    </tr>

    <tr>
      <td>iuid</td>
      <td>java.lang.String</td>
      <td>

        <input type="text" name="arg0">

      </td>
      <td>Study Instance UID.</td>
    </tr>

  </table>

  <input type="submit" value="Invoke">
</form>

The program I wrote:

// the URL of the configuration page on the JMX Console
URL url = new URL("http://localhost:8080/jmx-console/"
    + "HtmlAdaptor?action=inspectMBean&name="
    + "dcm4chee.archive%3Aservice%3DContentEditService");

// the login information
String userpassEnc = Base64.getEncoder().encodeToString(("admin:admin")
    .getBytes(StandardCharsets.UTF_8));

// the data to be sent
String params
    = "action=invokeOp&name=dcm4chee.archive%3Aservice%3DContentEditService"
    + "&methodIndex=29&arg0=123456&submit=Invoke";
byte[] postData = params.getBytes(StandardCharsets.UTF_8);

// Configuring the connection...
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("Authorization", "Basic " + userpassEnc);
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
conn.setRequestProperty("charset", "utf-8");
conn.setRequestProperty("Content-Length", Integer.toString(postData.length));
conn.setConnectTimeout(5000);
conn.setDoOutput(true);
conn.setInstanceFollowRedirects(true);

// Sending the data...
DataOutputStream out = new DataOutputStream(conn.getOutputStream());
out.write(postData);

// Receiving the response...
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
while (in.readLine() != null) { System.out.println(in.readLine()); }

The result:

The login is successful but the MBean method is not invoked because the form is not posted. As response I get only the HTML source of the web page that has the form I'd like to post. (When posting the form from a web browser, a page would open telling me whether the invoked operation was successful. I would expect the source code of that page as a response.)

tom
  • 2,137
  • 2
  • 27
  • 51

1 Answers1

0

I've found the error in the code, the only thing I had to do is change the URL to "http://localhost:8080/jmx-console/HtmlAdaptor". It's working now.

tom
  • 2,137
  • 2
  • 27
  • 51