diff --git a/libraries/bot-ai-luis-v3/pom.xml b/libraries/bot-ai-luis-v3/pom.xml index 6ecfe0ba0..943354b84 100644 --- a/libraries/bot-ai-luis-v3/pom.xml +++ b/libraries/bot-ai-luis-v3/pom.xml @@ -86,6 +86,18 @@ json 20190722 + + org.apache.httpcomponents + httpcore + 4.4.13 + compile + + + org.apache.httpcomponents + httpclient + 4.5.13 + compile + diff --git a/libraries/bot-ai-luis-v3/src/main/java/com/microsoft/bot/ai/luis/LuisRecognizerOptionsV3.java b/libraries/bot-ai-luis-v3/src/main/java/com/microsoft/bot/ai/luis/LuisRecognizerOptionsV3.java index 68becc62d..bf520db6c 100644 --- a/libraries/bot-ai-luis-v3/src/main/java/com/microsoft/bot/ai/luis/LuisRecognizerOptionsV3.java +++ b/libraries/bot-ai-luis-v3/src/main/java/com/microsoft/bot/ai/luis/LuisRecognizerOptionsV3.java @@ -452,7 +452,7 @@ private Request buildRequest(RequestBody body) { private RequestBody buildRequestBody(String utterance) throws JsonProcessingException { - ObjectMapper mapper = new ObjectMapper(); + ObjectMapper mapper = new ObjectMapper().findAndRegisterModules(); ObjectNode content = JsonNodeFactory.instance.objectNode().put("query", utterance); ObjectNode queryOptions = JsonNodeFactory.instance.objectNode().put("preferExternalEntities", preferExternalEntities); @@ -482,7 +482,7 @@ private CompletableFuture recognizeInternal(TurnContext turnCo RecognizerResult recognizerResult; JsonNode luisResponse = null; - ObjectMapper mapper = new ObjectMapper(); + ObjectMapper mapper = new ObjectMapper().findAndRegisterModules(); if (utterance == null || utterance.isEmpty()) { recognizerResult = new RecognizerResult() { @@ -691,7 +691,7 @@ private CompletableFuture sendTraceActivity( JsonNode luisResponse, TurnContext turnContext ) { - ObjectMapper mapper = new ObjectMapper(); + ObjectMapper mapper = new ObjectMapper().findAndRegisterModules(); try { ObjectNode traceInfo = JsonNodeFactory.instance.objectNode(); traceInfo diff --git a/libraries/bot-ai-luis-v3/src/test/java/com/microsoft/bot/ai/luis/LuisRecognizerOptionsV3Tests.java b/libraries/bot-ai-luis-v3/src/test/java/com/microsoft/bot/ai/luis/LuisRecognizerOptionsV3Tests.java index 60289649e..6e4c2cf04 100644 --- a/libraries/bot-ai-luis-v3/src/test/java/com/microsoft/bot/ai/luis/LuisRecognizerOptionsV3Tests.java +++ b/libraries/bot-ai-luis-v3/src/test/java/com/microsoft/bot/ai/luis/LuisRecognizerOptionsV3Tests.java @@ -99,7 +99,7 @@ private void shouldParseLuisResponsesCorrectly_TurnContextPassed(String fileName String content = readFileContent("/src/test/java/com/microsoft/bot/ai/luis/testdata/" + fileName); //Extract V3 response - ObjectMapper mapper = new ObjectMapper(); + ObjectMapper mapper = new ObjectMapper().findAndRegisterModules(); JsonNode testData = mapper.readTree(content); JsonNode v3SettingsAndResponse = testData.get("v3"); JsonNode v3Response = v3SettingsAndResponse.get("response"); @@ -176,7 +176,7 @@ public void shouldBuildExternalEntities_DialogContextPassed_ExternalRecognizer() String content = readFileContent("/src/test/java/com/microsoft/bot/ai/luis/testdata/ExternalRecognizer.json"); //Extract V3 response - ObjectMapper mapper = new ObjectMapper(); + ObjectMapper mapper = new ObjectMapper().findAndRegisterModules(); JsonNode testData = mapper.readTree(content); JsonNode v3SettingsAndResponse = testData.get("v3"); JsonNode v3Response = v3SettingsAndResponse.get("response"); @@ -308,7 +308,7 @@ private String buildUrl(StringBuilder pathToMock, JsonNode testSettings) { } private HttpUrl initializeMockServer(MockWebServer mockWebServer, JsonNode v3Response, String url) throws IOException { - ObjectMapper mapper = new ObjectMapper(); + ObjectMapper mapper = new ObjectMapper().findAndRegisterModules(); String mockResponse = mapper.writeValueAsString(v3Response); mockWebServer.enqueue(new MockResponse() .addHeader("Content-Type", "application/json; charset=utf-8") @@ -320,7 +320,7 @@ private HttpUrl initializeMockServer(MockWebServer mockWebServer, JsonNode v3Res } private LuisRecognizerOptionsV3 buildTestRecognizer (String endpoint, JsonNode testSettings) throws IOException { - ObjectMapper mapper = new ObjectMapper(); + ObjectMapper mapper = new ObjectMapper().findAndRegisterModules(); ObjectReader readerDynamicList = mapper.readerFor(new TypeReference>() {}); ObjectReader readerExternalentities = mapper.readerFor(new TypeReference>() {}); return new LuisRecognizerOptionsV3( diff --git a/libraries/bot-ai-luis-v3/src/test/java/com/microsoft/bot/ai/luis/LuisRecognizerTests.java b/libraries/bot-ai-luis-v3/src/test/java/com/microsoft/bot/ai/luis/LuisRecognizerTests.java index 307390cf8..6d07c20fc 100644 --- a/libraries/bot-ai-luis-v3/src/test/java/com/microsoft/bot/ai/luis/LuisRecognizerTests.java +++ b/libraries/bot-ai-luis-v3/src/test/java/com/microsoft/bot/ai/luis/LuisRecognizerTests.java @@ -142,7 +142,7 @@ public void recognizerResult() { RecognizerResult actual = null; try { actual = recognizer.recognize(turnContext).get(); - ObjectMapper mapper = new ObjectMapper(); + ObjectMapper mapper = new ObjectMapper().findAndRegisterModules(); assertEquals(mapper.writeValueAsString(expected), mapper.writeValueAsString(actual)); } catch (InterruptedException | ExecutionException | JsonProcessingException e) { e.printStackTrace(); @@ -197,7 +197,7 @@ public void recognizerResult_nullTelemetryClient() { RecognizerResult actual = null; try { actual = recognizer.recognize(turnContext).get(); - ObjectMapper mapper = new ObjectMapper(); + ObjectMapper mapper = new ObjectMapper().findAndRegisterModules(); assertEquals(mapper.writeValueAsString(expected), mapper.writeValueAsString(actual)); } catch (InterruptedException | ExecutionException | JsonProcessingException e) { e.printStackTrace(); @@ -256,7 +256,7 @@ public void recognizerResultDialogContext() { LuisRecognizer recognizer = new LuisRecognizer(options); try { actual = recognizer.recognize(dialogContext, turnContext.getActivity()).get(); - ObjectMapper mapper = new ObjectMapper(); + ObjectMapper mapper = new ObjectMapper().findAndRegisterModules(); assertEquals(mapper.writeValueAsString(expected), mapper.writeValueAsString(actual)); } catch (InterruptedException | ExecutionException | JsonProcessingException e) { e.printStackTrace(); diff --git a/libraries/bot-ai-qna/src/main/java/com/microsoft/bot/ai/qna/QnAMakerRecognizer.java b/libraries/bot-ai-qna/src/main/java/com/microsoft/bot/ai/qna/QnAMakerRecognizer.java index 6c1ddc55c..1867d8b11 100644 --- a/libraries/bot-ai-qna/src/main/java/com/microsoft/bot/ai/qna/QnAMakerRecognizer.java +++ b/libraries/bot-ai-qna/src/main/java/com/microsoft/bot/ai/qna/QnAMakerRecognizer.java @@ -417,7 +417,7 @@ public CompletableFuture recognize( } }); } - ObjectMapper mapper = new ObjectMapper(); + ObjectMapper mapper = new ObjectMapper().findAndRegisterModules(); ObjectNode entitiesNode = mapper.createObjectNode(); List answerArray = new ArrayList(); answerArray.add(topAnswer.getAnswer()); diff --git a/libraries/bot-ai-qna/src/main/java/com/microsoft/bot/ai/qna/utils/HttpRequestUtils.java b/libraries/bot-ai-qna/src/main/java/com/microsoft/bot/ai/qna/utils/HttpRequestUtils.java index 5e60838c4..b76a6d8cd 100644 --- a/libraries/bot-ai-qna/src/main/java/com/microsoft/bot/ai/qna/utils/HttpRequestUtils.java +++ b/libraries/bot-ai-qna/src/main/java/com/microsoft/bot/ai/qna/utils/HttpRequestUtils.java @@ -53,7 +53,7 @@ public CompletableFuture executeHttpRequest( return Async.completeExceptionally(new IllegalArgumentException("endpoint")); } - ObjectMapper mapper = new ObjectMapper(); + ObjectMapper mapper = new ObjectMapper().findAndRegisterModules(); String endpointKey = endpoint.getEndpointKey(); Response response; JsonNode qnaResponse = null; diff --git a/libraries/bot-ai-qna/src/test/java/com/microsoft/bot/ai/qna/QnAMakerRecognizerTests.java b/libraries/bot-ai-qna/src/test/java/com/microsoft/bot/ai/qna/QnAMakerRecognizerTests.java index 7443b01f2..4e03a4b1d 100644 --- a/libraries/bot-ai-qna/src/test/java/com/microsoft/bot/ai/qna/QnAMakerRecognizerTests.java +++ b/libraries/bot-ai-qna/src/test/java/com/microsoft/bot/ai/qna/QnAMakerRecognizerTests.java @@ -72,7 +72,7 @@ public void noAnswer() { MockWebServer mockWebServer = new MockWebServer(); try { String content = readFileContent("QnaMaker_ReturnsNoAnswer.json"); - ObjectMapper mapper = new ObjectMapper(); + ObjectMapper mapper = new ObjectMapper().findAndRegisterModules(); JsonNode response = mapper.readTree(content); // Set mock response in MockWebServer String url = "/qnamaker/knowledgebases/"; @@ -114,7 +114,7 @@ public void returnAnswers() { MockWebServer mockWebServer = new MockWebServer(); try { String content = readFileContent("QnaMaker_ReturnsAnswer.json"); - ObjectMapper mapper = new ObjectMapper(); + ObjectMapper mapper = new ObjectMapper().findAndRegisterModules(); JsonNode response = mapper.readTree(content); // Set mock response in MockWebServer String url = "/qnamaker/knowledgebases/"; @@ -154,7 +154,7 @@ public void topNAnswers() { MockWebServer mockWebServer = new MockWebServer(); try { String content = readFileContent("QnaMaker_TopNAnswer.json"); - ObjectMapper mapper = new ObjectMapper(); + ObjectMapper mapper = new ObjectMapper().findAndRegisterModules(); JsonNode response = mapper.readTree(content); // Set mock response in MockWebServer String url = "/qnamaker/knowledgebases/"; @@ -194,7 +194,7 @@ public void returnAnswersWithIntents() { MockWebServer mockWebServer = new MockWebServer(); try { String content = readFileContent("QnaMaker_ReturnsAnswerWithIntent.json"); - ObjectMapper mapper = new ObjectMapper(); + ObjectMapper mapper = new ObjectMapper().findAndRegisterModules(); JsonNode response = mapper.readTree(content); // Set mock response in MockWebServer String url = "/qnamaker/knowledgebases/"; @@ -237,7 +237,7 @@ private String readFileContent (String fileName) throws IOException { } private HttpUrl initializeMockServer(MockWebServer mockWebServer, JsonNode response, String url) throws IOException { - ObjectMapper mapper = new ObjectMapper(); + ObjectMapper mapper = new ObjectMapper().findAndRegisterModules(); String mockResponse = mapper.writeValueAsString(response); mockWebServer.enqueue(new MockResponse() .addHeader("Content-Type", "application/json; charset=utf-8") diff --git a/libraries/bot-ai-qna/src/test/java/com/microsoft/bot/ai/qna/QnAMakerTests.java b/libraries/bot-ai-qna/src/test/java/com/microsoft/bot/ai/qna/QnAMakerTests.java index 253908994..133c4db45 100644 --- a/libraries/bot-ai-qna/src/test/java/com/microsoft/bot/ai/qna/QnAMakerTests.java +++ b/libraries/bot-ai-qna/src/test/java/com/microsoft/bot/ai/qna/QnAMakerTests.java @@ -368,7 +368,7 @@ public void qnaMakerLowScoreVariation() { MockWebServer mockWebServer = new MockWebServer(); try { String content = readFileContent("QnaMaker_TopNAnswer.json"); - ObjectMapper mapper = new ObjectMapper(); + ObjectMapper mapper = new ObjectMapper().findAndRegisterModules(); JsonNode response = mapper.readTree(content); String url = this.getRequestUrl(); String endpoint = ""; @@ -421,7 +421,7 @@ public void qnaMakerLowScoreVariation() { @Test public void qnaMakerCallTrain() { MockWebServer mockWebServer = new MockWebServer(); - ObjectMapper objectMapper = new ObjectMapper(); + ObjectMapper objectMapper = new ObjectMapper().findAndRegisterModules(); String url = this.getTrainRequestUrl(); String endpoint = ""; try { @@ -499,7 +499,7 @@ public void qnaMakerReturnsAnswerWithFiltering() { MockWebServer mockWebServer = new MockWebServer(); try { String content = readFileContent("QnaMaker_UsesStrictFilters_ToReturnAnswer.json"); - ObjectMapper mapper = new ObjectMapper(); + ObjectMapper mapper = new ObjectMapper().findAndRegisterModules(); JsonNode response = mapper.readTree(content); String url = this.getRequestUrl(); String endpoint = ""; @@ -526,7 +526,7 @@ public void qnaMakerReturnsAnswerWithFiltering() { } }; QnAMaker qna = new QnAMaker(qnaMakerEndpoint, qnaMakerOptions); - ObjectMapper objectMapper = new ObjectMapper(); + ObjectMapper objectMapper = new ObjectMapper().findAndRegisterModules(); QueryResult[] results = qna.getAnswers(getContext("how do I clean the stove?"), qnaMakerOptions).join(); Assert.assertNotNull(results); @@ -563,7 +563,7 @@ public void qnaMakerSetScoreThresholdWhenThresholdIsZero() { MockWebServer mockWebServer = new MockWebServer(); try { String content = readFileContent("QnaMaker_ReturnsAnswer.json"); - ObjectMapper mapper = new ObjectMapper(); + ObjectMapper mapper = new ObjectMapper().findAndRegisterModules(); JsonNode response = mapper.readTree(content); String url = this.getRequestUrl(); String endpoint = ""; @@ -608,7 +608,7 @@ public void qnaMakerTestThreshold() { MockWebServer mockWebServer = new MockWebServer(); try { String content = readFileContent("QnaMaker_TestThreshold.json"); - ObjectMapper mapper = new ObjectMapper(); + ObjectMapper mapper = new ObjectMapper().findAndRegisterModules(); JsonNode response = mapper.readTree(content); String url = this.getRequestUrl(); String endpoint = ""; @@ -686,7 +686,7 @@ public void qnaMakerReturnsAnswerWithContext() { MockWebServer mockWebServer = new MockWebServer(); try { String content = readFileContent("QnaMaker_ReturnsAnswerWithContext.json"); - ObjectMapper mapper = new ObjectMapper(); + ObjectMapper mapper = new ObjectMapper().findAndRegisterModules(); JsonNode response = mapper.readTree(content); String url = this.getRequestUrl(); String endpoint = ""; @@ -737,7 +737,7 @@ public void qnaMakerReturnAnswersWithoutContext() { MockWebServer mockWebServer = new MockWebServer(); try { String content = readFileContent("QnaMaker_ReturnsAnswerWithoutContext.json"); - ObjectMapper mapper = new ObjectMapper(); + ObjectMapper mapper = new ObjectMapper().findAndRegisterModules(); JsonNode response = mapper.readTree(content); String url = this.getRequestUrl(); String endpoint = ""; @@ -780,7 +780,7 @@ public void qnaMakerReturnsHighScoreWhenIdPassed() { MockWebServer mockWebServer = new MockWebServer(); try { String content = readFileContent("QnaMaker_ReturnsAnswerWithContext.json"); - ObjectMapper mapper = new ObjectMapper(); + ObjectMapper mapper = new ObjectMapper().findAndRegisterModules(); JsonNode response = mapper.readTree(content); String url = this.getRequestUrl(); String endpoint = ""; @@ -904,7 +904,7 @@ public void qnaMakerV2LegacyEndpointShouldThrow() { MockWebServer mockWebServer = new MockWebServer(); try { String content = readFileContent("QnaMaker_LegacyEndpointAnswer.json"); - ObjectMapper mapper = new ObjectMapper(); + ObjectMapper mapper = new ObjectMapper().findAndRegisterModules(); JsonNode response = mapper.readTree(content); String url = this.getV2LegacyRequestUrl(); String endpoint = ""; @@ -938,7 +938,7 @@ public void qnaMakerV3LeagacyEndpointShouldThrow() { MockWebServer mockWebServer = new MockWebServer(); try { String content = readFileContent("QnaMaker_LegacyEndpointAnswer.json"); - ObjectMapper mapper = new ObjectMapper(); + ObjectMapper mapper = new ObjectMapper().findAndRegisterModules(); JsonNode response = mapper.readTree(content); String url = this.getV3LegacyRequestUrl(); String endpoint = ""; @@ -972,7 +972,7 @@ public void qnaMakerReturnsAnswerWithMetadataBoost() { MockWebServer mockWebServer = new MockWebServer(); try { String content = readFileContent("QnaMaker_ReturnsAnswersWithMetadataBoost.json"); - ObjectMapper mapper = new ObjectMapper(); + ObjectMapper mapper = new ObjectMapper().findAndRegisterModules(); JsonNode response = mapper.readTree(content); String url = this.getRequestUrl(); String endpoint = ""; @@ -1015,7 +1015,7 @@ public void qnaMakerTestThresholdInQueryOption() { MockWebServer mockWebServer = new MockWebServer(); try { String content = readFileContent("QnaMaker_ReturnsAnswer_GivenScoreThresholdQueryOption.json"); - ObjectMapper mapper = new ObjectMapper(); + ObjectMapper mapper = new ObjectMapper().findAndRegisterModules(); JsonNode response = mapper.readTree(content); String url = this.getRequestUrl(); String endpoint = ""; @@ -1039,7 +1039,7 @@ public void qnaMakerTestThresholdInQueryOption() { QnAMaker qna = new QnAMaker(qnAMakerEndpoint, queryOptionsWithScoreThreshold); - ObjectMapper objectMapper = new ObjectMapper(); + ObjectMapper objectMapper = new ObjectMapper().findAndRegisterModules(); QueryResult[] results = qna.getAnswers(getContext("What happens when you hug a porcupine?"), queryOptionsWithScoreThreshold).join(); RecordedRequest request = mockWebServer.takeRequest(); @@ -1093,7 +1093,7 @@ public void qnaMakerIsTestTrue() { MockWebServer mockWebServer = new MockWebServer(); try { String content = readFileContent("QnaMaker_IsTest_True.json"); - ObjectMapper mapper = new ObjectMapper(); + ObjectMapper mapper = new ObjectMapper().findAndRegisterModules(); JsonNode response = mapper.readTree(content); String url = this.getRequestUrl(); String endpoint = ""; @@ -1136,7 +1136,7 @@ public void qnaMakerRankerTypeQuestionOnly() { MockWebServer mockWebServer = new MockWebServer(); try { String content = readFileContent("QnaMaker_RankerType_QuestionOnly.json"); - ObjectMapper mapper = new ObjectMapper(); + ObjectMapper mapper = new ObjectMapper().findAndRegisterModules(); JsonNode response = mapper.readTree(content); String url = this.getRequestUrl(); String endpoint = ""; @@ -1181,7 +1181,7 @@ public void qnaMakerTestOptionsHydration() { String url = this.getRequestUrl(); String endpoint = ""; String content = readFileContent("QnaMaker_ReturnsAnswer.json"); - ObjectMapper mapper = new ObjectMapper(); + ObjectMapper mapper = new ObjectMapper().findAndRegisterModules(); JsonNode response = mapper.readTree(content); if (this.mockQnAResponse) { endpoint = String.format("%s:%s", hostname, initializeMockServer(mockWebServer, response, url).port()); @@ -1248,7 +1248,7 @@ public void qnaMakerTestOptionsHydration() { // Ensure that options from previous requests do not bleed over to the next, // And that the options set in the constructor are not overwritten improperly by options passed into .GetAnswersAsync() CapturedRequest[] requestContent = new CapturedRequest[6]; - ObjectMapper objectMapper = new ObjectMapper(); + ObjectMapper objectMapper = new ObjectMapper().findAndRegisterModules(); RecordedRequest request; qna.getAnswers(context, noFiltersOptions).join(); @@ -1315,7 +1315,7 @@ public void qnaMakerStrictFiltersCompoundOperationType() { MockWebServer mockWebServer = new MockWebServer(); try { String content = readFileContent("QnaMaker_ReturnsAnswer.json"); - ObjectMapper mapper = new ObjectMapper(); + ObjectMapper mapper = new ObjectMapper().findAndRegisterModules(); JsonNode response = mapper.readTree(content); String url = this.getRequestUrl(); String endpoint = ""; @@ -1354,7 +1354,7 @@ public void qnaMakerStrictFiltersCompoundOperationType() { QnAMaker qna = new QnAMaker(qnAMakerEndpoint, oneFilteredOption); TurnContext context = getContext("up"); - ObjectMapper objectMapper = new ObjectMapper(); + ObjectMapper objectMapper = new ObjectMapper().findAndRegisterModules(); QueryResult[] noFilterResults1 = qna.getAnswers(context, oneFilteredOption).join(); RecordedRequest request = mockWebServer.takeRequest(); @@ -1378,7 +1378,7 @@ public void telemetryNullTelemetryClient() { MockWebServer mockWebServer = new MockWebServer(); try { String content = readFileContent("QnaMaker_ReturnsAnswer.json"); - ObjectMapper mapper = new ObjectMapper(); + ObjectMapper mapper = new ObjectMapper().findAndRegisterModules(); JsonNode response = mapper.readTree(content); String url = this.getRequestUrl(); String endpoint = ""; @@ -1426,7 +1426,7 @@ public void telemetryReturnsAnswer() { MockWebServer mockWebServer = new MockWebServer(); try { String content = readFileContent("QnaMaker_ReturnsAnswer.json"); - ObjectMapper mapper = new ObjectMapper(); + ObjectMapper mapper = new ObjectMapper().findAndRegisterModules(); JsonNode response = mapper.readTree(content); String url = this.getRequestUrl(); String endpoint = ""; @@ -1494,7 +1494,7 @@ public void telemetryReturnsAnswerWhenNoAnswerFoundInKB() { MockWebServer mockWebServer = new MockWebServer(); try { String content = readFileContent("QnaMaker_ReturnsAnswer_WhenNoAnswerFoundInKb.json"); - ObjectMapper mapper = new ObjectMapper(); + ObjectMapper mapper = new ObjectMapper().findAndRegisterModules(); JsonNode response = mapper.readTree(content); String url = this.getRequestUrl(); String endpoint = ""; @@ -1562,7 +1562,7 @@ public void telemetryPii() { MockWebServer mockWebServer = new MockWebServer(); try { String content = readFileContent("QnaMaker_ReturnsAnswer.json"); - ObjectMapper mapper = new ObjectMapper(); + ObjectMapper mapper = new ObjectMapper().findAndRegisterModules(); JsonNode response = mapper.readTree(content); String url = this.getRequestUrl(); String endpoint = ""; @@ -1632,7 +1632,7 @@ public void telemetryOverride() { MockWebServer mockWebServer = new MockWebServer(); try { String content = readFileContent("QnaMaker_ReturnsAnswer.json"); - ObjectMapper mapper = new ObjectMapper(); + ObjectMapper mapper = new ObjectMapper().findAndRegisterModules(); JsonNode response = mapper.readTree(content); String url = this.getRequestUrl(); String endpoint = ""; @@ -1706,7 +1706,7 @@ public void telemetryAdditionalPropsMetrics() { MockWebServer mockWebServer = new MockWebServer(); try { String content = readFileContent("QnaMaker_ReturnsAnswer.json"); - ObjectMapper mapper = new ObjectMapper(); + ObjectMapper mapper = new ObjectMapper().findAndRegisterModules(); JsonNode response = mapper.readTree(content); String url = this.getRequestUrl(); String endpoint = ""; @@ -1793,7 +1793,7 @@ public void telemetryAdditionalPropsOverride() { MockWebServer mockWebServer = new MockWebServer(); try { String content = readFileContent("QnaMaker_ReturnsAnswer.json"); - ObjectMapper mapper = new ObjectMapper(); + ObjectMapper mapper = new ObjectMapper().findAndRegisterModules(); JsonNode response = mapper.readTree(content); String url = this.getRequestUrl(); String endpoint = ""; @@ -1876,7 +1876,7 @@ public void telemetryFillPropsOverride() { MockWebServer mockWebServer = new MockWebServer(); try { String content = readFileContent("QnaMaker_ReturnsAnswer.json"); - ObjectMapper mapper = new ObjectMapper(); + ObjectMapper mapper = new ObjectMapper().findAndRegisterModules(); JsonNode response = mapper.readTree(content); String url = this.getRequestUrl(); String endpoint = ""; @@ -2030,7 +2030,7 @@ public CompletableFuture resumeDialog(DialogContext dc, Dialog private QnAMaker qnaReturnsAnswer(MockWebServer mockWebServer) { try { String content = readFileContent("QnaMaker_ReturnsAnswer.json"); - ObjectMapper mapper = new ObjectMapper(); + ObjectMapper mapper = new ObjectMapper().findAndRegisterModules(); JsonNode response = mapper.readTree(content); String url = this.getRequestUrl(); String endpoint = ""; @@ -2065,7 +2065,7 @@ private String readFileContent (String fileName) throws IOException { } private HttpUrl initializeMockServer(MockWebServer mockWebServer, JsonNode response, String url) throws IOException { - ObjectMapper mapper = new ObjectMapper(); + ObjectMapper mapper = new ObjectMapper().findAndRegisterModules(); String mockResponse = mapper.writeValueAsString(response); mockWebServer.enqueue(new MockResponse() .addHeader("Content-Type", "application/json; charset=utf-8") @@ -2080,7 +2080,7 @@ private HttpUrl initializeMockServer(MockWebServer mockWebServer, JsonNode respo } private void enqueueResponse(MockWebServer mockWebServer, JsonNode response) throws JsonProcessingException { - ObjectMapper mapper = new ObjectMapper(); + ObjectMapper mapper = new ObjectMapper().findAndRegisterModules(); String mockResponse = mapper.writeValueAsString(response); mockWebServer.enqueue(new MockResponse() .addHeader("Content-Type", "application/json; charset=utf-8") diff --git a/libraries/bot-builder/src/main/java/com/microsoft/bot/builder/BotFrameworkAdapter.java b/libraries/bot-builder/src/main/java/com/microsoft/bot/builder/BotFrameworkAdapter.java index c3d366c2e..60e0e8f44 100644 --- a/libraries/bot-builder/src/main/java/com/microsoft/bot/builder/BotFrameworkAdapter.java +++ b/libraries/bot-builder/src/main/java/com/microsoft/bot/builder/BotFrameworkAdapter.java @@ -1302,7 +1302,8 @@ public CompletableFuture onTurn(TurnContext turnContext, NextDelegate next && turnContext.getActivity().getConversation() != null && StringUtils.isEmpty(turnContext.getActivity().getConversation().getTenantId())) { - JsonNode teamsChannelData = new ObjectMapper().valueToTree(turnContext.getActivity().getChannelData()); + ObjectMapper mapper = new ObjectMapper().findAndRegisterModules(); + JsonNode teamsChannelData = mapper.valueToTree(turnContext.getActivity().getChannelData()); if (teamsChannelData != null && teamsChannelData.has("tenant") && teamsChannelData.get("tenant").has("id")) { diff --git a/libraries/bot-builder/src/main/java/com/microsoft/bot/builder/BotState.java b/libraries/bot-builder/src/main/java/com/microsoft/bot/builder/BotState.java index 5c56dfbff..e3f7fe8a7 100644 --- a/libraries/bot-builder/src/main/java/com/microsoft/bot/builder/BotState.java +++ b/libraries/bot-builder/src/main/java/com/microsoft/bot/builder/BotState.java @@ -38,6 +38,8 @@ public abstract class BotState implements PropertyManager { */ private Storage storage; + private ObjectMapper mapper = new ObjectMapper().findAndRegisterModules(); + /** * Initializes a new instance of the BotState class. * @@ -221,7 +223,7 @@ public JsonNode get(TurnContext turnContext) { String stateKey = getClass().getSimpleName(); CachedBotState cachedState = turnContext.getTurnState().get(stateKey); - return new ObjectMapper().valueToTree(cachedState.state); + return mapper.valueToTree(cachedState.state); } /** @@ -355,7 +357,7 @@ public static class CachedBotState { /** * Object-JsonNode converter. */ - private ObjectMapper mapper = new ObjectMapper(); + private ObjectMapper mapper = new ObjectMapper().findAndRegisterModules(); /** * Construct with empty state. diff --git a/libraries/bot-builder/src/main/java/com/microsoft/bot/builder/teams/TeamsActivityHandler.java b/libraries/bot-builder/src/main/java/com/microsoft/bot/builder/teams/TeamsActivityHandler.java index 4831fffe6..3d51319f4 100644 --- a/libraries/bot-builder/src/main/java/com/microsoft/bot/builder/teams/TeamsActivityHandler.java +++ b/libraries/bot-builder/src/main/java/com/microsoft/bot/builder/teams/TeamsActivityHandler.java @@ -663,7 +663,7 @@ protected CompletableFuture onTeamsMembersAddedDispatch( TeamInfo teamInfo, TurnContext turnContext ) { - ObjectMapper mapper = new ObjectMapper(); + ObjectMapper mapper = new ObjectMapper().findAndRegisterModules(); mapper.findAndRegisterModules(); List teamsMembersAdded = new ArrayList<>(); @@ -731,7 +731,7 @@ protected CompletableFuture onTeamsMembersRemovedDispatch( TeamInfo teamInfo, TurnContext turnContext ) { - ObjectMapper mapper = new ObjectMapper(); + ObjectMapper mapper = new ObjectMapper().findAndRegisterModules(); mapper.findAndRegisterModules(); List teamsMembersRemoved = new ArrayList<>(); diff --git a/libraries/bot-connector/pom.xml b/libraries/bot-connector/pom.xml index f892898cd..38999fc5a 100644 --- a/libraries/bot-connector/pom.xml +++ b/libraries/bot-connector/pom.xml @@ -58,7 +58,6 @@ com.google.guava guava - 30.1-jre @@ -93,7 +92,7 @@ commons-codec commons-codec - 1.11 + 1.15 @@ -188,4 +187,30 @@ + + + + + org.apache.maven.plugins + maven-pmd-plugin + ${pmd.version} + + + org.apache.maven.plugins + maven-checkstyle-plugin + ${checkstyle.version} + + com/microsoft/bot/restclient/** + + + + + checkstyle + + + + + + + diff --git a/libraries/bot-connector/src/main/java/com/microsoft/bot/restclient/interceptors/LoggingInterceptor.java b/libraries/bot-connector/src/main/java/com/microsoft/bot/restclient/interceptors/LoggingInterceptor.java index 7b11988df..684254f80 100644 --- a/libraries/bot-connector/src/main/java/com/microsoft/bot/restclient/interceptors/LoggingInterceptor.java +++ b/libraries/bot-connector/src/main/java/com/microsoft/bot/restclient/interceptors/LoggingInterceptor.java @@ -34,7 +34,7 @@ public class LoggingInterceptor implements Interceptor { private static final String LOGGING_HEADER = "x-ms-logging-context"; private static final String BODY_LOGGING = "x-ms-body-logging"; - private static final ObjectMapper MAPPER = new ObjectMapper(); + private static final ObjectMapper MAPPER = new ObjectMapper().findAndRegisterModules(); private LogLevel logLevel; /** diff --git a/libraries/bot-dialogs/pom.xml b/libraries/bot-dialogs/pom.xml index 329cf00b5..fd9f09e51 100644 --- a/libraries/bot-dialogs/pom.xml +++ b/libraries/bot-dialogs/pom.xml @@ -56,13 +56,16 @@ com.microsoft.azure azure-documentdb - 2.6.0 + 2.6.1 + test com.azure azure-storage-blob - 12.8.0 + 12.10.0 + test + com.microsoft.bot bot-integration-core @@ -79,10 +82,10 @@ test-jar test + com.google.guava guava - 24.1.1-jre org.javatuples @@ -92,12 +95,11 @@ org.apache.commons commons-lang3 - 3.7 org.yaml snakeyaml - 1.20 + 1.27 @@ -149,4 +151,30 @@ + + + + + org.apache.maven.plugins + maven-pmd-plugin + ${pmd.version} + + + org.apache.maven.plugins + maven-checkstyle-plugin + ${checkstyle.version} + + com/microsoft/recognizers/** + + + + + checkstyle + + + + + + + diff --git a/libraries/bot-dialogs/src/main/java/com/microsoft/bot/dialogs/DialogSet.java b/libraries/bot-dialogs/src/main/java/com/microsoft/bot/dialogs/DialogSet.java index c5cbb4b61..63fdcd743 100644 --- a/libraries/bot-dialogs/src/main/java/com/microsoft/bot/dialogs/DialogSet.java +++ b/libraries/bot-dialogs/src/main/java/com/microsoft/bot/dialogs/DialogSet.java @@ -13,16 +13,16 @@ import java.nio.charset.StandardCharsets; import java.util.Collection; +import java.util.HashMap; import java.util.Map; import java.util.concurrent.CompletableFuture; -import org.apache.commons.collections4.map.HashedMap; import org.apache.commons.lang3.StringUtils; /** * A collection of Dialog objects that can all call each other. */ public class DialogSet { - private Map dialogs = new HashedMap<>(); + private Map dialogs = new HashMap<>(); private StatePropertyAccessor dialogState; @JsonIgnore private BotTelemetryClient telemetryClient; diff --git a/libraries/bot-dialogs/src/main/java/com/microsoft/bot/dialogs/ObjectPath.java b/libraries/bot-dialogs/src/main/java/com/microsoft/bot/dialogs/ObjectPath.java index 61e3c31e3..ce3c6e002 100644 --- a/libraries/bot-dialogs/src/main/java/com/microsoft/bot/dialogs/ObjectPath.java +++ b/libraries/bot-dialogs/src/main/java/com/microsoft/bot/dialogs/ObjectPath.java @@ -22,73 +22,8 @@ import java.util.Set; import java.util.function.BiConsumer; import java.util.stream.Collectors; -import org.apache.commons.collections4.IteratorUtils; import org.apache.commons.lang3.StringUtils; -/** - * Generic Arraylist of Object. - */ -class Segments extends ArrayList { - - /** - * Returns the first item in the collection. - * @return the first object. - */ - public Object first() { - return get(0); - } - - /** - * Returns the last item in the collection. - * @return the last object. - */ - public Object last() { - return get(size() - 1); - } - - /** - * Gets the SegmentType at the specified index. - * @param index Index of the requested segment. - * @return The SegmentType of item at the requested index. - */ - public SegmentType getSegment(int index) { - return new SegmentType(get(index)); - } -} - -/** - * A class wraps an Object and can assist in determining if it's an integer. - */ -@SuppressWarnings("checkstyle:VisibilityModifier") -class SegmentType { - - public boolean isInt; - public int intValue; - public Segments segmentsValue; - public String stringValue; - - /** - * - * @param value The object to create a SegmentType for. - */ - SegmentType(Object value) { - try { - intValue = Integer.parseInt((String) value); - isInt = true; - } catch (NumberFormatException e) { - isInt = false; - } - - if (!isInt) { - if (value instanceof Segments) { - segmentsValue = (Segments) value; - } else { - stringValue = (String) value; - } - } - } -} - /** * Helper methods for working with dynamic json objects. */ @@ -307,7 +242,9 @@ public static Collection getProperties(Object obj) { } else if (obj instanceof Map) { return ((Map) obj).keySet(); } else if (obj instanceof JsonNode) { - return IteratorUtils.toList(((JsonNode) obj).fieldNames()); + List fields = new ArrayList<>(); + ((JsonNode) obj).fieldNames().forEachRemaining(fields::add); + return fields; } else { List fields = new ArrayList<>(); for (Field field : obj.getClass().getDeclaredFields()) { diff --git a/libraries/bot-dialogs/src/main/java/com/microsoft/bot/dialogs/SegmentType.java b/libraries/bot-dialogs/src/main/java/com/microsoft/bot/dialogs/SegmentType.java new file mode 100644 index 000000000..b3e044a43 --- /dev/null +++ b/libraries/bot-dialogs/src/main/java/com/microsoft/bot/dialogs/SegmentType.java @@ -0,0 +1,33 @@ +package com.microsoft.bot.dialogs; + +/** + * A class wraps an Object and can assist in determining if it's an integer. + */ +@SuppressWarnings("checkstyle:VisibilityModifier") +class SegmentType { + + public boolean isInt; + public int intValue; + public Segments segmentsValue; + public String stringValue; + + /** + * @param value The object to create a SegmentType for. + */ + SegmentType(Object value) { + try { + intValue = Integer.parseInt((String) value); + isInt = true; + } catch (NumberFormatException e) { + isInt = false; + } + + if (!isInt) { + if (value instanceof Segments) { + segmentsValue = (Segments) value; + } else { + stringValue = (String) value; + } + } + } +} diff --git a/libraries/bot-dialogs/src/main/java/com/microsoft/bot/dialogs/Segments.java b/libraries/bot-dialogs/src/main/java/com/microsoft/bot/dialogs/Segments.java new file mode 100644 index 000000000..e2ea8779b --- /dev/null +++ b/libraries/bot-dialogs/src/main/java/com/microsoft/bot/dialogs/Segments.java @@ -0,0 +1,37 @@ +package com.microsoft.bot.dialogs; + +import java.util.ArrayList; + +/** + * Generic Arraylist of Object. + */ +class Segments extends ArrayList { + + /** + * Returns the first item in the collection. + * + * @return the first object. + */ + public Object first() { + return get(0); + } + + /** + * Returns the last item in the collection. + * + * @return the last object. + */ + public Object last() { + return get(size() - 1); + } + + /** + * Gets the SegmentType at the specified index. + * + * @param index Index of the requested segment. + * @return The SegmentType of item at the requested index. + */ + public SegmentType getSegment(int index) { + return new SegmentType(get(index)); + } +} diff --git a/libraries/bot-dialogs/src/main/java/com/microsoft/bot/dialogs/memory/DialogStateManager.java b/libraries/bot-dialogs/src/main/java/com/microsoft/bot/dialogs/memory/DialogStateManager.java index aab062cee..3fddb79f7 100644 --- a/libraries/bot-dialogs/src/main/java/com/microsoft/bot/dialogs/memory/DialogStateManager.java +++ b/libraries/bot-dialogs/src/main/java/com/microsoft/bot/dialogs/memory/DialogStateManager.java @@ -52,6 +52,8 @@ public class DialogStateManager implements Map { private final DialogContext dialogContext; private int version; + private ObjectMapper mapper = new ObjectMapper().findAndRegisterModules(); + /** * Initializes a new instance of the * {@link com.microsoft.bot.dialogs.memory.DialogStateManager} class. @@ -147,7 +149,6 @@ public void setElement(String key, Object element) { if (key.indexOf(SEPARATORS[0]) == -1 && key.indexOf(SEPARATORS[1]) == -1) { MemoryScope scope = getMemoryScope(key); if (scope != null) { - ObjectMapper mapper = new ObjectMapper(); try { scope.setMemory(dialogContext, mapper.writeValueAsString(element)); } catch (JsonProcessingException e) { @@ -398,7 +399,6 @@ public void setValue(String path, Object value) { } if (value != null) { - ObjectMapper mapper = new ObjectMapper(); value = mapper.valueToTree(value); } @@ -433,7 +433,6 @@ public void removeValue(String path) { * @return JsonNode that which represents all memory scopes. */ public JsonNode getMemorySnapshot() { - ObjectMapper mapper = new ObjectMapper(); ObjectNode result = mapper.createObjectNode(); List scopes = configuration.getMemoryScopes().stream().filter((x) -> x.getIncludeInSnapshot()) diff --git a/libraries/bot-dialogs/src/main/java/com/microsoft/bot/dialogs/memory/scopes/DialogContextMemoryScope.java b/libraries/bot-dialogs/src/main/java/com/microsoft/bot/dialogs/memory/scopes/DialogContextMemoryScope.java index ab2ddac4a..bccccf058 100644 --- a/libraries/bot-dialogs/src/main/java/com/microsoft/bot/dialogs/memory/scopes/DialogContextMemoryScope.java +++ b/libraries/bot-dialogs/src/main/java/com/microsoft/bot/dialogs/memory/scopes/DialogContextMemoryScope.java @@ -3,15 +3,15 @@ package com.microsoft.bot.dialogs.memory.scopes; +import com.fasterxml.jackson.databind.node.ArrayNode; +import com.fasterxml.jackson.databind.node.ObjectNode; +import com.microsoft.bot.schema.Serialization; import java.util.Optional; import com.microsoft.bot.dialogs.DialogContext; import com.microsoft.bot.dialogs.DialogInstance; import com.microsoft.bot.dialogs.ScopePath; -import org.json.JSONArray; -import org.json.JSONObject; - /** * DialogContextMemoryScope maps "dialogcontext" -> properties. */ @@ -39,8 +39,8 @@ public final Object getMemory(DialogContext dialogContext) { throw new IllegalArgumentException("dialogContext cannot be null."); } - JSONObject memory = new JSONObject(); - JSONArray stack = new JSONArray(); + ObjectNode memory = Serialization.createObjectNode(); + ArrayNode stack = Serialization.createArrayNode(); DialogContext currentDc = dialogContext; // go to leaf node @@ -52,7 +52,7 @@ public final Object getMemory(DialogContext dialogContext) { // (PORTERS NOTE: javascript stack is reversed with top of stack on end) currentDc.getStack().forEach(item -> { if (item.getId().startsWith("ActionScope[")) { - stack.put(item.getId()); + stack.add(item.getId()); } }); @@ -61,7 +61,7 @@ public final Object getMemory(DialogContext dialogContext) { } // top of stack is stack[0]. - memory.put(stackKey, stack); + memory.set(stackKey, stack); memory.put(activeDialogKey, Optional.ofNullable(dialogContext) .map(DialogContext::getActiveDialog) .map(DialogInstance::getId) diff --git a/libraries/bot-dialogs/src/test/java/com/microsoft/bot/dialogs/ComponentDialogTests.java b/libraries/bot-dialogs/src/test/java/com/microsoft/bot/dialogs/ComponentDialogTests.java index 9f822ef58..c3eca38b3 100644 --- a/libraries/bot-dialogs/src/test/java/com/microsoft/bot/dialogs/ComponentDialogTests.java +++ b/libraries/bot-dialogs/src/test/java/com/microsoft/bot/dialogs/ComponentDialogTests.java @@ -230,11 +230,7 @@ public void BasicComponentDialogTest() throws UnsupportedDataTypeException { new TestFlow(adapter, (turnContext) -> { DialogState state = dialogState.get(turnContext, () -> new DialogState()).join(); DialogSet dialogs = new DialogSet(dialogState); - try { - dialogs.add(new TestComponentDialog()); - } catch (UnsupportedDataTypeException e) { - e.printStackTrace(); - } + dialogs.add(new TestComponentDialog()); DialogContext dc = dialogs.createContext(turnContext).join(); @@ -272,11 +268,7 @@ public void NestedComponentDialogTest() { DialogState state = dialogState.get(turnContext, () -> new DialogState()).join(); DialogSet dialogs = new DialogSet(dialogState); - try { - dialogs.add(new TestNestedComponentDialog()); - } catch (UnsupportedDataTypeException e) { - e.printStackTrace(); - } + dialogs.add(new TestNestedComponentDialog()); DialogContext dc = dialogs.createContext(turnContext).join(); @@ -491,7 +483,7 @@ public void flush() { } private class TestComponentDialog extends ComponentDialog { - private TestComponentDialog() throws UnsupportedDataTypeException { + private TestComponentDialog() { super("TestComponentDialog"); addDialog(createWaterfall()); addDialog(new NumberPrompt("number", null, PromptCultureModels.ENGLISH_CULTURE, Integer.class)); @@ -499,7 +491,7 @@ private TestComponentDialog() throws UnsupportedDataTypeException { } private final class TestNestedComponentDialog extends ComponentDialog { - private TestNestedComponentDialog() throws UnsupportedDataTypeException { + private TestNestedComponentDialog() { super("TestNestedComponentDialog"); WaterfallStep[] steps = new WaterfallStep[] { new WaterfallStep1(), diff --git a/libraries/bot-dialogs/src/test/java/com/microsoft/bot/dialogs/DialogStateManagerTests.java b/libraries/bot-dialogs/src/test/java/com/microsoft/bot/dialogs/DialogStateManagerTests.java index ec38ca1a7..776dcb3ac 100644 --- a/libraries/bot-dialogs/src/test/java/com/microsoft/bot/dialogs/DialogStateManagerTests.java +++ b/libraries/bot-dialogs/src/test/java/com/microsoft/bot/dialogs/DialogStateManagerTests.java @@ -180,6 +180,7 @@ public void TestEntitiesRetrieval() { DialogTestFunction testFunction = dc -> { ObjectMapper mapper = new ObjectMapper(); + mapper.findAndRegisterModules(); String[] array = new String[] { "test1", diff --git a/libraries/bot-schema/src/main/java/com/microsoft/bot/schema/Serialization.java b/libraries/bot-schema/src/main/java/com/microsoft/bot/schema/Serialization.java index 53daaf4c8..9d50d0a99 100644 --- a/libraries/bot-schema/src/main/java/com/microsoft/bot/schema/Serialization.java +++ b/libraries/bot-schema/src/main/java/com/microsoft/bot/schema/Serialization.java @@ -8,6 +8,7 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.databind.node.ObjectNode; import java.io.IOException; import java.util.concurrent.CompletableFuture; @@ -259,5 +260,13 @@ public static JsonNode asNode(byte b) { public static ObjectNode createObjectNode() { return objectMapper.createObjectNode(); } + + /** + * Creates an ArrayNode. + * @return ArrayNode. + */ + public static ArrayNode createArrayNode() { + return objectMapper.createArrayNode(); + } } diff --git a/pom.xml b/pom.xml index 65cad6fc2..392c43b48 100644 --- a/pom.xml +++ b/pom.xml @@ -243,22 +243,22 @@ com.fasterxml.jackson.module jackson-module-parameter-names - 2.9.9 + 2.12.1 com.fasterxml.jackson.datatype jackson-datatype-jdk8 - 2.9.9 + 2.12.1 com.fasterxml.jackson.datatype jackson-datatype-jsr310 - 2.9.9 + 2.12.1 com.fasterxml.jackson.core jackson-databind - 2.9.10.7 + 2.12.1 @@ -269,12 +269,12 @@ com.auth0 java-jwt - 3.8.2 + 3.13.0 com.auth0 jwks-rsa - 0.8.3 + 0.15.0 org.slf4j @@ -289,7 +289,12 @@ commons-io commons-io - 2.6 + 2.8.0 + + + com.google.guava + guava + 30.1-jre @@ -590,12 +595,12 @@ org.apache.maven.plugins maven-site-plugin - 3.7.1 + 3.9.1 org.apache.maven.plugins maven-project-info-reports-plugin - 3.0.0 + 3.1.1