Search in sources :

Example 1 with ResponseContextDTO

use of org.wso2.carbon.apimgt.common.gateway.dto.ResponseContextDTO in project carbon-apimgt by wso2.

the class ExtensionListenerUtil method preProcessResponse.

/**
 * Handles pre-process response by constructing the response context DTO, invoking the matching extension listener
 * implementation and processing the extension listener response.
 *
 * @param messageContext Synapse Message Context
 * @param type           Extension type
 * @return boolean indicating to continue normal handler response flow or respond back immediately
 */
public static boolean preProcessResponse(MessageContext messageContext, String type) {
    ExtensionListener extensionListener = getExtensionListener(type);
    if (extensionListener != null) {
        ResponseContextDTO responseContextDTO = generateResponseContextDTO(messageContext);
        ExtensionResponseDTO responseDTO = extensionListener.preProcessResponse(responseContextDTO);
        return handleExtensionResponse(messageContext, responseDTO);
    }
    return true;
}
Also used : ExtensionListener(org.wso2.carbon.apimgt.common.gateway.extensionlistener.ExtensionListener) ExtensionResponseDTO(org.wso2.carbon.apimgt.common.gateway.dto.ExtensionResponseDTO) ResponseContextDTO(org.wso2.carbon.apimgt.common.gateway.dto.ResponseContextDTO)

Example 2 with ResponseContextDTO

use of org.wso2.carbon.apimgt.common.gateway.dto.ResponseContextDTO in project carbon-apimgt by wso2.

the class ExtensionListenerUtil method generateResponseContextDTO.

/**
 * Generates ResponseContextDTO object using Synapse MessageContext.
 *
 * @param messageContext Synapse MessageContext
 * @return ResponseContextDTO
 */
private static ResponseContextDTO generateResponseContextDTO(MessageContext messageContext) {
    ResponseContextDTO responseContextDTO = new ResponseContextDTO();
    MsgInfoDTO msgInfoDTO = generateMessageInfo(messageContext);
    APIRequestInfoDTO apiRequestInfoDTO = generateAPIInfoDTO(messageContext);
    responseContextDTO.setApiRequestInfo(apiRequestInfoDTO);
    responseContextDTO.setMsgInfo(msgInfoDTO);
    responseContextDTO.setStatusCode((int) ((Axis2MessageContext) messageContext).getAxis2MessageContext().getProperty(NhttpConstants.HTTP_SC));
    return responseContextDTO;
}
Also used : ResponseContextDTO(org.wso2.carbon.apimgt.common.gateway.dto.ResponseContextDTO) MsgInfoDTO(org.wso2.carbon.apimgt.common.gateway.dto.MsgInfoDTO) APIRequestInfoDTO(org.wso2.carbon.apimgt.common.gateway.dto.APIRequestInfoDTO)

Example 3 with ResponseContextDTO

use of org.wso2.carbon.apimgt.common.gateway.dto.ResponseContextDTO in project carbon-apimgt by wso2.

the class ExtensionListenerUtil method postProcessResponse.

/**
 * Handles post-process response by constructing the response context DTO, invoking the matching extension listener
 * implementation and processing the extension listener response.
 *
 * @param messageContext Synapse Message Context
 * @param type           Extension type
 * @return boolean indicating to continue normal handler response flow or respond back immediately
 */
public static boolean postProcessResponse(MessageContext messageContext, String type) {
    ExtensionListener extensionListener = getExtensionListener(type);
    if (extensionListener != null) {
        ResponseContextDTO responseContextDTO = generateResponseContextDTO(messageContext);
        ExtensionResponseDTO responseDTO = extensionListener.postProcessResponse(responseContextDTO);
        return handleExtensionResponse(messageContext, responseDTO);
    }
    return true;
}
Also used : ExtensionListener(org.wso2.carbon.apimgt.common.gateway.extensionlistener.ExtensionListener) ExtensionResponseDTO(org.wso2.carbon.apimgt.common.gateway.dto.ExtensionResponseDTO) ResponseContextDTO(org.wso2.carbon.apimgt.common.gateway.dto.ResponseContextDTO)

Aggregations

ResponseContextDTO (org.wso2.carbon.apimgt.common.gateway.dto.ResponseContextDTO)3 ExtensionResponseDTO (org.wso2.carbon.apimgt.common.gateway.dto.ExtensionResponseDTO)2 ExtensionListener (org.wso2.carbon.apimgt.common.gateway.extensionlistener.ExtensionListener)2 APIRequestInfoDTO (org.wso2.carbon.apimgt.common.gateway.dto.APIRequestInfoDTO)1 MsgInfoDTO (org.wso2.carbon.apimgt.common.gateway.dto.MsgInfoDTO)1