com.google.ipc.invalidation.ticl.android2.channel.AndroidChannelConstants.HttpConstants Java Examples

The following examples show how to use com.google.ipc.invalidation.ticl.android2.channel.AndroidChannelConstants.HttpConstants. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AndroidMessageSenderService.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a URL to use to send a message to the data center.
 *
 * @param gaiaServiceId Gaia service for which the request will be authenticated (when using a
 *      GoogleLogin token), or {@code null} when using an OAuth2 token.
 * @param networkEndpointId network id of the client
 */
private static URL buildUrl(String gaiaServiceId, NetworkEndpointId networkEndpointId)
    throws MalformedURLException {
  StringBuilder urlBuilder = new StringBuilder();

  // Build base URL that targets the inbound request service with the encoded network endpoint
  // id.
  urlBuilder.append((channelUrlForTest != null) ? channelUrlForTest : HttpConstants.CHANNEL_URL);
  urlBuilder.append(HttpConstants.REQUEST_URL);

  // TODO: We should be sending a ClientGatewayMessage in the request body
  // instead of appending the client's network endpoint id to the request URL. Once we do that, we
  // should use a UriBuilder to build up a structured Uri object instead of the brittle string
  // concatenation we're doing below.
  urlBuilder.append(base64Encode(networkEndpointId.toByteArray()));

  // Add query parameter indicating the service to authenticate against
  if (gaiaServiceId != null) {
    urlBuilder.append('?');
    urlBuilder.append(HttpConstants.SERVICE_PARAMETER);
    urlBuilder.append('=');
    urlBuilder.append(gaiaServiceId);
  }
  return new URL(urlBuilder.toString());
}
 
Example #2
Source File: AndroidMessageSenderService.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Returns a URL to use to send a message to the data center.
 *
 * @param gaiaServiceId Gaia service for which the request will be authenticated (when using a
 *      GoogleLogin token), or {@code null} when using an OAuth2 token.
 * @param networkEndpointId network id of the client
 */
private static URL buildUrl(String gaiaServiceId, NetworkEndpointId networkEndpointId)
    throws MalformedURLException {
  StringBuilder urlBuilder = new StringBuilder();

  // Build base URL that targets the inbound request service with the encoded network endpoint
  // id.
  urlBuilder.append((channelUrlForTest != null) ? channelUrlForTest : HttpConstants.CHANNEL_URL);
  urlBuilder.append(HttpConstants.REQUEST_URL);

  // TODO: We should be sending a ClientGatewayMessage in the request body
  // instead of appending the client's network endpoint id to the request URL. Once we do that, we
  // should use a UriBuilder to build up a structured Uri object instead of the brittle string
  // concatenation we're doing below.
  urlBuilder.append(base64Encode(networkEndpointId.toByteArray()));

  // Add query parameter indicating the service to authenticate against
  if (gaiaServiceId != null) {
    urlBuilder.append('?');
    urlBuilder.append(HttpConstants.SERVICE_PARAMETER);
    urlBuilder.append('=');
    urlBuilder.append(gaiaServiceId);
  }
  return new URL(urlBuilder.toString());
}
 
Example #3
Source File: AndroidMessageSenderService.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Returns an {@link HttpURLConnection} to use to POST a message to the data center. Sets
 * the content-type and user-agent headers; also sets the echo token header if we have an
 * echo token.
 *
 * @param context Android context
 * @param url URL to which to post
 * @param authToken auth token to provide in the request header
 * @param isOAuth2Token whether the token is an OAuth2 token (vs. a GoogleLogin token)
 */

public static HttpURLConnection createUrlConnectionForPost(Context context, URL url,
    String authToken, boolean isOAuth2Token) throws IOException {
  HttpURLConnection connection = (HttpURLConnection) url.openConnection();
  try {
    connection.setRequestMethod("POST");
  } catch (ProtocolException exception) {
    throw new RuntimeException("Cannot set request method to POST: " + exception);
  }
  connection.setDoOutput(true);
  if (isOAuth2Token) {
    connection.setRequestProperty("Authorization", "Bearer " + authToken);
  } else {
    connection.setRequestProperty("Authorization", "GoogleLogin auth=" + authToken);
  }
  connection.setRequestProperty("Content-Type", HttpConstants.PROTO_CONTENT_TYPE);
  connection.setRequestProperty("User-Agent",
      context.getApplicationInfo().className + "(" + Build.VERSION.RELEASE + ")");
  String echoToken = AndroidChannelPreferences.getEchoToken(context);
  if (echoToken != null) {
    // If we have a token to echo to the server, echo it.
    connection.setRequestProperty(HttpConstants.ECHO_HEADER, echoToken);
  }
  return connection;
}
 
