use of org.wso2.carbon.apimgt.gateway.inbound.websocket.InboundProcessorResponseDTO in project carbon-apimgt by wso2.
the class InboundWebsocketProcessorUtil method doThrottleForGraphQL.
/**
* Checks if the request is throttled for GraphQL subscriptions.
*
* @param msgSize Websocket msg size
* @param verbInfoDTO VerbInfoDTO for invoking operation.
* @param inboundMessageContext InboundMessageContext
* @param operationId Operation ID
* @return InboundProcessorResponseDTO
*/
public static InboundProcessorResponseDTO doThrottleForGraphQL(int msgSize, VerbInfoDTO verbInfoDTO, InboundMessageContext inboundMessageContext, String operationId) {
GraphQLProcessorResponseDTO responseDTO = new GraphQLProcessorResponseDTO();
responseDTO.setId(operationId);
return InboundWebsocketProcessorUtil.doThrottle(msgSize, verbInfoDTO, inboundMessageContext, responseDTO);
}
use of org.wso2.carbon.apimgt.gateway.inbound.websocket.InboundProcessorResponseDTO in project carbon-apimgt by wso2.
the class HandshakeProcessor method processHandshake.
/**
* This method process websocket handshake and perform authentication using the inbound message context.
* For successful authentications, it sets the resource map of the invoking API to the context.
*
* @param inboundMessageContext InboundMessageContext
* @return InboundProcessorResponseDTO with handshake processing response
*/
public InboundProcessorResponseDTO processHandshake(InboundMessageContext inboundMessageContext) {
if (log.isDebugEnabled()) {
log.debug("Processing handshake message for inbound websocket context: " + inboundMessageContext.getApiContext());
}
InboundProcessorResponseDTO inboundProcessorResponseDTO = new InboundProcessorResponseDTO();
boolean isOAuthHeaderValid;
try {
isOAuthHeaderValid = InboundWebsocketProcessorUtil.isAuthenticated(inboundMessageContext);
} catch (APIManagementException e) {
log.error(WebSocketApiConstants.HandshakeErrorConstants.API_AUTH_GENERAL_MESSAGE, e);
return InboundWebsocketProcessorUtil.getHandshakeErrorDTO(WebSocketApiConstants.HandshakeErrorConstants.API_AUTH_ERROR, WebSocketApiConstants.HandshakeErrorConstants.API_AUTH_GENERAL_MESSAGE);
} catch (APISecurityException e) {
log.error(e);
return InboundWebsocketProcessorUtil.getHandshakeErrorDTO(WebSocketApiConstants.HandshakeErrorConstants.API_AUTH_ERROR, e.getMessage());
}
if (isOAuthHeaderValid) {
if (log.isDebugEnabled()) {
log.debug("Handshake authentication success for inbound websocket context: " + inboundMessageContext.getApiContext() + " Setting ResourceInfoDTOs of elected API " + "to inbound message context");
}
setResourcesMapToContext(inboundMessageContext);
} else {
log.error("Authentication failed for " + inboundMessageContext.getApiContext());
return InboundWebsocketProcessorUtil.getHandshakeErrorDTO(WebSocketApiConstants.HandshakeErrorConstants.API_AUTH_ERROR, WebSocketApiConstants.HandshakeErrorConstants.API_AUTH_INVALID_CREDENTIALS_MESSAGE);
}
return inboundProcessorResponseDTO;
}
use of org.wso2.carbon.apimgt.gateway.inbound.websocket.InboundProcessorResponseDTO in project carbon-apimgt by wso2.
the class InboundWebSocketProcessor method handleRequest.
/**
* This method process websocket request messages (publish messages) and
* hand over the processing to relevant request 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 handleRequest(WebSocketFrame msg, InboundMessageContext inboundMessageContext) {
RequestProcessor requestProcessor;
String msgText = null;
if (APIConstants.GRAPHQL_API.equals(inboundMessageContext.getElectedAPI().getApiType()) && msg instanceof TextWebSocketFrame) {
requestProcessor = new GraphQLRequestProcessor();
msgText = ((TextWebSocketFrame) msg).text();
} else {
requestProcessor = new RequestProcessor();
}
return requestProcessor.handleRequest(msg.content().capacity(), msgText, inboundMessageContext);
}
use of org.wso2.carbon.apimgt.gateway.inbound.websocket.InboundProcessorResponseDTO 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);
}
use of org.wso2.carbon.apimgt.gateway.inbound.websocket.InboundProcessorResponseDTO in project carbon-apimgt by wso2.
the class GraphQLRequestProcessor method validateQueryPayload.
/**
* Validates GraphQL query payload using QueryValidator and graphql schema of the invoking API.
*
* @param inboundMessageContext InboundMessageContext
* @param document Graphql payload
* @param operationId Graphql message id
* @return InboundProcessorResponseDTO
*/
private InboundProcessorResponseDTO validateQueryPayload(InboundMessageContext inboundMessageContext, Document document, String operationId) {
GraphQLProcessorResponseDTO responseDTO = new GraphQLProcessorResponseDTO();
responseDTO.setId(operationId);
QueryValidator queryValidator = new QueryValidator(new Validator());
// payload validation
String validationErrorMessage = queryValidator.validatePayload(inboundMessageContext.getGraphQLSchemaDTO().getGraphQLSchema(), document);
if (validationErrorMessage != null) {
String error = WebSocketApiConstants.FrameErrorConstants.GRAPHQL_INVALID_QUERY_MESSAGE + " : " + validationErrorMessage;
log.error(error);
responseDTO.setError(true);
responseDTO.setErrorCode(WebSocketApiConstants.FrameErrorConstants.GRAPHQL_INVALID_QUERY);
responseDTO.setErrorMessage(error);
return responseDTO;
}
return responseDTO;
}
Aggregations