Search in sources :

Example 1 with LoggingRequestMessage

use of org.opensmartgridplatform.adapter.ws.infra.jms.LoggingRequestMessage in project open-smart-grid-platform by OSGP.

the class WebServiceMonitorInterceptor method createAndSendLoggingRequestMessage.

/**
 * Create the logging Request Message and send it using {@link
 * WebServiceMonitorInterceptor#loggingMessageSender}.
 *
 * @param messageContext The messageContext.
 * @param endpoint The endpoint.
 * @param overrideResult When set, use this value as result for the {@link LoggingRequestMessage}.
 * @throws WebServiceMonitorInterceptorException
 */
private void createAndSendLoggingRequestMessage(final MessageContext messageContext, final Object endpoint, final String overrideResult) throws WebServiceMonitorInterceptorException {
    if (!this.soapMessageLoggingEnabled) {
        return;
    }
    // Get the current time.
    final Date now = new Date();
    // Get EndPointClass and EndPointMethod.
    final EndpointClassAndMethod classAndMethod = this.getEndPointClassAndMethod(endpoint);
    // Get the request.
    final SoapMessage request = this.getSoapRequest(messageContext);
    final SoapHeader soapHeader = request.getSoapHeader();
    // Read OrganisationIdentification, UserName and ApplicationName from
    // header from request.
    final String organisationIdentification = this.getHeaderValue(soapHeader, this.organisationIdentificationHeader);
    final String userName = this.getHeaderValue(soapHeader, this.userNameHeader);
    final String appName = this.getHeaderValue(soapHeader, this.applicationNameHeader);
    // Read correlationUid and deviceId from request.
    final Map<String, Object> requestData = this.parseSoapMessage(request);
    if (requestData == null) {
        throw new WebServiceMonitorInterceptorException("unable to get correlationUid or deviceId from request");
    }
    // Get the response.
    final SoapMessage response = this.getSoapResponse(messageContext);
    // Read correlationUid and deviceId and result and data size from
    // response.
    final Map<String, Object> responseData = this.parseSoapMessage(response);
    if (responseData == null) {
        throw new WebServiceMonitorInterceptorException("unable to get correlationUid or deviceId or result from response");
    }
    // Check response for correlationId, otherwise request.
    String correlationUid = (String) responseData.get(CORRELATION_UID);
    if (StringUtils.isEmpty(correlationUid)) {
        correlationUid = (String) requestData.get(CORRELATION_UID);
    }
    // Creating the logging request message.
    final String deviceIdentification = (String) requestData.get(DEVICE_ID);
    final CorrelationIds ids = new CorrelationIds(organisationIdentification, deviceIdentification, correlationUid);
    final ResponseResultAndDataSize responseResultAndDataSize = this.resultAndDataSizeFrom(responseData);
    final LoggingRequestMessage loggingRequestMessage = new LoggingRequestMessage(now, ids, userName, appName, classAndMethod, responseResultAndDataSize);
    if (!StringUtils.isEmpty(overrideResult)) {
        loggingRequestMessage.setResponseResult(overrideResult);
    }
    this.loggingMessageSender.send(loggingRequestMessage);
}
Also used : EndpointClassAndMethod(org.opensmartgridplatform.adapter.ws.infra.jms.EndpointClassAndMethod) ResponseResultAndDataSize(org.opensmartgridplatform.adapter.ws.infra.jms.ResponseResultAndDataSize) LoggingRequestMessage(org.opensmartgridplatform.adapter.ws.infra.jms.LoggingRequestMessage) WebServiceMonitorInterceptorException(org.opensmartgridplatform.domain.core.exceptions.WebServiceMonitorInterceptorException) SoapHeader(org.springframework.ws.soap.SoapHeader) Date(java.util.Date) CorrelationIds(org.opensmartgridplatform.shared.infra.jms.CorrelationIds) SoapMessage(org.springframework.ws.soap.SoapMessage)

Aggregations

Date (java.util.Date)1 EndpointClassAndMethod (org.opensmartgridplatform.adapter.ws.infra.jms.EndpointClassAndMethod)1 LoggingRequestMessage (org.opensmartgridplatform.adapter.ws.infra.jms.LoggingRequestMessage)1 ResponseResultAndDataSize (org.opensmartgridplatform.adapter.ws.infra.jms.ResponseResultAndDataSize)1 WebServiceMonitorInterceptorException (org.opensmartgridplatform.domain.core.exceptions.WebServiceMonitorInterceptorException)1 CorrelationIds (org.opensmartgridplatform.shared.infra.jms.CorrelationIds)1 SoapHeader (org.springframework.ws.soap.SoapHeader)1 SoapMessage (org.springframework.ws.soap.SoapMessage)1