diff --git a/libraries/bot-builder/src/main/java/com/microsoft/bot/builder/ActivityHandler.java b/libraries/bot-builder/src/main/java/com/microsoft/bot/builder/ActivityHandler.java index 58b32a75f..e671f9edb 100644 --- a/libraries/bot-builder/src/main/java/com/microsoft/bot/builder/ActivityHandler.java +++ b/libraries/bot-builder/src/main/java/com/microsoft/bot/builder/ActivityHandler.java @@ -11,11 +11,9 @@ import org.apache.commons.lang3.StringUtils; -import com.microsoft.bot.connector.ConnectorClient; import com.microsoft.bot.schema.Activity; import com.microsoft.bot.schema.ActivityTypes; import com.microsoft.bot.schema.ChannelAccount; -import com.microsoft.bot.schema.HealthCheckResponse; import com.microsoft.bot.schema.MessageReaction; import com.microsoft.bot.schema.ResourceResponse; import com.microsoft.bot.schema.SignInConstants; @@ -415,10 +413,6 @@ protected CompletableFuture onInvokeActivity(TurnContext turnCon } return new InvokeResponse(HttpURLConnection.HTTP_INTERNAL_ERROR, null); }); - } else if (StringUtils.equals(turnContext.getActivity().getName(), "healthCheck")) { - CompletableFuture result = new CompletableFuture<>(); - result.complete(new InvokeResponse(HttpURLConnection.HTTP_OK, onHealthCheck(turnContext))); - return result; } CompletableFuture result = new CompletableFuture<>(); @@ -450,18 +444,6 @@ protected CompletableFuture onSignInInvoke(TurnContext turnContext) { return result; } - /** - * Invoked when a 'healthCheck' event is - * received when the base behavior of onInvokeActivity is used. - * - * @param turnContext The current TurnContext. - * @return A task that represents a HealthCheckResponse. - */ - protected CompletableFuture onHealthCheck(TurnContext turnContext) { - ConnectorClient client = turnContext.getTurnState().get(BotFrameworkAdapter.CONNECTOR_CLIENT_KEY); - return CompletableFuture.completedFuture(HealthCheck.createHealthCheckResponse(client)); - } - /** * Creates a success InvokeResponse with the specified body. * diff --git a/libraries/bot-builder/src/main/java/com/microsoft/bot/builder/HealthCheck.java b/libraries/bot-builder/src/main/java/com/microsoft/bot/builder/HealthCheck.java deleted file mode 100644 index 3fe4ef890..000000000 --- a/libraries/bot-builder/src/main/java/com/microsoft/bot/builder/HealthCheck.java +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -package com.microsoft.bot.builder; - -import java.util.concurrent.ExecutionException; - -import com.microsoft.bot.connector.ConnectorClient; -import com.microsoft.bot.connector.authentication.AppCredentials; -import com.microsoft.bot.schema.HealthCheckResponse; -import com.microsoft.bot.schema.HealthResults; - -/** - * A class to process a HealthCheck request. - */ -public final class HealthCheck { - - private HealthCheck() { - // not called - } - - /** - * @param connector the ConnectorClient instance for this request - * @return HealthCheckResponse - */ - public static HealthCheckResponse createHealthCheckResponse(ConnectorClient connector) { - HealthResults healthResults = new HealthResults(); - healthResults.setSuccess(true); - - if (connector != null) { - healthResults.setUserAgent(connector.getUserAgent()); - AppCredentials credentials = (AppCredentials) connector.credentials(); - try { - healthResults.setAuthorization(credentials.getToken().get()); - } catch (InterruptedException | ExecutionException ignored) { - // An exception here may happen when you have a valid appId but invalid or blank secret. - // No callbacks will be possible, although the bot maybe healthy in other respects. - } - } - - if (healthResults.getAuthorization() != null) { - healthResults.setMessages(new String[]{"Health check succeeded."}); - } else { - healthResults.setMessages(new String[]{"Health check succeeded.", "Callbacks are not authorized."}); - } - - HealthCheckResponse response = new HealthCheckResponse(); - response.setHealthResults(healthResults); - return response; - } -} diff --git a/libraries/bot-builder/src/test/java/com/microsoft/bot/builder/ActivityHandlerTests.java b/libraries/bot-builder/src/test/java/com/microsoft/bot/builder/ActivityHandlerTests.java index 4ca4fcfc4..b6a5af8eb 100644 --- a/libraries/bot-builder/src/test/java/com/microsoft/bot/builder/ActivityHandlerTests.java +++ b/libraries/bot-builder/src/test/java/com/microsoft/bot/builder/ActivityHandlerTests.java @@ -10,9 +10,6 @@ import java.util.ArrayList; import java.util.List; import java.util.concurrent.CompletableFuture; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.atomic.AtomicReference; -import org.mockito.internal.matchers.Not; public class ActivityHandlerTests { @Test @@ -428,98 +425,6 @@ public void TestUnrecognizedActivityType() { Assert.assertEquals("onUnrecognizedActivityType", bot.getRecord().get(0)); } - @Test - public void TestHealthCheckAsyncOverride() { - Activity activity = new Activity() { - { - setType(ActivityTypes.INVOKE); - setName("healthCheck"); - } - }; - - TurnContext turnContext = new TurnContextImpl(new TestInvokeAdapter(), activity); - - TestActivityHandler bot = new TestActivityHandler(); - bot.onTurn(turnContext).join(); - - Assert.assertEquals(2, bot.getRecord().size()); - Assert.assertEquals("onInvokeActivity", bot.getRecord().get(0)); - Assert.assertEquals("onHealthCheck", bot.getRecord().get(1)); - } - - @Test - public void TestHealthCheckAsync() { - Activity activity = new Activity() { - { - setType(ActivityTypes.INVOKE); - setName("healthCheck"); - } - }; - - AtomicReference> activitiesToSend = new AtomicReference<>(); - TurnContext turnContext = new TurnContextImpl(new SimpleAdapter(activitiesToSend::set), activity); - - ActivityHandler bot = new ActivityHandler(); - bot.onTurn(turnContext).join(); - - Assert.assertNotNull(activitiesToSend.get()); - Assert.assertEquals(1, activitiesToSend.get().size()); - Assert.assertTrue(activitiesToSend.get().get(0).getValue() instanceof InvokeResponse); - Assert.assertEquals(200, ((InvokeResponse) activitiesToSend.get().get(0).getValue()).getStatus()); - CompletableFuture future = ((CompletableFuture) ((InvokeResponse) activitiesToSend.get().get(0).getValue()) - .getBody()); - HealthCheckResponse result = new HealthCheckResponse(); - result = (HealthCheckResponse) future.join(); - Assert.assertTrue(result.getHealthResults().getSuccess()); - String[] messages = result.getHealthResults().getMessages(); - Assert.assertEquals(messages[0], "Health check succeeded."); - } - - @Test - public void TestHealthCheckWithConnectorAsync() { - Activity activity = new Activity() { - { - setType(ActivityTypes.INVOKE); - setName("healthCheck"); - } - }; - - AtomicReference> activitiesToSend = new AtomicReference<>(); - TurnContext turnContext = new TurnContextImpl(new SimpleAdapter(activitiesToSend::set), activity); - MockConnectorClient mockConnector = new MockConnectorClient("Windows/3.1", new MockAppCredentials("awesome")); - turnContext.getTurnState().add(BotFrameworkAdapter.CONNECTOR_CLIENT_KEY, mockConnector); - ActivityHandler bot = new ActivityHandler(); - bot.onTurn(turnContext).join(); - - Assert.assertNotNull(activitiesToSend.get()); - Assert.assertEquals(1, activitiesToSend.get().size()); - Assert.assertTrue(activitiesToSend.get().get(0).getValue() instanceof InvokeResponse); - Assert.assertEquals( - 200, - ((InvokeResponse) activitiesToSend.get().get(0).getValue()).getStatus() - ); - CompletableFuture future = - ((CompletableFuture) - ((InvokeResponse) activitiesToSend.get().get(0).getValue()).getBody()); - HealthCheckResponse result = new HealthCheckResponse(); - result = (HealthCheckResponse) future.join(); - Assert.assertTrue(result.getHealthResults().getSuccess()); - Assert.assertEquals(result.getHealthResults().getAuthorization(), "awesome"); - Assert.assertEquals(result.getHealthResults().getUserAgent(), "Windows/3.1"); - String[] messages = result.getHealthResults().getMessages(); - Assert.assertEquals(messages[0], "Health check succeeded."); - } - - private static class TestInvokeAdapter extends NotImplementedAdapter { - @Override - public CompletableFuture sendActivities( - TurnContext context, - List activities - ) { - return CompletableFuture.completedFuture(new ResourceResponse[0]); - } - } - private static class NotImplementedAdapter extends BotAdapter { @Override public CompletableFuture sendActivities( @@ -635,12 +540,6 @@ protected CompletableFuture onInvokeActivity(TurnContext turnCon return super.onInvokeActivity(turnContext); } - @Override - protected CompletableFuture onHealthCheck(TurnContext turnContext) { - record.add("onHealthCheck"); - return super.onHealthCheck(turnContext); - } - @Override protected CompletableFuture onInstallationUpdate(TurnContext turnContext) { record.add("onInstallationUpdate"); diff --git a/libraries/bot-schema/src/main/java/com/microsoft/bot/schema/HealthCheckResponse.java b/libraries/bot-schema/src/main/java/com/microsoft/bot/schema/HealthCheckResponse.java deleted file mode 100644 index caf9d49af..000000000 --- a/libraries/bot-schema/src/main/java/com/microsoft/bot/schema/HealthCheckResponse.java +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -package com.microsoft.bot.schema; - -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; - -/** - * Defines the structure that is returned as the result of a health check on the bot. - * The health check is sent to the bot as an {@link Activity} of type "invoke" and this class along - * with {@link HealthResults} defines the structure of the body of the response. - * The name of the invoke Activity is "healthCheck". - */ -public class HealthCheckResponse { - /** - * The health check results. - */ - @JsonProperty(value = "healthResults") - @JsonInclude(JsonInclude.Include.NON_EMPTY) - private HealthResults healthResults; - - /** - * Gets the healthResults value. - * - * @return The healthResults value. - */ - public HealthResults getHealthResults() { - return this.healthResults; - } - - /** - * Sets the healthResults value. - * - * @param withHealthResults The healthResults value to set. - */ - public void setHealthResults(HealthResults withHealthResults) { - this.healthResults = withHealthResults; - } -} diff --git a/libraries/bot-schema/src/main/java/com/microsoft/bot/schema/HealthResults.java b/libraries/bot-schema/src/main/java/com/microsoft/bot/schema/HealthResults.java deleted file mode 100644 index 2e727cc00..000000000 --- a/libraries/bot-schema/src/main/java/com/microsoft/bot/schema/HealthResults.java +++ /dev/null @@ -1,139 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -package com.microsoft.bot.schema; - -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; - -/** - * Defines the structure that is returned as the result of a health check on the bot. - * The health check is sent to the bot as an InvokeActivity and this class along with {@link HealthCheckResponse} - * defines the structure of the body of the response. - */ -public class HealthResults { - /** - * A value indicating whether the health check has succeeded and the bot is healthy. - */ - @JsonProperty(value = "success") - @JsonInclude(JsonInclude.Include.NON_EMPTY) - private Boolean success; - - /** - * A value that is exactly the same as the Authorization header that would have been added to an HTTP POST back. - */ - @JsonProperty(value = "authorization") - @JsonInclude(JsonInclude.Include.NON_EMPTY) - private String authorization; - - /** - * A value that is exactly the same as the User-Agent header that would have been added to an HTTP POST back. - */ - @JsonProperty(value = "user-agent") - @JsonInclude(JsonInclude.Include.NON_EMPTY) - private String userAgent; - - /** - * Informational messages that can be optionally included in the health check response. - */ - @JsonProperty(value = "messages") - @JsonInclude(JsonInclude.Include.NON_EMPTY) - private String[] messages; - - /** - * Diagnostic data that can be optionally included in the health check response. - */ - @JsonProperty(value = "diagnostics") - @JsonInclude(JsonInclude.Include.NON_EMPTY) - private Object diagnostics; - - /** - * Gets the success value. - * - * @return The success value. - */ - public Boolean getSuccess() { - return this.success; - } - - /** - * Sets the success value. - * - * @param withSuccess The success value to set. - */ - public void setSuccess(Boolean withSuccess) { - this.success = withSuccess; - } - - /** - * Get the authorization value. - * - * @return the authorization value - */ - public String getAuthorization() { - return this.authorization; - } - - /** - * Set the authorization value. - * - * @param withAuthorization the authization value to set - */ - public void setAuthorization(String withAuthorization) { - this.authorization = withAuthorization; - } - - /** - * Get the userAgent value. - * - * @return the userAgent value - */ - public String getUserAgent() { - return this.userAgent; - } - - /** - * Set the userAgent value. - * - * @param withUserAgent the userAgent value to set - */ - public void setUserAgent(String withUserAgent) { - this.userAgent = withUserAgent; - } - - /** - * Get the messages value. - * - * @return the messages value - */ - public String[] getMessages() { - return this.messages; - } - - /** - * Set the messages value. - * - * @param withMessages the messages value to set - */ - public void setMessages(String[] withMessages) { - this.messages = withMessages; - } - - /** - * Get the diagnostics value. - * - * @return the diagnostics value - */ - public Object getDiagnostics() { - return this.diagnostics; - } - - /** - * Set the diagnostics value. - * - * @param withDiagnostics the diagnostics value to set - */ - public void setDiagnostics(Object withDiagnostics) { - this.diagnostics = withDiagnostics; - } -}