Search in sources :

Example 1 with MsgInfoDTO

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

the class ExtensionListenerUtil method generateMessageInfo.

/**
 * Populate common MsgInfoDTO properties for both Request and Response from MessageContext.
 *
 * @param messageContext Synapse MessageContext
 */
private static MsgInfoDTO generateMessageInfo(MessageContext messageContext) {
    MsgInfoDTO msgInfoDTO = new MsgInfoDTO();
    org.apache.axis2.context.MessageContext axis2MC = ((Axis2MessageContext) messageContext).getAxis2MessageContext();
    msgInfoDTO.setHeaders(getAxis2TransportHeaders(axis2MC));
    msgInfoDTO.setResource(GatewayUtils.extractResource(messageContext));
    msgInfoDTO.setElectedResource((String) messageContext.getProperty(APIMgtGatewayConstants.API_ELECTED_RESOURCE));
    // Add a payload handler instance for the current message context to consume the payload later
    msgInfoDTO.setPayloadHandler(new SynapsePayloadHandler(messageContext));
    Object correlationId = axis2MC.getProperty(CorrelationConstants.CORRELATION_ID);
    if (correlationId instanceof String) {
        msgInfoDTO.setMessageId((String) correlationId);
    }
    msgInfoDTO.setHttpMethod((String) messageContext.getProperty(APIMgtGatewayConstants.HTTP_METHOD));
    return msgInfoDTO;
}
Also used : SynapsePayloadHandler(org.wso2.carbon.apimgt.gateway.handlers.ext.payloadhandler.SynapsePayloadHandler) MsgInfoDTO(org.wso2.carbon.apimgt.common.gateway.dto.MsgInfoDTO) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext)

Example 2 with MsgInfoDTO

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

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

MsgInfoDTO (org.wso2.carbon.apimgt.common.gateway.dto.MsgInfoDTO)3 APIRequestInfoDTO (org.wso2.carbon.apimgt.common.gateway.dto.APIRequestInfoDTO)2 X509Certificate (javax.security.cert.X509Certificate)1 Axis2MessageContext (org.apache.synapse.core.axis2.Axis2MessageContext)1 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)1 RequestContextDTO (org.wso2.carbon.apimgt.common.gateway.dto.RequestContextDTO)1 ResponseContextDTO (org.wso2.carbon.apimgt.common.gateway.dto.ResponseContextDTO)1 SynapsePayloadHandler (org.wso2.carbon.apimgt.gateway.handlers.ext.payloadhandler.SynapsePayloadHandler)1