From a687c57d7a5fc8841434fd01f36912f054e0bf11 Mon Sep 17 00:00:00 2001 From: WarL0ck Date: Wed, 6 Dec 2017 22:55:55 +0700 Subject: [PATCH] =?UTF-8?q?=D0=A7=D1=82=D0=BE-=D1=82=D0=BE=20=D0=BD=D0=B0?= =?UTF-8?q?=D1=87=D0=B0=D0=BB=D0=BE=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0?= =?UTF-8?q?=D1=82=D1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...ackson_core_jackson_annotations_2_9_2.xml} | 8 +-- ...erxml_jackson_core_jackson_core_2_9_2.xml} | 8 +-- ...l_jackson_core_jackson_databind_2_9_2.xml} | 8 +-- ...format_jackson_dataformat_json_unknown.xml | 13 ---- ...n__com_jayway_jsonpath_json_path_2_2_0.xml | 13 ---- ...ogle_android_json_0_0_20131108_vaadin1.xml | 13 ---- .idea/libraries/Maven__junit_junit_4_12.xml | 13 ---- ...Maven__net_minidev_accessors_smart_1_1.xml | 13 ---- .../Maven__net_minidev_json_smart_2_2_1.xml | 13 ---- .../Maven__org_assertj_assertj_core_2_6_0.xml | 13 ---- .../Maven__org_atteo_evo_inflector_1_2_2.xml | 13 ---- .../Maven__org_hamcrest_hamcrest_core_1_3.xml | 13 ---- ...ven__org_hamcrest_hamcrest_library_1_3.xml | 13 ---- ...aven__org_mockito_mockito_core_1_10_19.xml | 13 ---- .../Maven__org_objenesis_objenesis_2_1.xml | 13 ---- .../Maven__org_ow2_asm_asm_5_0_3.xml | 13 ---- ...aven__org_skyscreamer_jsonassert_1_4_0.xml | 13 ---- ...g_boot_starter_data_rest_1_5_9_RELEASE.xml | 13 ---- ...spring_boot_starter_test_1_5_9_RELEASE.xml | 13 ---- ...rk_boot_spring_boot_test_1_5_9_RELEASE.xml | 13 ---- ..._boot_test_autoconfigure_1_5_9_RELEASE.xml | 13 ---- ...ata_spring_data_commons_1_13_9_RELEASE.xml | 13 ---- ...ta_spring_data_rest_core_2_6_9_RELEASE.xml | 13 ---- ..._spring_data_rest_webmvc_2_6_9_RELEASE.xml | 13 ---- ..._hateoas_spring_hateoas_0_23_0_RELEASE.xml | 13 ---- ...lugin_spring_plugin_core_1_2_0_RELEASE.xml | 13 ---- ...ngframework_spring_test_4_3_13_RELEASE.xml | 13 ---- ...ringframework_spring_tx_4_3_13_RELEASE.xml | 13 ---- config.properties | 2 +- pom.xml | 26 +++---- restClient.iml | 37 ++-------- .../restClient/RestActionsController.java | 72 ++++++++++++------- .../cft/task/restClient/RestErrorHandler.java | 12 ---- 33 files changed, 78 insertions(+), 420 deletions(-) rename .idea/libraries/{Maven__com_fasterxml_jackson_core_jackson_annotations_2_8_0.xml => Maven__com_fasterxml_jackson_core_jackson_annotations_2_9_2.xml} (65%) rename .idea/libraries/{Maven__com_fasterxml_jackson_core_jackson_core_2_8_10.xml => Maven__com_fasterxml_jackson_core_jackson_core_2_9_2.xml} (65%) rename .idea/libraries/{Maven__com_fasterxml_jackson_core_jackson_databind_2_8_10.xml => Maven__com_fasterxml_jackson_core_jackson_databind_2_9_2.xml} (62%) delete mode 100644 .idea/libraries/Maven__com_fasterxml_jackson_dataformat_jackson_dataformat_json_unknown.xml delete mode 100644 .idea/libraries/Maven__com_jayway_jsonpath_json_path_2_2_0.xml delete mode 100644 .idea/libraries/Maven__com_vaadin_external_google_android_json_0_0_20131108_vaadin1.xml delete mode 100644 .idea/libraries/Maven__junit_junit_4_12.xml delete mode 100644 .idea/libraries/Maven__net_minidev_accessors_smart_1_1.xml delete mode 100644 .idea/libraries/Maven__net_minidev_json_smart_2_2_1.xml delete mode 100644 .idea/libraries/Maven__org_assertj_assertj_core_2_6_0.xml delete mode 100644 .idea/libraries/Maven__org_atteo_evo_inflector_1_2_2.xml delete mode 100644 .idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml delete mode 100644 .idea/libraries/Maven__org_hamcrest_hamcrest_library_1_3.xml delete mode 100644 .idea/libraries/Maven__org_mockito_mockito_core_1_10_19.xml delete mode 100644 .idea/libraries/Maven__org_objenesis_objenesis_2_1.xml delete mode 100644 .idea/libraries/Maven__org_ow2_asm_asm_5_0_3.xml delete mode 100644 .idea/libraries/Maven__org_skyscreamer_jsonassert_1_4_0.xml delete mode 100644 .idea/libraries/Maven__org_springframework_boot_spring_boot_starter_data_rest_1_5_9_RELEASE.xml delete mode 100644 .idea/libraries/Maven__org_springframework_boot_spring_boot_starter_test_1_5_9_RELEASE.xml delete mode 100644 .idea/libraries/Maven__org_springframework_boot_spring_boot_test_1_5_9_RELEASE.xml delete mode 100644 .idea/libraries/Maven__org_springframework_boot_spring_boot_test_autoconfigure_1_5_9_RELEASE.xml delete mode 100644 .idea/libraries/Maven__org_springframework_data_spring_data_commons_1_13_9_RELEASE.xml delete mode 100644 .idea/libraries/Maven__org_springframework_data_spring_data_rest_core_2_6_9_RELEASE.xml delete mode 100644 .idea/libraries/Maven__org_springframework_data_spring_data_rest_webmvc_2_6_9_RELEASE.xml delete mode 100644 .idea/libraries/Maven__org_springframework_hateoas_spring_hateoas_0_23_0_RELEASE.xml delete mode 100644 .idea/libraries/Maven__org_springframework_plugin_spring_plugin_core_1_2_0_RELEASE.xml delete mode 100644 .idea/libraries/Maven__org_springframework_spring_test_4_3_13_RELEASE.xml delete mode 100644 .idea/libraries/Maven__org_springframework_spring_tx_4_3_13_RELEASE.xml delete mode 100644 src/main/java/ru/cft/task/restClient/RestErrorHandler.java diff --git a/.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_annotations_2_8_0.xml b/.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_annotations_2_9_2.xml similarity index 65% rename from .idea/libraries/Maven__com_fasterxml_jackson_core_jackson_annotations_2_8_0.xml rename to .idea/libraries/Maven__com_fasterxml_jackson_core_jackson_annotations_2_9_2.xml index 49b4ec7..fa4f6eb 100644 --- a/.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_annotations_2_8_0.xml +++ b/.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_annotations_2_9_2.xml @@ -1,13 +1,13 @@ - + - + - + - + \ No newline at end of file diff --git a/.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_core_2_8_10.xml b/.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_core_2_9_2.xml similarity index 65% rename from .idea/libraries/Maven__com_fasterxml_jackson_core_jackson_core_2_8_10.xml rename to .idea/libraries/Maven__com_fasterxml_jackson_core_jackson_core_2_9_2.xml index 5d9d662..f0f5ccb 100644 --- a/.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_core_2_8_10.xml +++ b/.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_core_2_9_2.xml @@ -1,13 +1,13 @@ - + - + - + - + \ No newline at end of file diff --git a/.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_databind_2_8_10.xml b/.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_databind_2_9_2.xml similarity index 62% rename from .idea/libraries/Maven__com_fasterxml_jackson_core_jackson_databind_2_8_10.xml rename to .idea/libraries/Maven__com_fasterxml_jackson_core_jackson_databind_2_9_2.xml index df5cb22..25753a3 100644 --- a/.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_databind_2_8_10.xml +++ b/.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_databind_2_9_2.xml @@ -1,13 +1,13 @@ - + - + - + - + \ No newline at end of file diff --git a/.idea/libraries/Maven__com_fasterxml_jackson_dataformat_jackson_dataformat_json_unknown.xml b/.idea/libraries/Maven__com_fasterxml_jackson_dataformat_jackson_dataformat_json_unknown.xml deleted file mode 100644 index a16e4b7..0000000 --- a/.idea/libraries/Maven__com_fasterxml_jackson_dataformat_jackson_dataformat_json_unknown.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Maven__com_jayway_jsonpath_json_path_2_2_0.xml b/.idea/libraries/Maven__com_jayway_jsonpath_json_path_2_2_0.xml deleted file mode 100644 index 578b079..0000000 --- a/.idea/libraries/Maven__com_jayway_jsonpath_json_path_2_2_0.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Maven__com_vaadin_external_google_android_json_0_0_20131108_vaadin1.xml b/.idea/libraries/Maven__com_vaadin_external_google_android_json_0_0_20131108_vaadin1.xml deleted file mode 100644 index b8581a6..0000000 --- a/.idea/libraries/Maven__com_vaadin_external_google_android_json_0_0_20131108_vaadin1.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Maven__junit_junit_4_12.xml b/.idea/libraries/Maven__junit_junit_4_12.xml deleted file mode 100644 index d411041..0000000 --- a/.idea/libraries/Maven__junit_junit_4_12.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Maven__net_minidev_accessors_smart_1_1.xml b/.idea/libraries/Maven__net_minidev_accessors_smart_1_1.xml deleted file mode 100644 index 88d626e..0000000 --- a/.idea/libraries/Maven__net_minidev_accessors_smart_1_1.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Maven__net_minidev_json_smart_2_2_1.xml b/.idea/libraries/Maven__net_minidev_json_smart_2_2_1.xml deleted file mode 100644 index 6c692c8..0000000 --- a/.idea/libraries/Maven__net_minidev_json_smart_2_2_1.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Maven__org_assertj_assertj_core_2_6_0.xml b/.idea/libraries/Maven__org_assertj_assertj_core_2_6_0.xml deleted file mode 100644 index 58bdc9a..0000000 --- a/.idea/libraries/Maven__org_assertj_assertj_core_2_6_0.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Maven__org_atteo_evo_inflector_1_2_2.xml b/.idea/libraries/Maven__org_atteo_evo_inflector_1_2_2.xml deleted file mode 100644 index 2dde355..0000000 --- a/.idea/libraries/Maven__org_atteo_evo_inflector_1_2_2.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml b/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml deleted file mode 100644 index f58bbc1..0000000 --- a/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Maven__org_hamcrest_hamcrest_library_1_3.xml b/.idea/libraries/Maven__org_hamcrest_hamcrest_library_1_3.xml deleted file mode 100644 index 78dbe45..0000000 --- a/.idea/libraries/Maven__org_hamcrest_hamcrest_library_1_3.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Maven__org_mockito_mockito_core_1_10_19.xml b/.idea/libraries/Maven__org_mockito_mockito_core_1_10_19.xml deleted file mode 100644 index a523703..0000000 --- a/.idea/libraries/Maven__org_mockito_mockito_core_1_10_19.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Maven__org_objenesis_objenesis_2_1.xml b/.idea/libraries/Maven__org_objenesis_objenesis_2_1.xml deleted file mode 100644 index 7ab319b..0000000 --- a/.idea/libraries/Maven__org_objenesis_objenesis_2_1.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Maven__org_ow2_asm_asm_5_0_3.xml b/.idea/libraries/Maven__org_ow2_asm_asm_5_0_3.xml deleted file mode 100644 index da69f6c..0000000 --- a/.idea/libraries/Maven__org_ow2_asm_asm_5_0_3.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Maven__org_skyscreamer_jsonassert_1_4_0.xml b/.idea/libraries/Maven__org_skyscreamer_jsonassert_1_4_0.xml deleted file mode 100644 index f86d2c8..0000000 --- a/.idea/libraries/Maven__org_skyscreamer_jsonassert_1_4_0.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Maven__org_springframework_boot_spring_boot_starter_data_rest_1_5_9_RELEASE.xml b/.idea/libraries/Maven__org_springframework_boot_spring_boot_starter_data_rest_1_5_9_RELEASE.xml deleted file mode 100644 index 33960a7..0000000 --- a/.idea/libraries/Maven__org_springframework_boot_spring_boot_starter_data_rest_1_5_9_RELEASE.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Maven__org_springframework_boot_spring_boot_starter_test_1_5_9_RELEASE.xml b/.idea/libraries/Maven__org_springframework_boot_spring_boot_starter_test_1_5_9_RELEASE.xml deleted file mode 100644 index d7db397..0000000 --- a/.idea/libraries/Maven__org_springframework_boot_spring_boot_starter_test_1_5_9_RELEASE.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Maven__org_springframework_boot_spring_boot_test_1_5_9_RELEASE.xml b/.idea/libraries/Maven__org_springframework_boot_spring_boot_test_1_5_9_RELEASE.xml deleted file mode 100644 index 9312efe..0000000 --- a/.idea/libraries/Maven__org_springframework_boot_spring_boot_test_1_5_9_RELEASE.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Maven__org_springframework_boot_spring_boot_test_autoconfigure_1_5_9_RELEASE.xml b/.idea/libraries/Maven__org_springframework_boot_spring_boot_test_autoconfigure_1_5_9_RELEASE.xml deleted file mode 100644 index 07d7bca..0000000 --- a/.idea/libraries/Maven__org_springframework_boot_spring_boot_test_autoconfigure_1_5_9_RELEASE.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Maven__org_springframework_data_spring_data_commons_1_13_9_RELEASE.xml b/.idea/libraries/Maven__org_springframework_data_spring_data_commons_1_13_9_RELEASE.xml deleted file mode 100644 index f87de9f..0000000 --- a/.idea/libraries/Maven__org_springframework_data_spring_data_commons_1_13_9_RELEASE.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Maven__org_springframework_data_spring_data_rest_core_2_6_9_RELEASE.xml b/.idea/libraries/Maven__org_springframework_data_spring_data_rest_core_2_6_9_RELEASE.xml deleted file mode 100644 index 3816e08..0000000 --- a/.idea/libraries/Maven__org_springframework_data_spring_data_rest_core_2_6_9_RELEASE.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Maven__org_springframework_data_spring_data_rest_webmvc_2_6_9_RELEASE.xml b/.idea/libraries/Maven__org_springframework_data_spring_data_rest_webmvc_2_6_9_RELEASE.xml deleted file mode 100644 index 43e6a71..0000000 --- a/.idea/libraries/Maven__org_springframework_data_spring_data_rest_webmvc_2_6_9_RELEASE.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Maven__org_springframework_hateoas_spring_hateoas_0_23_0_RELEASE.xml b/.idea/libraries/Maven__org_springframework_hateoas_spring_hateoas_0_23_0_RELEASE.xml deleted file mode 100644 index 92e7f9f..0000000 --- a/.idea/libraries/Maven__org_springframework_hateoas_spring_hateoas_0_23_0_RELEASE.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Maven__org_springframework_plugin_spring_plugin_core_1_2_0_RELEASE.xml b/.idea/libraries/Maven__org_springframework_plugin_spring_plugin_core_1_2_0_RELEASE.xml deleted file mode 100644 index fbc0452..0000000 --- a/.idea/libraries/Maven__org_springframework_plugin_spring_plugin_core_1_2_0_RELEASE.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Maven__org_springframework_spring_test_4_3_13_RELEASE.xml b/.idea/libraries/Maven__org_springframework_spring_test_4_3_13_RELEASE.xml deleted file mode 100644 index 0c0fcbf..0000000 --- a/.idea/libraries/Maven__org_springframework_spring_test_4_3_13_RELEASE.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Maven__org_springframework_spring_tx_4_3_13_RELEASE.xml b/.idea/libraries/Maven__org_springframework_spring_tx_4_3_13_RELEASE.xml deleted file mode 100644 index d56e28f..0000000 --- a/.idea/libraries/Maven__org_springframework_spring_tx_4_3_13_RELEASE.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/config.properties b/config.properties index a62d299..c35194c 100644 --- a/config.properties +++ b/config.properties @@ -1,4 +1,4 @@ #Rest server config -#Tue Dec 05 21:32:53 KRAT 2017 +#Wed Dec 06 20:17:24 KRAT 2017 port=8090 url=http\://localhost diff --git a/pom.xml b/pom.xml index 5c95db8..9814496 100644 --- a/pom.xml +++ b/pom.xml @@ -16,6 +16,12 @@ 1.5.9.RELEASE + + UTF-8 + UTF-8 + 1.8 + + @@ -99,34 +105,24 @@ - - org.springframework.boot - spring-boot-starter - - - org.springframework.boot - spring-boot-starter-test - test - org.springframework.boot spring-boot-starter-web - - org.springframework.boot - spring-boot-starter-data-rest - com.fasterxml.jackson.core jackson-core + 2.9.2 com.fasterxml.jackson.core jackson-databind + 2.9.2 - com.fasterxml.jackson.dataformat - jackson-dataformat-json + com.fasterxml.jackson.core + jackson-annotations + 2.9.2 \ No newline at end of file diff --git a/restClient.iml b/restClient.iml index a2c3fce..37efeb8 100644 --- a/restClient.iml +++ b/restClient.iml @@ -11,36 +11,19 @@ + - + - - - - - - - - - - - - - - - - - - @@ -53,19 +36,11 @@ + - - - - - - - - - - - - + + + \ No newline at end of file diff --git a/src/main/java/ru/cft/task/restClient/RestActionsController.java b/src/main/java/ru/cft/task/restClient/RestActionsController.java index d5f2fa2..8caf136 100644 --- a/src/main/java/ru/cft/task/restClient/RestActionsController.java +++ b/src/main/java/ru/cft/task/restClient/RestActionsController.java @@ -1,12 +1,19 @@ package ru.cft.task.restClient; +import com.fasterxml.jackson.databind.ObjectMapper; import javafx.fxml.FXML; import javafx.scene.control.Button; import javafx.scene.control.TextField; import javafx.stage.Stage; +import org.springframework.boot.autoconfigure.security.SecurityProperties; import org.springframework.http.*; +import org.springframework.util.LinkedMultiValueMap; +import org.springframework.util.MultiValueMap; +import org.springframework.web.client.HttpClientErrorException; +import org.springframework.web.client.HttpStatusCodeException; import org.springframework.web.client.RestClientException; import org.springframework.web.client.RestTemplate; +import org.springframework.web.util.UriComponentsBuilder; import java.io.FileInputStream; import java.io.IOException; @@ -55,44 +62,61 @@ public class RestActionsController { } public void createAction() { - EmailRecord emailRecord = new EmailRecord(); - emailRecord.setName("Test"); - emailRecord.setEmail("aaa"); - RestTemplate restTemplate = new RestTemplate(); - HttpEntity request = new HttpEntity<>(emailRecord); + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); + MultiValueMap map = new LinkedMultiValueMap(); + map.add("name", name.getText()); + map.add("email", email.getText()); + + HttpEntity> entity = new HttpEntity>(map, headers); try { - ResponseEntity response = restTemplate.exchange(getRestServerUrl(), HttpMethod.POST, request, EmailRecord.class); - System.out.println(response.getStatusCode()); + ResponseEntity response = restTemplate.exchange(getRestServerUrl(), HttpMethod.POST, entity, EmailRecord.class); if (response.getStatusCode() == HttpStatus.OK) { - EmailRecord er = response.getBody(); - id.setText(String.valueOf(er.getId())); + EmailRecord emailRecord = response.getBody(); + id.setText(String.valueOf(emailRecord.getId())); + } + } catch (HttpStatusCodeException ex) { + try { + ObjectMapper objectMapper = new ObjectMapper(); + ErrorResponse err = objectMapper.readValue(ex.getResponseBodyAsString(), ErrorResponse.class); + Utils.showAlert("error", err.getMessage()); + } catch (IOException e) { + Utils.showAlert("error", e.getMessage()); } - } catch (RestClientException ex) { - Utils.showAlert("error", ex.getMessage()); } } public void readAction() { - HttpHeaders headers = new HttpHeaders(); - headers.add("Accept", MediaType.APPLICATION_JSON_VALUE); - headers.setContentType(MediaType.APPLICATION_JSON); - headers.set("id", id.getText()); - headers.set("name", name.getText()); - headers.set("email", email.getText()); - RestTemplate restTemplate = new RestTemplate(); - HttpEntity entity = new HttpEntity<>(headers); + HttpHeaders headers = new HttpHeaders(); + headers.set("Accept", MediaType.APPLICATION_JSON_VALUE); + UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(getRestServerUrl()); + if (!id.getText().isEmpty()) { + builder.queryParam("id", id.getText()); + } else if (!email.getText().isEmpty()) { + builder.queryParam("email", email.getText()); + } else { + builder.queryParam("name", name.getText()); + } + + HttpEntity entity = new HttpEntity<>(headers); try { - ResponseEntity result = restTemplate.exchange(getRestServerUrl(), HttpMethod.GET, entity, EmailRecord.class); - if (result.getStatusCode() == HttpStatus.OK) { - EmailRecord emailRecord = result.getBody(); + ResponseEntity response = restTemplate.exchange(builder.build().encode().toUri(), HttpMethod.GET, entity, EmailRecord.class); + if (response.getStatusCode() == HttpStatus.OK) { + EmailRecord emailRecord = response.getBody(); id.setText(String.valueOf(emailRecord.getId())); name.setText(emailRecord.getName()); email.setText(emailRecord.getEmail()); } - } catch (RestClientException ex) { - Utils.showAlert("error", ex.getMessage()); + } catch (HttpStatusCodeException ex) { + try { + ObjectMapper objectMapper = new ObjectMapper(); + ErrorResponse err = objectMapper.readValue(ex.getResponseBodyAsString(), ErrorResponse.class); + Utils.showAlert("error", err.getMessage()); + } catch (IOException e) { + Utils.showAlert("error", e.getMessage()); + } } } diff --git a/src/main/java/ru/cft/task/restClient/RestErrorHandler.java b/src/main/java/ru/cft/task/restClient/RestErrorHandler.java deleted file mode 100644 index 628ea74..0000000 --- a/src/main/java/ru/cft/task/restClient/RestErrorHandler.java +++ /dev/null @@ -1,12 +0,0 @@ -package ru.cft.task.restClient; - -import org.springframework.http.client.ClientHttpResponse; -import org.springframework.web.client.DefaultResponseErrorHandler; - -import java.io.IOException; - -public class RestErrorHandler extends DefaultResponseErrorHandler { - public void handleError(ClientHttpResponse response) throws IOException { - Utils.showAlert("error", response.getStatusText()); - } -}