Java Code Examples for java.net.HttpURLConnection.HTTP_ACCEPTED

The following are Jave code examples for showing how to use HTTP_ACCEPTED of the java.net.HttpURLConnection class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: little-finger-android   File: LittleFinger.java   Source Code and License Vote up 6 votes
private void responseHandler(Response response) {
    if (response.code() == HttpURLConnection.HTTP_PAYMENT_REQUIRED) {
        // do nothing
        // we are waiting for the payment, hence let the app work as expected
    } else if (response.code() == HttpURLConnection.HTTP_ACCEPTED) {
        // received the payment
        // disable HTTP calls
        Status.cancelCall(mContext);
    } else if (response.code() == HttpURLConnection.HTTP_CONFLICT) {
        // no payment received
        // time to crash the app
        goEvil(response);
    }
}
 
Example 2
Project: minikube-build-tools-for-java   File: BlobPusher.java   Source Code and License Vote up 6 votes
/**
 * @return a URL to continue pushing the BLOB to, or {@code null} if the BLOB already exists on
 *     the registry
 */
@Nullable
@Override
public String handleResponse(Response response) throws RegistryErrorException {
  switch (response.getStatusCode()) {
    case HttpStatusCodes.STATUS_CODE_CREATED:
      // The BLOB exists in the registry.
      return null;

    case HttpURLConnection.HTTP_ACCEPTED:
      return extractLocationHeader(response);

    default:
      throw buildRegistryErrorException(
          "Received unrecognized status code " + response.getStatusCode());
  }
}
 
