@Test public void testIllegalResponseDataByPost() throws Exception { setErrorData(400, "testErrorMessage".getBytes(CHARSET)); LineApiResponse<String> responseData = target.post( Uri.parse("https: Collections.<String, String>emptyMap() , Collections.<String, String>emptyMap() , new StringResponseParser()); assertFalse(responseData.isSuccess()); assertEquals(LineApiResponseCode.SERVER_ERROR, responseData.getResponseCode()); assertEquals(400, responseData.getErrorData().getHttpResponseCode()); assertEquals("testErrorMessage", responseData.getErrorData().getMessage()); }
@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);  }