Search in sources :

Example 1 with RequestContextDTO

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

the class ExtensionListenerUtil method preProcessRequest.

/**
 * Handles pre-process request by constructing the request 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 preProcessRequest(MessageContext messageContext, String type) {
    ExtensionListener extensionListener = getExtensionListener(type);
    if (extensionListener != null) {
        RequestContextDTO requestContextDTO = generateRequestContextDTO(messageContext);
        ExtensionResponseDTO responseDTO = extensionListener.preProcessRequest(requestContextDTO);
        return handleExtensionResponse(messageContext, responseDTO);
    }
    return true;
}
Also used : ExtensionListener(org.wso2.carbon.apimgt.common.gateway.extensionlistener.ExtensionListener) RequestContextDTO(org.wso2.carbon.apimgt.common.gateway.dto.RequestContextDTO) ExtensionResponseDTO(org.wso2.carbon.apimgt.common.gateway.dto.ExtensionResponseDTO)

Example 2 with RequestContextDTO

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

the class ExtensionListenerUtil method postProcessRequest.

/**
 * Handles post-process request by constructing the request 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 postProcessRequest(MessageContext messageContext, String type) {
    ExtensionListener extensionListener = getExtensionListener(type);
    if (extensionListener != null) {
        RequestContextDTO requestContextDTO = generateRequestContextDTO(messageContext);
        ExtensionResponseDTO responseDTO = extensionListener.postProcessRequest(requestContextDTO);
        return handleExtensionResponse(messageContext, responseDTO);
    }
    return true;
}
Also used : ExtensionListener(org.wso2.carbon.apimgt.common.gateway.extensionlistener.ExtensionListener) RequestContextDTO(org.wso2.carbon.apimgt.common.gateway.dto.RequestContextDTO) ExtensionResponseDTO(org.wso2.carbon.apimgt.common.gateway.dto.ExtensionResponseDTO)

Example 3 with RequestContextDTO

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

the class ExtensionListenerUtil method generateRequestContextDTO.

/**
 * Generates RequestContextDTO object using Synapse MessageContext.
 *
 * @param messageContext Synapse MessageContext
 * @return RequestContextDTO
 */
private static RequestContextDTO generateRequestContextDTO(MessageContext messageContext) {
    RequestContextDTO requestDTO = new RequestContextDTO();
    MsgInfoDTO msgInfoDTO = generateMessageInfo(messageContext);
    APIRequestInfoDTO apiRequestInfoDTO = generateAPIInfoDTO(messageContext);
    requestDTO.setApiRequestInfo(apiRequestInfoDTO);
    requestDTO.setMsgInfo(msgInfoDTO);
    requestDTO.setCustomProperty(getCustomPropertyMapFromMsgContext(messageContext));
    javax.security.cert.X509Certificate[] clientCerts = null;
    try {
        X509Certificate clientCertificate = Utils.getClientCertificate(((Axis2MessageContext) messageContext).getAxis2MessageContext());
        if (clientCertificate != null) {
            clientCerts = new X509Certificate[] { clientCertificate };
        }
    } catch (APIManagementException e) {
        log.error("Error when getting client certificate", e);
    }
    requestDTO.setClientCerts(clientCerts);
    return requestDTO;
}
Also used : RequestContextDTO(org.wso2.carbon.apimgt.common.gateway.dto.RequestContextDTO) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) MsgInfoDTO(org.wso2.carbon.apimgt.common.gateway.dto.MsgInfoDTO) APIRequestInfoDTO(org.wso2.carbon.apimgt.common.gateway.dto.APIRequestInfoDTO) X509Certificate(javax.security.cert.X509Certificate)

Aggregations

RequestContextDTO (org.wso2.carbon.apimgt.common.gateway.dto.RequestContextDTO)3 ExtensionResponseDTO (org.wso2.carbon.apimgt.common.gateway.dto.ExtensionResponseDTO)2 ExtensionListener (org.wso2.carbon.apimgt.common.gateway.extensionlistener.ExtensionListener)2 X509Certificate (javax.security.cert.X509Certificate)1 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)1 APIRequestInfoDTO (org.wso2.carbon.apimgt.common.gateway.dto.APIRequestInfoDTO)1 MsgInfoDTO (org.wso2.carbon.apimgt.common.gateway.dto.MsgInfoDTO)1