Search in sources :

Example 6 with GraphQLResponseProcessor

use of org.wso2.carbon.apimgt.gateway.inbound.websocket.response.GraphQLResponseProcessor in project carbon-apimgt by wso2.

the class GraphQLResponseProcessorTest method testHandleResponseSuccess.

@Test
public void testHandleResponseSuccess() {
    InboundMessageContext inboundMessageContext = new InboundMessageContext();
    int msgSize = 100;
    String msgText = "{\"type\":\"data\",\"id\":\"1\",\"payload\":{\"data\":" + "{\"liftStatusChange\":{\"name\":\"Astra Express\"}}}}";
    PowerMockito.mockStatic(InboundWebsocketProcessorUtil.class);
    InboundProcessorResponseDTO responseDTO = new InboundProcessorResponseDTO();
    PowerMockito.when(InboundWebsocketProcessorUtil.authenticateToken(inboundMessageContext)).thenReturn(responseDTO);
    VerbInfoDTO verbInfoDTO = new VerbInfoDTO();
    verbInfoDTO.setHttpVerb("SUBSCRIPTION");
    verbInfoDTO.setThrottling("Unlimited");
    GraphQLOperationDTO graphQLOperationDTO = new GraphQLOperationDTO(verbInfoDTO, "liftStatusChange");
    inboundMessageContext.addVerbInfoForGraphQLMsgId("1", graphQLOperationDTO);
    PowerMockito.when(InboundWebsocketProcessorUtil.validateScopes(inboundMessageContext, "liftStatusChange", "1")).thenReturn(responseDTO);
    PowerMockito.when(InboundWebsocketProcessorUtil.doThrottleForGraphQL(msgSize, verbInfoDTO, inboundMessageContext, "1")).thenReturn(responseDTO);
    GraphQLResponseProcessor responseProcessor = new GraphQLResponseProcessor();
    InboundProcessorResponseDTO processorResponseDTO = responseProcessor.handleResponse(msgSize, msgText, inboundMessageContext);
    Assert.assertFalse(processorResponseDTO.isError());
    Assert.assertNull(processorResponseDTO.getErrorMessage());
}
Also used : GraphQLOperationDTO(org.wso2.carbon.apimgt.gateway.dto.GraphQLOperationDTO) VerbInfoDTO(org.wso2.carbon.apimgt.impl.dto.VerbInfoDTO) InboundProcessorResponseDTO(org.wso2.carbon.apimgt.gateway.inbound.websocket.InboundProcessorResponseDTO) InboundMessageContext(org.wso2.carbon.apimgt.gateway.inbound.InboundMessageContext) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 7 with GraphQLResponseProcessor

use of org.wso2.carbon.apimgt.gateway.inbound.websocket.response.GraphQLResponseProcessor in project carbon-apimgt by wso2.

the class InboundWebSocketProcessor method handleResponse.

/**
 * This method process websocket response messages (subscribe messages) and
 * hand over the processing to relevant response intercepting processor for authentication, scope validation,
 * throttling etc.
 *
 * @param msg                   Websocket request message frame
 * @param inboundMessageContext InboundMessageContext
 * @return InboundProcessorResponseDTO with handshake processing response
 */
public InboundProcessorResponseDTO handleResponse(WebSocketFrame msg, InboundMessageContext inboundMessageContext) throws Exception {
    ResponseProcessor responseProcessor;
    String msgText = null;
    if (APIConstants.GRAPHQL_API.equals(inboundMessageContext.getElectedAPI().getApiType()) && msg instanceof TextWebSocketFrame) {
        responseProcessor = new GraphQLResponseProcessor();
        msgText = ((TextWebSocketFrame) msg).text();
    } else {
        responseProcessor = new ResponseProcessor();
    }
    return responseProcessor.handleResponse(msg.content().capacity(), msgText, inboundMessageContext);
}
Also used : GraphQLResponseProcessor(org.wso2.carbon.apimgt.gateway.inbound.websocket.response.GraphQLResponseProcessor) TextWebSocketFrame(io.netty.handler.codec.http.websocketx.TextWebSocketFrame) GraphQLResponseProcessor(org.wso2.carbon.apimgt.gateway.inbound.websocket.response.GraphQLResponseProcessor) ResponseProcessor(org.wso2.carbon.apimgt.gateway.inbound.websocket.response.ResponseProcessor)

Aggregations

Test (org.junit.Test)6 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)6 InboundMessageContext (org.wso2.carbon.apimgt.gateway.inbound.InboundMessageContext)6 InboundProcessorResponseDTO (org.wso2.carbon.apimgt.gateway.inbound.websocket.InboundProcessorResponseDTO)6 GraphQLOperationDTO (org.wso2.carbon.apimgt.gateway.dto.GraphQLOperationDTO)4 VerbInfoDTO (org.wso2.carbon.apimgt.impl.dto.VerbInfoDTO)4 GraphQLProcessorResponseDTO (org.wso2.carbon.apimgt.gateway.inbound.websocket.GraphQLProcessorResponseDTO)3 TextWebSocketFrame (io.netty.handler.codec.http.websocketx.TextWebSocketFrame)1 GraphQLResponseProcessor (org.wso2.carbon.apimgt.gateway.inbound.websocket.response.GraphQLResponseProcessor)1 ResponseProcessor (org.wso2.carbon.apimgt.gateway.inbound.websocket.response.ResponseProcessor)1