spring-rest module before running this live test
- */
-public class OkHttpPostingLiveTest {
-
- private static final String BASE_URL = "http://localhost:" + APPLICATION_PORT + "/spring-rest";
- private static final String URL_SECURED_BY_BASIC_AUTHENTICATION = "http://browserspy.dk/password-ok.php";
-
- OkHttpClient client;
-
- @Before
- public void init() {
-
- client = new OkHttpClient();
- }
-
- @Test
- public void whenSendPostRequest_thenCorrect() throws IOException {
- final RequestBody formBody = new FormBody.Builder().add("username", "test").add("password", "test").build();
-
- final Request request = new Request.Builder().url(BASE_URL + "/users").post(formBody).build();
-
- final Call call = client.newCall(request);
- final Response response = call.execute();
-
- assertThat(response.code(), equalTo(200));
- }
-
- @Test
- public void whenSendPostRequestWithAuthorization_thenCorrect() throws IOException {
- final String postBody = "test post";
-
- final Request request = new Request.Builder().url(URL_SECURED_BY_BASIC_AUTHENTICATION).addHeader("Authorization", Credentials.basic("test", "test")).post(RequestBody.create(MediaType.parse("text/x-markdown; charset=utf-8"), "test post")).build();
-
- final Call call = client.newCall(request);
- final Response response = call.execute();
-
- assertThat(response.code(), equalTo(200));
- }
-
- @Test
- public void whenPostJson_thenCorrect() throws IOException {
- final String json = "{\"id\":1,\"name\":\"John\"}";
-
- final RequestBody body = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), "{\"id\":1,\"name\":\"John\"}");
- final Request request = new Request.Builder().url(BASE_URL + "/users/detail").post(body).build();
-
- final Call call = client.newCall(request);
- final Response response = call.execute();
-
- assertThat(response.code(), equalTo(200));
- }
-
- @Test
- public void whenSendMultipartRequest_thenCorrect() throws IOException {
- final RequestBody requestBody = new MultipartBody.Builder().setType(MultipartBody.FORM).addFormDataPart("username", "test").addFormDataPart("password", "test")
- .addFormDataPart("file", "file.txt", RequestBody.create(MediaType.parse("application/octet-stream"), new File("src/test/resources/test.txt"))).build();
-
- final Request request = new Request.Builder().url(BASE_URL + "/users/multipart").post(requestBody).build();
-
- final Call call = client.newCall(request);
- final Response response = call.execute();
-
- assertThat(response.code(), equalTo(200));
- }
-}
+package com.baeldung.okhttp.post;
+
+import static com.baeldung.client.Consts.APPLICATION_PORT;
+import static org.hamcrest.Matchers.equalTo;
+import static org.junit.Assert.assertThat;
+
+import java.io.File;
+import java.io.IOException;
+
+import okhttp3.Call;
+import okhttp3.Credentials;
+import okhttp3.FormBody;
+import okhttp3.MediaType;
+import okhttp3.MultipartBody;
+import okhttp3.OkHttpClient;
+import okhttp3.Request;
+import okhttp3.RequestBody;
+import okhttp3.Response;
+
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Execute spring-rest module before running this live test
+ */
+public class OkHttpPostingLiveTest {
+
+ private static final String BASE_URL = "http://localhost:" + APPLICATION_PORT + "/spring-rest";
+ private static final String URL_SECURED_BY_BASIC_AUTHENTICATION = "http://browserspy.dk/password-ok.php";
+
+ OkHttpClient client;
+
+ @Before
+ public void init() {
+
+ client = new OkHttpClient();
+ }
+
+ @Test
+ public void whenSendPostRequest_thenCorrect() throws IOException {
+ final RequestBody formBody = new FormBody.Builder()
+ .add("username", "test")
+ .add("password", "test")
+ .build();
+
+ final Request request = new Request.Builder()
+ .url(BASE_URL + "/users")
+ .post(formBody)
+ .build();
+
+ final Call call = client.newCall(request);
+ final Response response = call.execute();
+
+ assertThat(response.code(), equalTo(200));
+ }
+
+ @Test
+ public void whenSendPostRequestWithAuthorization_thenCorrect() throws IOException {
+ final String postBody = "test post";
+
+ final Request request = new Request.Builder()
+ .url(URL_SECURED_BY_BASIC_AUTHENTICATION)
+ .addHeader("Authorization", Credentials.basic("test", "test"))
+ .post(RequestBody.create(MediaType.parse("text/x-markdown"), "test post"))
+ .build();
+
+ final Call call = client.newCall(request);
+ final Response response = call.execute();
+
+ assertThat(response.code(), equalTo(200));
+ }
+
+ @Test
+ public void whenPostJson_thenCorrect() throws IOException {
+ final String json = "{\"id\":1,\"name\":\"John\"}";
+
+ final RequestBody body = RequestBody.create(MediaType.parse("application/json"), "{\"id\":1,\"name\":\"John\"}");
+ final Request request = new Request.Builder().url(BASE_URL + "/users/detail").post(body).build();
+
+ final Call call = client.newCall(request);
+ final Response response = call.execute();
+
+ assertThat(response.code(), equalTo(200));
+ }
+
+ @Test
+ public void whenPostJsonWithoutCharset_thenCharsetIsUtf8() throws IOException {
+ final String json = "{\"id\":1,\"name\":\"John\"}";
+
+ final RequestBody body = RequestBody.create(
+ MediaType.parse("application/json"), json);
+
+ String charset = body.contentType().charset().displayName();
+
+ assertThat(charset, equalTo("UTF-8"));
+ }
+
+ @Test
+ public void whenPostJsonWithUtf16Charset_thenCharsetIsUtf16() throws IOException {
+ final String json = "{\"id\":1,\"name\":\"John\"}";
+
+ final RequestBody body = RequestBody.create(
+ MediaType.parse("application/json; charset=utf-16"), json);
+
+ String charset = body.contentType().charset().displayName();
+
+ assertThat(charset, equalTo("UTF-16"));
+ }
+
+ @Test
+ public void whenSendMultipartRequest_thenCorrect() throws IOException {
+ final RequestBody requestBody = new MultipartBody.Builder().setType(MultipartBody.FORM).addFormDataPart("username", "test").addFormDataPart("password", "test")
+ .addFormDataPart("file", "file.txt", RequestBody.create(MediaType.parse("application/octet-stream"), new File("src/test/resources/test.txt"))).build();
+
+ final Request request = new Request.Builder().url(BASE_URL + "/users/multipart").post(requestBody).build();
+
+ final Call call = client.newCall(request);
+ final Response response = call.execute();
+
+ assertThat(response.code(), equalTo(200));
+ }
+}
diff --git a/libraries-io/src/test/java/org/baeldung/java/io/remote/SftpFileTransferLiveTest.java b/libraries-io/src/test/java/com/baeldung/java/io/remote/SftpFileTransferLiveTest.java
similarity index 99%
rename from libraries-io/src/test/java/org/baeldung/java/io/remote/SftpFileTransferLiveTest.java
rename to libraries-io/src/test/java/com/baeldung/java/io/remote/SftpFileTransferLiveTest.java
index 192153bc90..5846128082 100644
--- a/libraries-io/src/test/java/org/baeldung/java/io/remote/SftpFileTransferLiveTest.java
+++ b/libraries-io/src/test/java/com/baeldung/java/io/remote/SftpFileTransferLiveTest.java
@@ -1,4 +1,4 @@
-package org.baeldung.java.io.remote;
+package com.baeldung.java.io.remote;
import java.io.IOException;
diff --git a/linux-bash/read/src/main/bash/file.csv b/linux-bash/read/src/main/bash/file.csv
new file mode 100644
index 0000000000..69a50772ab
--- /dev/null
+++ b/linux-bash/read/src/main/bash/file.csv
@@ -0,0 +1 @@
+car,car model,car year,car vin;Mercury,Grand Marquis,2000,2G61S5S33F9986032;Mitsubishi,Truck,1995,SCFFDABE1CG137362;Ford,Mustang,1968,2G4WS55J351278031;Ford,Crown Victoria,1996,4T1BK1EB8EU586249;GMC,Envoy,2004,WVGEF9BP3FD720618;
diff --git a/linux-bash/read/src/main/bash/read_inputs.sh b/linux-bash/read/src/main/bash/read_inputs.sh
new file mode 100755
index 0000000000..30eb598ac3
--- /dev/null
+++ b/linux-bash/read/src/main/bash/read_inputs.sh
@@ -0,0 +1,122 @@
+#!/bin/bash
+
+# section 2.1
+default_read(){
+ read input1 input2 input3
+ echo "[$input1] [$input2] [$input3]"
+}
+
+# section 2.2
+custom_ifs_no_array(){
+ OLDIFS=$IFS
+ IFS=";"
+ read input1 input2 input3
+ echo "[$input1] [$input2] [$input3]"
+ # restore default IFS after we're finished so current shell behaves like before
+ IFS=$OLDIFS
+}
+
+# Section 2.3
+prompt_read_password(){
+ prompt="You shall not pass:"
+ read -p "$prompt" -s input
+ echo -e "\ninput password [$input]"
+}
+
+array_read(){
+ declare -a input_array
+ text="baeldung is a cool tech site"
+ read -e -i "$text" -a input_array
+ for input in ${input_array[@]}
+ do
+ echo " word [$input]"
+ done
+}
+
+# section 3.1
+file_read(){
+ exec {file_descriptor}<"./file.csv"
+ declare -a input_array
+ delimiter=";"
+ while IFS="," read -a input_array -d $delimiter -u $file_descriptor
+ do
+ echo "${input_array[0]},${input_array[2]}"
+ done
+ exec {file_descriptor}>&-
+}
+
+# section 3.2
+command_pipe(){
+ ls -ll / | { declare -a input
+ read
+ while read -a input;
+ do
+ echo "${input[0]} ${input[8]}"
+ done }
+}
+
+# section 3.3
+timeout_input_read(){
+ prompt="You shall not pass:"
+ read -p "$prompt" -s -r -t 5 input
+ if [ -z "$input" ]; then
+ echo -e "\ntimeout occured!"
+ else
+ echo -e "\ninput word [$input]"
+ fi
+}
+
+exactly_n_read(){
+ prompt="Reading exactly 11 chars:"
+ read -p "$prompt" -N 11 -t 5 input1 input2
+ echo -e "\ninput word1 [$input1]"
+ echo "input word2 [$input2]"
+}
+
+# main menu entry point
+echo "****Read command samples menu*****"
+PS3="Your choice (1,2,3 etc.):"
+options=("default_read" "custom_ifs_no_array" "prompt_read_password" \
+ "array_read" "file_read" "command_pipe" "timeout_input_read" \
+ "exactly_n_read" "quit")
+select option in "${options[@]}"
+do
+ case $option in
+ "default_read")
+ echo "Enter something separated by spaces"
+ default_read
+ ;;
+ "custom_ifs_no_array")
+ echo "Enter something separated by ;"
+ custom_ifs_no_array
+ ;;
+ "prompt_read_password")
+ echo "Enter an invisible password after the prompt"
+ prompt_read_password
+ ;;
+ "array_read")
+ echo "Enter something else or just return"
+ array_read
+ ;;
+ "file_read")
+ echo "Reading from one liner csv file"
+ file_read
+ ;;
+ "command_pipe")
+ echo "Listing files and access rights from /"
+ command_pipe
+ ;;
+ "timeout_input_read")
+ echo "Enter something in 5 seconds or less"
+ timeout_input_read
+ ;;
+ "exactly_n_read")
+ echo "Enter at least 11 characters or wait 5 seconds"
+ exactly_n_read
+ ;;
+ "quit")
+ break
+ ;;
+ *) echo "Invalid option";;
+ esac
+done
\ No newline at end of file
diff --git a/logging-modules/logback/pom.xml b/logging-modules/logback/pom.xml
index 6ffc9e1235..ee430949df 100644
--- a/logging-modules/logback/pom.xml
+++ b/logging-modules/logback/pom.xml
@@ -50,12 +50,25 @@
Spring Security Thymeleaf tutorial
-Spring Security Thymeleaf tutorial
+