Example #4
Source File: AndroidMessageSenderService.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Returns a URL to use to send a message to the data center.
 *
 * @param gaiaServiceId Gaia service for which the request will be authenticated (when using a
 *      GoogleLogin token), or {@code null} when using an OAuth2 token.
 * @param networkEndpointId network id of the client
 */
private static URL buildUrl(String gaiaServiceId, NetworkEndpointId networkEndpointId)
    throws MalformedURLException {
  StringBuilder urlBuilder = new StringBuilder();

  // Build base URL that targets the inbound request service with the encoded network endpoint
  // id.
  urlBuilder.append((channelUrlForTest != null) ? channelUrlForTest : HttpConstants.CHANNEL_URL);
  urlBuilder.append(HttpConstants.REQUEST_URL);

  // TODO: We should be sending a ClientGatewayMessage in the request body
  // instead of appending the client's network endpoint id to the request URL. Once we do that, we
  // should use a UriBuilder to build up a structured Uri object instead of the brittle string
  // concatenation we're doing below.
  urlBuilder.append(base64Encode(networkEndpointId.toByteArray()));

  // Add query parameter indicating the service to authenticate against
  if (gaiaServiceId != null) {
    urlBuilder.append('?');
    urlBuilder.append(HttpConstants.SERVICE_PARAMETER);
    urlBuilder.append('=');
    urlBuilder.append(gaiaServiceId);
  }
  return new URL(urlBuilder.toString());
}
 
Example #5
Source File: AndroidMessageSenderService.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Returns an {@link HttpURLConnection} to use to POST a message to the data center. Sets
 * the content-type and user-agent headers; also sets the echo token header if we have an
 * echo token.
 *
 * @param context Android context
 * @param url URL to which to post
 * @param authToken auth token to provide in the request header
 * @param isOAuth2Token whether the token is an OAuth2 token (vs. a GoogleLogin token)
 */

public static HttpURLConnection createUrlConnectionForPost(Context context, URL url,
    String authToken, boolean isOAuth2Token) throws IOException {
  HttpURLConnection connection = (HttpURLConnection) url.openConnection();
  try {
    connection.setRequestMethod("POST");
  } catch (ProtocolException exception) {
    throw new RuntimeException("Cannot set request method to POST: " + exception);
  }
  connection.setDoOutput(true);
  if (isOAuth2Token) {
    connection.setRequestProperty("Authorization", "Bearer " + authToken);
  } else {
    connection.setRequestProperty("Authorization", "GoogleLogin auth=" + authToken);
  }
  connection.setRequestProperty("Content-Type", HttpConstants.PROTO_CONTENT_TYPE);
  connection.setRequestProperty("User-Agent",
      context.getApplicationInfo().className + "(" + Build.VERSION.RELEASE + ")");
  String echoToken = AndroidChannelPreferences.getEchoToken(context);
  if (echoToken != null) {
    // If we have a token to echo to the server, echo it.
    connection.setRequestProperty(HttpConstants.ECHO_HEADER, echoToken);
  }
  return connection;
}
 
Example #6
Source File: AndroidMessageSenderService.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Returns an {@link HttpURLConnection} to use to POST a message to the data center. Sets
 * the content-type and user-agent headers; also sets the echo token header if we have an
 * echo token.
 *
 * @param context Android context
 * @param url URL to which to post
 * @param authToken auth token to provide in the request header
 * @param isOAuth2Token whether the token is an OAuth2 token (vs. a GoogleLogin token)
 */

public static HttpURLConnection createUrlConnectionForPost(
    Context context, URL url, String authToken, boolean isOAuth2Token) throws IOException {
  HttpURLConnection connection = (HttpURLConnection) url.openConnection();
  try {
    connection.setRequestMethod("POST");
  } catch (ProtocolException exception) {
    throw new RuntimeException("Cannot set request method to POST", exception);
  }
  connection.setDoOutput(true);
  if (isOAuth2Token) {
    connection.setRequestProperty("Authorization", "Bearer " + authToken);
  } else {
    connection.setRequestProperty("Authorization", "GoogleLogin auth=" + authToken);
  }
  connection.setRequestProperty("Content-Type", HttpConstants.PROTO_CONTENT_TYPE);
  connection.setRequestProperty(
      "User-Agent", context.getApplicationInfo().className + "(" + Build.VERSION.RELEASE + ")");
  
  String echoToken = AndroidChannelPreferences.getEchoToken(context);
  if (echoToken != null) {
    // If we have a token to echo to the server, echo it.
    connection.setRequestProperty(HttpConstants.ECHO_HEADER, echoToken);
  }
  return connection;
}