use of org.opensmartgridplatform.domain.core.exceptions.WebServiceMonitorInterceptorException 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);
}
Aggregations