private void doSend(final String gatewayMessage) {
		HttpURLConnection urlConnection = null;

		try {
			if (proxy == null) {
				urlConnection = (HttpURLConnection) gatewayUrl.openConnection();
			} else {
				urlConnection = (HttpURLConnection) gatewayUrl.openConnection(proxy);
			}
			urlConnection.setRequestMethod("POST");
			urlConnection.setDoInput(true);
			urlConnection.setDoOutput(true);
			urlConnection.setReadTimeout(timeoutInMillis);
			urlConnection.setRequestProperty("content-type", "application/json; charset=utf-8");
			urlConnection.setRequestProperty("x-stackdriver-apikey", apiKey);

			// Stackdriver's own implementation does not specify char encoding
			// to use. Let's take the simplest approach and at lest ensure that
			// if we have problems they can be reproduced in consistant ways.
			// See https://github.com/Stackdriver/stackdriver-custommetrics-java/blob/master/src/main/java/com/stackdriver/api/custommetrics/CustomMetricsPoster.java#L262
			// for details.
			urlConnection.getOutputStream().write(gatewayMessage.getBytes(ISO_8859_1));

			int responseCode = urlConnection.getResponseCode();
			if (responseCode != 200 && responseCode != 201) {
				logger.warn("Failed to send results to Stackdriver server: responseCode=" + responseCode + " message=" + urlConnection.getResponseMessage());
			}
		} catch (Exception e) {
			logger.warn("Failure to send result to Stackdriver server", e);
		} finally {
			if (urlConnection != null) {
				try {
					InputStream in = urlConnection.getInputStream();
					in.close();
					InputStream err = urlConnection.getErrorStream();
					if (err != null) {
						err.close();
					}
					urlConnection.disconnect();
				} catch (IOException e) {
					logger.warn("Error flushing http connection for one result, continuing");
					logger.debug("Stack trace for the http connection, usually a network timeout", e);
				}
			}

		}
	}
private void doSend ( final String gatewayMessage ) { HttpURLConnection urlConnection = null ; try { if ( proxy == null ) { urlConnection = ( HttpURLConnection ) gatewayUrl . openConnection ( ) ; } else { urlConnection = ( HttpURLConnection ) gatewayUrl . openConnection ( proxy ) ; } urlConnection . setRequestMethod ( "POST" ) ; urlConnection . setDoInput ( true ) ; urlConnection . setDoOutput ( true ) ; urlConnection . setReadTimeout ( timeoutInMillis ) ; urlConnection . setRequestProperty ( "content-type" , "application/json; charset=utf-8" ) ; urlConnection . setRequestProperty ( "x-stackdriver-apikey" , apiKey ) ; urlConnection . getOutputStream ( ) . write ( gatewayMessage . getBytes ( ISO_8859_1 ) ) ; int responseCode = urlConnection . getResponseCode ( ) ; if ( responseCode != 200 && responseCode != 201 ) { logger . warn ( "Failed to send results to Stackdriver server: responseCode=" + responseCode + " message=" + urlConnection . getResponseMessage ( ) ) ; } } catch ( Exception e ) { logger . warn ( "Failure to send result to Stackdriver server" , e ) ; } finally { if ( urlConnection != null ) { try { InputStream in = urlConnection . getInputStream ( ) ; in . close ( ) ; InputStream err = urlConnection . getErrorStream ( ) ; if ( err != null ) { err . close ( ) ; } urlConnection . disconnect ( ) ; } catch ( IOException e ) { logger . warn ( "Error flushing http connection for one result, continuing" ) ; logger . debug ( "Stack trace for the http connection, usually a network timeout" , e ) ; } } } }
Post the formatted results to the gateway URL over HTTP

@param gatewayMessage String in the Stackdriver custom metrics JSON format containing the data points