mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-22 07:38:45 +05:00
Add CustomJSONCoded in case that Apier is active on the same engine with dispatcher
This commit is contained in:
committed by
Dan Christian Bogos
parent
b86d83b2e8
commit
fbc9f2332d
@@ -582,6 +582,8 @@ const (
|
||||
MetaSuppliersOffset = "*suppliers_offset"
|
||||
ActiveSessionPrefix = "act"
|
||||
PasiveSessionPrefix = "psv"
|
||||
ApierV = "ApierV"
|
||||
MetaApier = "*apier"
|
||||
)
|
||||
|
||||
// Migrator Action
|
||||
@@ -713,6 +715,7 @@ const (
|
||||
ChargerSv1 = "ChargerSv1"
|
||||
MetaAuth = "*auth"
|
||||
APIKey = "APIKey"
|
||||
RouteID = "RouteID"
|
||||
APIMethods = "APIMethods"
|
||||
APIMethod = "APIMethod"
|
||||
NestingSep = "."
|
||||
@@ -886,9 +889,9 @@ const (
|
||||
|
||||
// DispatcherS APIs
|
||||
const (
|
||||
DispatcherSv1Ping = "DispatcherSv1.Ping"
|
||||
DispatcherSv1GetProfileForEvent = "DispatcherSv1.GetProfileForEvent"
|
||||
DispatcherSv1SwitchApierVRequest = "DispatcherSv1.SwitchApierVRequest"
|
||||
DispatcherSv1Ping = "DispatcherSv1.Ping"
|
||||
DispatcherSv1GetProfileForEvent = "DispatcherSv1.GetProfileForEvent"
|
||||
DispatcherSv1Apier = "DispatcherSv1.Apier"
|
||||
)
|
||||
|
||||
// AnalyzerS APIs
|
||||
|
||||
19
utils/gob_codec.go
Normal file
19
utils/gob_codec.go
Normal file
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
|
||||
Copyright (C) ITsysCOM GmbH
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
package utils
|
||||
@@ -53,7 +53,7 @@ type jsonServerCodec struct {
|
||||
pending map[uint64]*json.RawMessage
|
||||
}
|
||||
|
||||
// NewServerCodec returns a new rpc.ServerCodec using JSON-RPC on conn.
|
||||
// NewCustomJSONServerCodec is used only when DispatcherS is active to handle APIer methods generically
|
||||
func NewCustomJSONServerCodec(conn io.ReadWriteCloser) rpc.ServerCodec {
|
||||
return &jsonServerCodec{
|
||||
dec: json.NewDecoder(conn),
|
||||
@@ -64,9 +64,10 @@ func NewCustomJSONServerCodec(conn io.ReadWriteCloser) rpc.ServerCodec {
|
||||
}
|
||||
|
||||
type serverRequest struct {
|
||||
Method string `json:"method"`
|
||||
Params *json.RawMessage `json:"params"`
|
||||
Id *json.RawMessage `json:"id"`
|
||||
Method string `json:"method"`
|
||||
Params *json.RawMessage `json:"params"`
|
||||
Id *json.RawMessage `json:"id"`
|
||||
isApier bool
|
||||
}
|
||||
|
||||
func (r *serverRequest) reset() {
|
||||
@@ -88,8 +89,8 @@ func (c *jsonServerCodec) ReadRequestHeader(r *rpc.Request) error {
|
||||
}
|
||||
// in case we get a request with ApierV1 or ApierV2 we redirect
|
||||
// to Dispatcher to send it according to ArgDispatcher
|
||||
if strings.HasPrefix(c.req.Method, "ApierV") {
|
||||
r.ServiceMethod = DispatcherSv1SwitchApierVRequest
|
||||
if c.req.isApier = strings.HasPrefix(c.req.Method, ApierV); c.req.isApier {
|
||||
r.ServiceMethod = DispatcherSv1Apier
|
||||
} else {
|
||||
r.ServiceMethod = c.req.Method
|
||||
}
|
||||
@@ -116,7 +117,7 @@ func (c *jsonServerCodec) ReadRequestBody(x interface{}) error {
|
||||
}
|
||||
// following example from ReadRequestHeader in case we get ApierV1
|
||||
// or ApierV2 we compose the parameters
|
||||
if strings.HasPrefix(c.req.Method, "ApierV") {
|
||||
if c.req.isApier {
|
||||
cx := x.(*MethodParameters)
|
||||
cx.Method = c.req.Method
|
||||
var params [1]interface{}
|
||||
|
||||
@@ -262,7 +262,11 @@ func (s *Server) ServeHTTP(addr string, jsonRPCURL string, wsRPCURL string,
|
||||
s.Unlock()
|
||||
Logger.Info("<HTTP> enabling handler for WebSocket connections")
|
||||
wsHandler := websocket.Handler(func(ws *websocket.Conn) {
|
||||
jsonrpc.ServeConn(ws)
|
||||
if s.isDispatched {
|
||||
rpc.ServeCodec(NewCustomJSONServerCodec(ws))
|
||||
} else {
|
||||
jsonrpc.ServeConn(ws)
|
||||
}
|
||||
})
|
||||
if useBasicAuth {
|
||||
s.httpMux.HandleFunc(wsRPCURL, use(func(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -458,7 +462,11 @@ func (s *Server) ServeJSONTLS(addr, serverCrt, serverKey, caCert string,
|
||||
}
|
||||
continue
|
||||
}
|
||||
go jsonrpc.ServeConn(conn)
|
||||
if s.isDispatched {
|
||||
go rpc.ServeCodec(NewCustomJSONServerCodec(conn))
|
||||
} else {
|
||||
go jsonrpc.ServeConn(conn)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user