@Test public void testPost() throws Exception { Map<String, String> requestHeaders = new HashMap(); requestHeaders.put("headerKey1", "headerValue1"); requestHeaders.put("headerKey2", "headerValue2"); RequestParameter requestParameter = new RequestParameter() .put("param1", "value1") .put("param2", "value2&="); String postData = "param1=value1&param2=value2%26%3D"; setResponseData("test".getBytes(CHARSET)); LineApiResponse<String> responseData = target.post( Uri.parse("https: requestHeaders, requestParameter.getMapData(), new StringResponseParser()); verify(target).openHttpConnection(Uri.parse("https: verify(httpsURLConnection).setRequestMethod("POST"); verify(httpsURLConnection).setDoOutput(true); verify(httpsURLConnection).setRequestProperty("User-Agent", USER_AGENT); verify(httpsURLConnection).setRequestProperty("Accept-Encoding", "gzip"); verify(httpsURLConnection).setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); verify(httpsURLConnection).setRequestProperty("Content-Length", String.valueOf(postData.getBytes(CHARSET).length)); verify(httpsURLConnection).setRequestProperty("headerKey1", "headerValue1"); verify(httpsURLConnection).setRequestProperty("headerKey2", "headerValue2"); verify(httpsURLConnection).setConnectTimeout(CONNECT_TIMEOUT_MILLIS); verify(httpsURLConnection).setReadTimeout(READ_TIMEOUT_MILLIS); assertEquals(postData, connectionOutputStream.toString(CHARSET)); assertTrue(responseData.isSuccess()); assertEquals("test", responseData.getResponseData()); assertEquals(LineApiError.DEFAULT, responseData.getErrorData()); }
@WorkerThread @NonNull public <T> LineApiResponse<T> post( @NonNull Uri uri, @NonNull Map<String, String> requestHeaders, @NonNull Map<String, String> postData, @NonNull ResponseDataParser<T> responseDataParser) { byte[] postDataBytes = convertPostDataToBytes(postData); HttpURLConnection conn = null; try { conn = openPostConnection(uri, postDataBytes.length); setRequestHeaders(conn, requestHeaders); if (BuildConfig.DEBUG) { logRequestForDebug(conn, postDataBytes); } conn.connect(); OutputStream os = conn.getOutputStream(); os.write(postDataBytes); os.flush(); if (BuildConfig.DEBUG) { logResponseHeadersForDebug(conn); } return getChannelServiceResponse(conn, responseDataParser, errorResponseParser); } catch (IOException e) { LineApiResponse<T> response = LineApiResponse.createAsError( LineApiResponseCode.NETWORK_ERROR, new LineApiError(e)); logExceptionForDebug(response, e); return response; } finally { if (conn != null) { conn.disconnect(); } } }
ChannelServiceHttpClient { @WorkerThread @NonNull public <T> LineApiResponse<T> post( @NonNull Uri uri, @NonNull Map<String, String> requestHeaders, @NonNull Map<String, String> postData, @NonNull ResponseDataParser<T> responseDataParser) { byte[] postDataBytes = convertPostDataToBytes(postData); HttpURLConnection conn = null; try { conn = openPostConnection(uri, postDataBytes.length); setRequestHeaders(conn, requestHeaders); if (BuildConfig.DEBUG) { logRequestForDebug(conn, postDataBytes); } conn.connect(); OutputStream os = conn.getOutputStream(); os.write(postDataBytes); os.flush(); if (BuildConfig.DEBUG) { logResponseHeadersForDebug(conn); } return getChannelServiceResponse(conn, responseDataParser, errorResponseParser); } catch (IOException e) { LineApiResponse<T> response = LineApiResponse.createAsError( LineApiResponseCode.NETWORK_ERROR, new LineApiError(e)); logExceptionForDebug(response, e); return response; } finally { if (conn != null) { conn.disconnect(); } } } }
ChannelServiceHttpClient { @WorkerThread @NonNull public <T> LineApiResponse<T> post( @NonNull Uri uri, @NonNull Map<String, String> requestHeaders, @NonNull Map<String, String> postData, @NonNull ResponseDataParser<T> responseDataParser) { byte[] postDataBytes = convertPostDataToBytes(postData); HttpURLConnection conn = null; try { conn = openPostConnection(uri, postDataBytes.length); setRequestHeaders(conn, requestHeaders); if (BuildConfig.DEBUG) { logRequestForDebug(conn, postDataBytes); } conn.connect(); OutputStream os = conn.getOutputStream(); os.write(postDataBytes); os.flush(); if (BuildConfig.DEBUG) { logResponseHeadersForDebug(conn); } return getChannelServiceResponse(conn, responseDataParser, errorResponseParser); } catch (IOException e) { LineApiResponse<T> response = LineApiResponse.createAsError( LineApiResponseCode.NETWORK_ERROR, new LineApiError(e)); logExceptionForDebug(response, e); return response; } finally { if (conn != null) { conn.disconnect(); } } } ChannelServiceHttpClient(@NonNull Context context, @NonNull String lineSdkVersion); @VisibleForTesting protected  ChannelServiceHttpClient(@NonNull UserAgentGenerator userAgentGenerator); }
ChannelServiceHttpClient { @WorkerThread @NonNull public <T> LineApiResponse<T> post( @NonNull Uri uri, @NonNull Map<String, String> requestHeaders, @NonNull Map<String, String> postData, @NonNull ResponseDataParser<T> responseDataParser) { byte[] postDataBytes = convertPostDataToBytes(postData); HttpURLConnection conn = null; try { conn = openPostConnection(uri, postDataBytes.length); setRequestHeaders(conn, requestHeaders); if (BuildConfig.DEBUG) { logRequestForDebug(conn, postDataBytes); } conn.connect(); OutputStream os = conn.getOutputStream(); os.write(postDataBytes); os.flush(); if (BuildConfig.DEBUG) { logResponseHeadersForDebug(conn); } return getChannelServiceResponse(conn, responseDataParser, errorResponseParser); } catch (IOException e) { LineApiResponse<T> response = LineApiResponse.createAsError( LineApiResponseCode.NETWORK_ERROR, new LineApiError(e)); logExceptionForDebug(response, e); return response; } finally { if (conn != null) { conn.disconnect(); } } } ChannelServiceHttpClient(@NonNull Context context, @NonNull String lineSdkVersion); @VisibleForTesting protected  ChannelServiceHttpClient(@NonNull UserAgentGenerator userAgentGenerator); void setConnectTimeoutMillis(int connectTimeoutMillis); void setReadTimeoutMillis(int readTimeoutMillis); @WorkerThread @NonNull LineApiResponse<T> post(
            @NonNull Uri uri,
            @NonNull Map<String, String> requestHeaders,
            @NonNull Map<String, String> postData,
            @NonNull ResponseDataParser<T> responseDataParser); @WorkerThread @NonNull LineApiResponse<T> postWithJson(
            @NonNull Uri uri,
            @NonNull Map<String, String> requestHeaders,
            @NonNull String postData,
            @NonNull ResponseDataParser<T> responseDataParser); @WorkerThread @NonNull LineApiResponse<T> putWithJson(
            @NonNull Uri uri,
            @NonNull Map<String, String> requestHeaders,
            @NonNull String postData,
            @Nullable ResponseDataParser<T> responseDataParser); @WorkerThread @NonNull LineApiResponse<T> get(
            @NonNull Uri uri,
            @NonNull Map<String, String> requestHeaders,
            @NonNull Map<String, String> queryParameters,
            @Nullable ResponseDataParser<T> responseDataParser); @WorkerThread @NonNull LineApiResponse<T> delete(
            @NonNull Uri uri,
            @NonNull Map<String, String> requestHeaders,
            @Nullable ResponseDataParser<T> responseDataParser); }
ChannelServiceHttpClient { @WorkerThread @NonNull public <T> LineApiResponse<T> post( @NonNull Uri uri, @NonNull Map<String, String> requestHeaders, @NonNull Map<String, String> postData, @NonNull ResponseDataParser<T> responseDataParser) { byte[] postDataBytes = convertPostDataToBytes(postData); HttpURLConnection conn = null; try { conn = openPostConnection(uri, postDataBytes.length); setRequestHeaders(conn, requestHeaders); if (BuildConfig.DEBUG) { logRequestForDebug(conn, postDataBytes); } conn.connect(); OutputStream os = conn.getOutputStream(); os.write(postDataBytes); os.flush(); if (BuildConfig.DEBUG) { logResponseHeadersForDebug(conn); } return getChannelServiceResponse(conn, responseDataParser, errorResponseParser); } catch (IOException e) { LineApiResponse<T> response = LineApiResponse.createAsError( LineApiResponseCode.NETWORK_ERROR, new LineApiError(e)); logExceptionForDebug(response, e); return response; } finally { if (conn != null) { conn.disconnect(); } } } ChannelServiceHttpClient(@NonNull Context context, @NonNull String lineSdkVersion); @VisibleForTesting protected  ChannelServiceHttpClient(@NonNull UserAgentGenerator userAgentGenerator); void setConnectTimeoutMillis(int connectTimeoutMillis); void setReadTimeoutMillis(int readTimeoutMillis); @WorkerThread @NonNull LineApiResponse<T> post(
            @NonNull Uri uri,
            @NonNull Map<String, String> requestHeaders,
            @NonNull Map<String, String> postData,
            @NonNull ResponseDataParser<T> responseDataParser); @WorkerThread @NonNull LineApiResponse<T> postWithJson(
            @NonNull Uri uri,
            @NonNull Map<String, String> requestHeaders,
            @NonNull String postData,
            @NonNull ResponseDataParser<T> responseDataParser); @WorkerThread @NonNull LineApiResponse<T> putWithJson(
            @NonNull Uri uri,
            @NonNull Map<String, String> requestHeaders,
            @NonNull String postData,
            @Nullable ResponseDataParser<T> responseDataParser); @WorkerThread @NonNull LineApiResponse<T> get(
            @NonNull Uri uri,
            @NonNull Map<String, String> requestHeaders,
            @NonNull Map<String, String> queryParameters,
            @Nullable ResponseDataParser<T> responseDataParser); @WorkerThread @NonNull LineApiResponse<T> delete(
            @NonNull Uri uri,
            @NonNull Map<String, String> requestHeaders,
            @Nullable ResponseDataParser<T> responseDataParser);  }