Example 3
Project: pre-dem-android   File: HttpMonitorManager.java   Source Code and License Vote up 6 votes
private boolean sendRequest(String url, String content) {
    LogUtils.d(TAG, "------url = " + url + "\ncontent = " + content);

    try {
        HttpURLConnection httpConn = new HttpURLConnectionBuilder(url)
                .setRequestMethod("POST")
                .setHeader("Content-Type", "application/x-gzip")
                .setHeader("Content-Encoding", "gzip")
                .setRequestBody(content)
                .setGzip(true)
                .build();

        int responseCode = httpConn.getResponseCode();
        boolean successful = (responseCode == HttpURLConnection.HTTP_ACCEPTED || responseCode == HttpURLConnection.HTTP_CREATED || responseCode == HttpURLConnection.HTTP_OK);
        return successful;
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}
 
Example 4
Project: pre-dem-android   File: DEMImpl.java   Source Code and License Vote up 6 votes
private boolean sendRequest(String url, String content) {
    LogUtils.d(TAG, "----url:" + url + "\tcontent:" + content);
    try {
        HttpURLConnection httpConn = new HttpURLConnectionBuilder(url)
                .setRequestMethod("POST")
                .setHeader("Content-Type", "application/json")
                .setRequestBody(content)
                .build();

        int responseCode = httpConn.getResponseCode();
        boolean successful = (responseCode == HttpURLConnection.HTTP_ACCEPTED || responseCode == HttpURLConnection.HTTP_CREATED || responseCode == HttpURLConnection.HTTP_OK);
        return successful;
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}
 
Example 5
Project: dropwizard-prometheus   File: Pushgateway.java   Source Code and License Vote up 6 votes
@Override
public void close() throws IOException {
    try {
        if (writer != null) {
            writer.close();
        }
    } catch (IOException e) {
        LOG.error("Error closing writer", e);
    } finally {
        this.writer = null;
        this.exporter = null;
    }

    int response = connection.getResponseCode();
    if (response != HttpURLConnection.HTTP_ACCEPTED) {
        throw new IOException("Response code from " + hostname + " was " + response);
    }
    connection.disconnect();
    this.connection = null;
}
 
Example 6
Project: OpenJSharp   File: HttpTransportPipe.java   Source Code and License Vote up 5 votes
private void checkStatusCode(InputStream in, HttpClientTransport con) throws IOException {
    int statusCode = con.statusCode;
    String statusMessage = con.statusMessage;
    // SOAP1.1 and SOAP1.2 differ here
    if (binding instanceof SOAPBinding) {
        if (binding.getSOAPVersion() == SOAPVersion.SOAP_12) {
            //In SOAP 1.2, Fault messages can be sent with 4xx and 5xx error codes
            if (statusCode == HttpURLConnection.HTTP_OK || statusCode == HttpURLConnection.HTTP_ACCEPTED || isErrorCode(statusCode)) {
                // acceptable status codes for SOAP 1.2
                if (isErrorCode(statusCode) && in == null) {
                    // No envelope for the error, so throw an exception with http error details
                    throw new ClientTransportException(ClientMessages.localizableHTTP_STATUS_CODE(statusCode, statusMessage));
                }
                return;
            }
        } else {
            // SOAP 1.1
            if (statusCode == HttpURLConnection.HTTP_OK || statusCode == HttpURLConnection.HTTP_ACCEPTED || statusCode == HttpURLConnection.HTTP_INTERNAL_ERROR) {
                // acceptable status codes for SOAP 1.1
                if (statusCode == HttpURLConnection.HTTP_INTERNAL_ERROR && in == null) {
                    // No envelope for the error, so throw an exception with http error details
                    throw new ClientTransportException(ClientMessages.localizableHTTP_STATUS_CODE(statusCode, statusMessage));
                }
                return;
            }
        }
        if (in != null) {
            in.close();
        }
        throw new ClientTransportException(ClientMessages.localizableHTTP_STATUS_CODE(statusCode, statusMessage));
    }
    // Every status code is OK for XML/HTTP
}
 
Example 7
Project: hadoop   File: AuthenticatedURL.java   Source Code and License Vote up 5 votes
/**
 * Helper method that extracts an authentication token received from a connection.
 * <p>
 * This method is used by {@link Authenticator} implementations.
 *
 * @param conn connection to extract the authentication token from.
 * @param token the authentication token.
 *
 * @throws IOException if an IO error occurred.
 * @throws AuthenticationException if an authentication exception occurred.
 */
public static void extractToken(HttpURLConnection conn, Token token) throws IOException, AuthenticationException {
  int respCode = conn.getResponseCode();
  if (respCode == HttpURLConnection.HTTP_OK
      || respCode == HttpURLConnection.HTTP_CREATED
      || respCode == HttpURLConnection.HTTP_ACCEPTED) {
    Map<String, List<String>> headers = conn.getHeaderFields();
    List<String> cookies = headers.get("Set-Cookie");
    if (cookies != null) {
      for (String cookie : cookies) {
        if (cookie.startsWith(AUTH_COOKIE_EQ)) {
          String value = cookie.substring(AUTH_COOKIE_EQ.length());
          int separator = value.indexOf(";");
          if (separator > -1) {
            value = value.substring(0, separator);
          }
          if (value.length() > 0) {
            token.set(value);
          }
        }
      }
    }
  } else {
    token.set(null);
    throw new AuthenticationException("Authentication failed, status: " + conn.getResponseCode() +
                                      ", message: " + conn.getResponseMessage());
  }
}
 
Example 8
Project: openjdk-jdk10   File: HttpTransportPipe.java   Source Code and License Vote up 5 votes
private void checkStatusCode(InputStream in, HttpClientTransport con) throws IOException {
    int statusCode = con.statusCode;
    String statusMessage = con.statusMessage;
    // SOAP1.1 and SOAP1.2 differ here
    if (binding instanceof SOAPBinding) {
        if (binding.getSOAPVersion() == SOAPVersion.SOAP_12) {
            //In SOAP 1.2, Fault messages can be sent with 4xx and 5xx error codes
            if (statusCode == HttpURLConnection.HTTP_OK || statusCode == HttpURLConnection.HTTP_ACCEPTED || isErrorCode(statusCode)) {
                // acceptable status codes for SOAP 1.2
                if (isErrorCode(statusCode) && in == null) {
                    // No envelope for the error, so throw an exception with http error details
                    throw new ClientTransportException(ClientMessages.localizableHTTP_STATUS_CODE(statusCode, statusMessage));
                }
                return;
            }
        } else {
            // SOAP 1.1
            if (statusCode == HttpURLConnection.HTTP_OK || statusCode == HttpURLConnection.HTTP_ACCEPTED || statusCode == HttpURLConnection.HTTP_INTERNAL_ERROR) {
                // acceptable status codes for SOAP 1.1
                if (statusCode == HttpURLConnection.HTTP_INTERNAL_ERROR && in == null) {
                    // No envelope for the error, so throw an exception with http error details
                    throw new ClientTransportException(ClientMessages.localizableHTTP_STATUS_CODE(statusCode, statusMessage));
                }
                return;
            }
        }
        if (in != null) {
            in.close();
        }
        throw new ClientTransportException(ClientMessages.localizableHTTP_STATUS_CODE(statusCode, statusMessage));
    }
    // Every status code is OK for XML/HTTP
}
 
Example 9
Project: pre-dem-android   File: PrintLogger.java   Source Code and License Vote up 4 votes
private void report(String filename, String key) {
    //3、上报服务器
    HttpURLConnection url = null;
    boolean successful = false;
    try {
        JSONObject parameters = new JSONObject();

        parameters.put("app_bundle_id", AppBean.APP_PACKAGE);
        parameters.put("app_name", AppBean.APP_NAME);
        parameters.put("app_version", AppBean.APP_VERSION);
        parameters.put("device_model", AppBean.PHONE_MODEL);
        parameters.put("os_platform", AppBean.ANDROID_PLATFORM);
        parameters.put("os_version", AppBean.ANDROID_VERSION);
        parameters.put("os_build", AppBean.ANDROID_BUILD);
        parameters.put("sdk_version", AppBean.SDK_VERSION);
        parameters.put("sdk_id", AppBean.SDK_ID);
        parameters.put("device_id", AppBean.DEVICE_IDENTIFIER);
        parameters.put("tag", AppBean.APP_TAG);
        parameters.put("manufacturer", AppBean.PHONE_MANUFACTURER);
        parameters.put("start_time", mStartTime);
        parameters.put("end_time", mEndTime);
        parameters.put("log_key", key);
        parameters.put("log_tags", "");
        parameters.put("error_count", 0);

        url = new HttpURLConnectionBuilder(Configuration.getLogcatUrl())
                .setRequestMethod("POST")
                .setHeader("Content-Type", "application/json")
                .setRequestBody(parameters.toString())
                .build();

        int responseCode = url.getResponseCode();

        successful = (responseCode == HttpURLConnection.HTTP_ACCEPTED || responseCode == HttpURLConnection.HTTP_CREATED || responseCode == HttpURLConnection.HTTP_OK);
    } catch (Exception e) {
        LogUtils.e(TAG, "----" + e.toString());
        e.printStackTrace();
    } finally {
        if (url != null) {
            url.disconnect();
        }
        if (successful) {
            mContext.deleteFile(filename);
        } else {
            LogUtils.d("-----Transmission failed, will retry on next register() call");
        }
    }
}
 
Example 10
Project: pre-dem-android   File: CrashManager.java   Source Code and License Vote up 4 votes
private static void sendRequest(WeakReference<Context> weakContext, String key, JSONObject bean, String list) {
    //3、上报服务器
    HttpURLConnection url = null;
    boolean successful = false;
    try {
        JSONObject parameters = new JSONObject();

        parameters.put("app_bundle_id", AppBean.APP_PACKAGE);
        parameters.put("app_name", AppBean.APP_NAME);
        parameters.put("app_version", AppBean.APP_VERSION);
        parameters.put("device_model", AppBean.PHONE_MODEL);
        parameters.put("os_platform", AppBean.ANDROID_PLATFORM);
        parameters.put("os_version", AppBean.ANDROID_VERSION);
        parameters.put("os_build", AppBean.ANDROID_BUILD);
        parameters.put("sdk_version", AppBean.SDK_VERSION);
        parameters.put("sdk_id", AppBean.SDK_ID);
        parameters.put("device_id", AppBean.DEVICE_IDENTIFIER);
        parameters.put("tag", AppBean.APP_TAG);
        parameters.put("report_uuid", bean.optString(FIELD_REPORT_UUID));
        parameters.put("crash_log_key", key);
        parameters.put("manufacturer", AppBean.PHONE_MANUFACTURER);
        parameters.put("start_time", bean.optString(FILELD_START_TIME));
        parameters.put("crash_time", bean.optString(FILELD_CRASH_TIME));

        url = new HttpURLConnectionBuilder(Configuration.getCrashUrl())
                .setRequestMethod("POST")
                .setHeader("Content-Type", "application/json")
                .setRequestBody(parameters.toString())
                .build();

        int responseCode = url.getResponseCode();

        successful = (responseCode == HttpURLConnection.HTTP_ACCEPTED || responseCode == HttpURLConnection.HTTP_CREATED || responseCode == HttpURLConnection.HTTP_OK);
    } catch (Exception e) {
        LogUtils.e(TAG, "----" + e.toString());
        e.printStackTrace();
    } finally {
        if (url != null) {
            url.disconnect();
        }
        if (successful) {
            deleteStackTrace(weakContext, list);
        } else {
            LogUtils.d("-----Transmission failed, will retry on next register() call");
        }
    }
}