api/siri_check_status_request_hander.go
package api
import (
"fmt"
"bitbucket.org/enroute-mobi/ara/audit"
"bitbucket.org/enroute-mobi/ara/clock"
"bitbucket.org/enroute-mobi/ara/core"
"bitbucket.org/enroute-mobi/ara/logger"
"bitbucket.org/enroute-mobi/ara/remote"
"bitbucket.org/enroute-mobi/ara/siri/sxml"
)
type SIRICheckStatusRequestHandler struct {
xmlRequest *sxml.XMLCheckStatusRequest
referential *core.Referential
}
func (handler *SIRICheckStatusRequestHandler) RequestorRef() string {
return handler.xmlRequest.RequestorRef()
}
func (handler *SIRICheckStatusRequestHandler) ConnectorType() string {
return "siri-check-status-server"
}
func (handler *SIRICheckStatusRequestHandler) Respond(params HandlerParams) {
logger.Log.Debugf("CheckStatus %s", handler.xmlRequest.MessageIdentifier())
t := clock.DefaultClock().Now()
response, err := params.connector.(core.CheckStatusServer).CheckStatus(handler.xmlRequest, params.message)
if err != nil {
SIRIError{
errCode: "InternalServiceError",
errDescription: fmt.Sprintf("Internal Error: %v", err),
referentialSlug: string(handler.referential.Slug()),
envelopeType: params.envelopeType,
response: params.rw,
}.Send()
return
}
xmlResponse, err := response.BuildXML(params.envelopeType)
if err != nil {
SIRIError{
errCode: "InternalServiceError",
errDescription: fmt.Sprintf("Internal Error: %v", err),
referentialSlug: string(handler.referential.Slug()),
envelopeType: params.envelopeType,
response: params.rw,
}.Send()
return
}
// Wrap soap and send response
buffer := remote.NewSIRIBuffer(params.envelopeType)
buffer.WriteXML(xmlResponse)
n, err := buffer.WriteTo(params.rw)
if err != nil {
SIRIError{
errCode: "InternalServiceError",
errDescription: fmt.Sprintf("Internal Error: %v", err),
referentialSlug: string(handler.referential.Slug()),
envelopeType: params.envelopeType,
response: params.rw,
}.Send()
return
}
params.message.Partner = string(params.connector.(*core.SIRICheckStatusServer).Partner().Slug())
params.message.Type = audit.CHECK_STATUS_REQUEST
params.message.RequestRawMessage = handler.xmlRequest.RawXML()
params.message.ResponseRawMessage = xmlResponse
params.message.ResponseSize = n
params.message.ProcessingTime = clock.DefaultClock().Since(t).Seconds()
audit.CurrentBigQuery(string(handler.referential.Slug())).WriteEvent(params.message)
}