Search in sources :

Example 1 with PrivateUnsubscribeRequest

use of org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.request.PrivateUnsubscribeRequest in project besu by hyperledger.

the class PrivUnsubscribe method response.

@Override
public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
    try {
        final PrivateUnsubscribeRequest unsubscribeRequest = getMapper().mapPrivateUnsubscribeRequest(requestContext);
        if (privacyController instanceof MultiTenancyPrivacyController) {
            checkIfPrivacyGroupMatchesAuthenticatedPrivacyUserId(requestContext, unsubscribeRequest.getPrivacyGroupId());
        }
        final boolean unsubscribed = subscriptionManager().unsubscribe(unsubscribeRequest);
        return new JsonRpcSuccessResponse(requestContext.getRequest().getId(), unsubscribed);
    } catch (final InvalidSubscriptionRequestException isEx) {
        return new JsonRpcErrorResponse(requestContext.getRequest().getId(), JsonRpcError.INVALID_REQUEST);
    } catch (final SubscriptionNotFoundException snfEx) {
        return new JsonRpcErrorResponse(requestContext.getRequest().getId(), JsonRpcError.SUBSCRIPTION_NOT_FOUND);
    }
}
Also used : PrivateUnsubscribeRequest(org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.request.PrivateUnsubscribeRequest) SubscriptionNotFoundException(org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.SubscriptionNotFoundException) JsonRpcSuccessResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse) InvalidSubscriptionRequestException(org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.request.InvalidSubscriptionRequestException) MultiTenancyPrivacyController(org.hyperledger.besu.ethereum.privacy.MultiTenancyPrivacyController) JsonRpcErrorResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse)

Example 2 with PrivateUnsubscribeRequest

use of org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.request.PrivateUnsubscribeRequest in project besu by hyperledger.

the class PrivUnsubscribeTest method responseContainsUnsubscribeStatus.

@Test
public void responseContainsUnsubscribeStatus() {
    final JsonRpcRequestContext request = createPrivUnsubscribeRequest();
    final PrivateUnsubscribeRequest unsubscribeRequest = new PrivateUnsubscribeRequest(1L, CONNECTION_ID, PRIVACY_GROUP_ID);
    when(mapperMock.mapPrivateUnsubscribeRequest(eq(request))).thenReturn(unsubscribeRequest);
    when(subscriptionManagerMock.unsubscribe(eq(unsubscribeRequest))).thenReturn(true);
    final JsonRpcSuccessResponse expectedResponse = new JsonRpcSuccessResponse(request.getRequest().getId(), true);
    assertThat(privUnsubscribe.response(request)).isEqualTo(expectedResponse);
}
Also used : PrivateUnsubscribeRequest(org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.request.PrivateUnsubscribeRequest) JsonRpcRequestContext(org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext) JsonRpcSuccessResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse) Test(org.junit.Test)

Aggregations

JsonRpcSuccessResponse (org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse)2 PrivateUnsubscribeRequest (org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.request.PrivateUnsubscribeRequest)2 JsonRpcRequestContext (org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext)1 JsonRpcErrorResponse (org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse)1 SubscriptionNotFoundException (org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.SubscriptionNotFoundException)1 InvalidSubscriptionRequestException (org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.request.InvalidSubscriptionRequestException)1 MultiTenancyPrivacyController (org.hyperledger.besu.ethereum.privacy.MultiTenancyPrivacyController)1 Test (org.junit.Test)1