1 package net.sf.openrocket.communication;
3 import java.io.IOException;
4 import java.io.OutputStreamWriter;
5 import java.net.HttpURLConnection;
7 import net.sf.openrocket.util.BuildProperties;
9 public class BugReporter extends Communicator {
11 // Inhibit instantiation
12 private BugReporter() {
17 * Send the provided report to the OpenRocket bug report URL. If the connection
18 * fails or the server does not respond with the correct response code, an
19 * exception is thrown.
21 * @param report the report to send.
22 * @throws IOException if an error occurs while connecting to the server or
23 * the server responds with a wrong response code.
25 public static void sendBugReport(String report) throws IOException {
27 HttpURLConnection connection = connectionSource.getConnection(BUG_REPORT_URL);
29 connection.setConnectTimeout(CONNECTION_TIMEOUT);
30 connection.setInstanceFollowRedirects(true);
31 connection.setRequestMethod("POST");
32 connection.setUseCaches(false);
33 connection.setRequestProperty("X-OpenRocket-Version", encode(BuildProperties.getVersion()));
36 post = (VERSION_PARAM + "=" + encode(BuildProperties.getVersion())
37 + "&" + BUG_REPORT_PARAM + "=" + encode(report));
39 OutputStreamWriter wr = null;
41 // Send post information
42 connection.setDoOutput(true);
43 wr = new OutputStreamWriter(connection.getOutputStream(), "UTF-8");
47 if (connection.getResponseCode() != BUG_REPORT_RESPONSE_CODE) {
48 throw new IOException("Server responded with code " +
49 connection.getResponseCode() + ", expecting " + BUG_REPORT_RESPONSE_CODE);
54 connection.disconnect();