2017-11-26 10:15:51 +00:00
|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"git.loafle.net/commons_go/logging"
|
|
|
|
"git.loafle.net/commons_go/rpc"
|
|
|
|
"git.loafle.net/commons_go/rpc/protocol"
|
2017-12-01 07:29:32 +00:00
|
|
|
"git.loafle.net/commons_go/rpc/registry"
|
2017-11-26 10:15:51 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type ServletHandlers struct {
|
2017-11-28 16:24:16 +00:00
|
|
|
rpc.ServletHandlers
|
2017-11-26 10:15:51 +00:00
|
|
|
|
2017-12-01 07:48:40 +00:00
|
|
|
RPCInvoker registry.RPCInvoker
|
2017-11-26 10:15:51 +00:00
|
|
|
}
|
|
|
|
|
2017-11-28 16:24:16 +00:00
|
|
|
func (sh *ServletHandlers) Invoke(servletCTX rpc.ServletContext, requestCodec protocol.RegistryCodec) (result interface{}, err error) {
|
2017-12-01 07:48:40 +00:00
|
|
|
if !sh.RPCInvoker.HasMethod(requestCodec.Method()) {
|
2017-11-26 10:15:51 +00:00
|
|
|
return nil, fmt.Errorf("RPC Servlet Handler: Method[%s] is not exist", requestCodec.Method())
|
|
|
|
}
|
|
|
|
|
2017-12-01 07:48:40 +00:00
|
|
|
result, err = sh.RPCInvoker.Invoke(requestCodec)
|
2017-11-26 10:15:51 +00:00
|
|
|
if nil != err {
|
2017-11-28 02:55:25 +00:00
|
|
|
if params, pErr := requestCodec.Params(); nil != err {
|
|
|
|
logging.Logger().Error(fmt.Sprintf("RPC Servlet Handler: Read Param of Method[%s] returns error %v", requestCodec.Method(), pErr))
|
|
|
|
} else {
|
|
|
|
logging.Logger().Error(fmt.Sprintf("RPC Servlet Handler: Method[%s] params[%v] returns error %v", requestCodec.Method(), params, err))
|
|
|
|
}
|
2017-11-26 10:15:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2017-12-01 07:48:40 +00:00
|
|
|
func (sh *ServletHandlers) GetRPCInvoker() registry.RPCInvoker {
|
|
|
|
return sh.RPCInvoker
|
|
|
|
}
|
|
|
|
|
2017-11-26 10:15:51 +00:00
|
|
|
func (sh *ServletHandlers) Validate() {
|
2017-11-28 16:24:16 +00:00
|
|
|
sh.ServletHandlers.Validate()
|
2017-11-26 10:15:51 +00:00
|
|
|
|
2017-12-01 07:48:40 +00:00
|
|
|
if nil == sh.RPCInvoker {
|
|
|
|
logging.Logger().Panic(fmt.Sprintf("RPC Servlet Handler: RPC Invoker must be specified"))
|
2017-11-26 10:15:51 +00:00
|
|
|
}
|
|
|
|
}
|