api/siri_delete_subscription_request_handler.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 SIRIDeleteSubscriptionRequestHandler struct {
xmlRequest *sxml.XMLDeleteSubscriptionRequest
referential *core.Referential
}
func (handler *SIRIDeleteSubscriptionRequestHandler) RequestorRef() string {
return handler.xmlRequest.RequestorRef()
}
func (handler *SIRIDeleteSubscriptionRequestHandler) ConnectorType() string {
return core.SIRI_SUBSCRIPTION_REQUEST_DISPATCHER
}
func (handler *SIRIDeleteSubscriptionRequestHandler) Respond(params HandlerParams) {
logger.Log.Debugf("DeleteSubscription %s cancel subscription: %s", handler.xmlRequest.MessageIdentifier(), handler.xmlRequest.SubscriptionRef())
t := clock.DefaultClock().Now()
response := params.connector.(core.SubscriptionRequestDispatcher).CancelSubscription(handler.xmlRequest, params.message)
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.Type = audit.DELETE_SUBSCRIPTION_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)
}