Search in sources :

Example 1 with ExtensionListener

use of org.wso2.carbon.apimgt.common.gateway.extensionlistener.ExtensionListener 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 ExtensionListener

use of org.wso2.carbon.apimgt.common.gateway.extensionlistener.ExtensionListener 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 3 with ExtensionListener

use of org.wso2.carbon.apimgt.common.gateway.extensionlistener.ExtensionListener in project carbon-apimgt by wso2.

the class APIManagerConfiguration method setExtensionListenerConfigurations.

/**
 * Set Extension Listener Configurations.
 *
 * @param omElement XML Config
 */
public void setExtensionListenerConfigurations(OMElement omElement) {
    Iterator extensionListenersElement = omElement.getChildrenWithLocalName(APIConstants.ExtensionListenerConstants.EXTENSION_LISTENER);
    while (extensionListenersElement.hasNext()) {
        OMElement listenerElement = (OMElement) extensionListenersElement.next();
        OMElement listenerTypeElement = listenerElement.getFirstChildWithName(new QName(APIConstants.ExtensionListenerConstants.EXTENSION_TYPE));
        OMElement listenerClassElement = listenerElement.getFirstChildWithName(new QName(APIConstants.ExtensionListenerConstants.EXTENSION_LISTENER_CLASS_NAME));
        if (listenerTypeElement != null && listenerClassElement != null) {
            String listenerClass = listenerClassElement.getText();
            try {
                ExtensionListener extensionListener = (ExtensionListener) APIUtil.getClassInstance(listenerClass);
                extensionListenerMap.put(listenerTypeElement.getText().toUpperCase(), extensionListener);
            } catch (InstantiationException e) {
                log.error("Error while instantiating class " + listenerClass, e);
            } catch (IllegalAccessException e) {
                log.error(e);
            } catch (ClassNotFoundException e) {
                log.error("Cannot find the class " + listenerClass + e);
            }
        }
    }
}
Also used : ExtensionListener(org.wso2.carbon.apimgt.common.gateway.extensionlistener.ExtensionListener) QName(javax.xml.namespace.QName) Iterator(java.util.Iterator) OMElement(org.apache.axiom.om.OMElement)

Example 4 with ExtensionListener

use of org.wso2.carbon.apimgt.common.gateway.extensionlistener.ExtensionListener 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)

Example 5 with ExtensionListener

use of org.wso2.carbon.apimgt.common.gateway.extensionlistener.ExtensionListener 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)

Aggregations

ExtensionListener (org.wso2.carbon.apimgt.common.gateway.extensionlistener.ExtensionListener)5 ExtensionResponseDTO (org.wso2.carbon.apimgt.common.gateway.dto.ExtensionResponseDTO)4 RequestContextDTO (org.wso2.carbon.apimgt.common.gateway.dto.RequestContextDTO)2 ResponseContextDTO (org.wso2.carbon.apimgt.common.gateway.dto.ResponseContextDTO)2 Iterator (java.util.Iterator)1 QName (javax.xml.namespace.QName)1 OMElement (org.apache.axiom.om.OMElement)1