rpc tunnel & delete rpc.server.map
This commit is contained in:
parent
0c0c03e2ca
commit
d6f0047632
|
@ -109,10 +109,14 @@ class Client
|
|||
try {
|
||||
$body = \GuzzleHttp\json_decode($resp->getBody(), true);
|
||||
app('rpc.logger')->info("client_response",$body);
|
||||
if (empty($body)) {
|
||||
throw new RpcServerException('http response empty', 500);
|
||||
}
|
||||
if (isset($body['error']) && isset($body['error']['code']) && isset($body['error']['message'])) {
|
||||
$message = is_array($body['error']['message']) ? json_encode($body['error']['message']) : $body['error']['message'];
|
||||
throw new RpcServerException($message, $body['error']['code']);
|
||||
}
|
||||
|
||||
return $body['result'];
|
||||
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
|
|
44
src/Middleware/TunnelMiddleware.php
Normal file
44
src/Middleware/TunnelMiddleware.php
Normal file
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
namespace JsonRpc\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
|
||||
/**
|
||||
* Class TunnelMiddleware
|
||||
* @package JsonRpc\Middleware
|
||||
*/
|
||||
class TunnelMiddleware
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
// Pre-Middleware Action
|
||||
$response = $next($request);
|
||||
|
||||
// Post-Middleware Action
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
public function terminate($request, $response)
|
||||
{
|
||||
//过滤tool返回结果
|
||||
if ($response instanceof JsonResponse)
|
||||
{
|
||||
$content = $response->getOriginalContent();
|
||||
if (isset($content['error'])){
|
||||
app('rpc.logger')->info('rpc tunnel', [$content['error']['code']]);
|
||||
} else {
|
||||
app('rpc.logger')->info('rpc tunnel', [200]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -8,7 +8,7 @@ use JsonRpc\Exception\RpcServerException;
|
|||
use JsonRpc\Server\JsonRpcServer;
|
||||
|
||||
|
||||
class ClientServiceProvider extends ServiceProvider
|
||||
class ClientServiceProvider extends LoggerServiceProvider
|
||||
{
|
||||
|
||||
|
||||
|
@ -17,6 +17,7 @@ class ClientServiceProvider extends ServiceProvider
|
|||
*/
|
||||
public function register()
|
||||
{
|
||||
parent::register();
|
||||
$this->app->configure('rpc');
|
||||
$config = config('rpc');
|
||||
if (!is_array($config)) {
|
||||
|
|
|
@ -2,8 +2,6 @@
|
|||
|
||||
namespace JsonRpc\Providers;
|
||||
|
||||
use App\Http\Middleware\JsonRpc;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use JsonRpc\Exception\RpcServerException;
|
||||
use JsonRpc\Middleware\Security;
|
||||
use JsonRpc\Server\JsonRpcDoc;
|
||||
|
@ -11,7 +9,7 @@ use JsonRpc\Server\JsonRpcServer;
|
|||
use JsonRpc\Server\JsonRpcTool;
|
||||
use Laravel\Lumen\Application;
|
||||
|
||||
class LumenServerServiceProvider extends ServiceProvider
|
||||
class LumenServerServiceProvider extends LoggerServiceProvider
|
||||
{
|
||||
|
||||
/**
|
||||
|
@ -34,6 +32,8 @@ class LumenServerServiceProvider extends ServiceProvider
|
|||
|
||||
$this->app->configure('rpc');
|
||||
$config = config('rpc.server');
|
||||
$map = require_once $config['map'];
|
||||
$config['map'] = $map;
|
||||
if (!is_array($config)) {
|
||||
throw new RpcServerException("Application's Rpc Server Config Undefind", 500);
|
||||
}
|
||||
|
@ -71,10 +71,6 @@ class LumenServerServiceProvider extends ServiceProvider
|
|||
*/
|
||||
public function register()
|
||||
{
|
||||
$this->app->configure('rpc');
|
||||
$config = config('rpc.server');
|
||||
$this->app->singleton('rpc.server.map', function() use($config){
|
||||
return include_once $config['map'];
|
||||
});
|
||||
parent::register();
|
||||
}
|
||||
}
|
|
@ -26,7 +26,7 @@ class JsonRpcServer extends JsonRpcBase
|
|||
{
|
||||
$this->config = $config;
|
||||
$this->request = function_exists('app') ? app('request') : Request::capture();
|
||||
$this->map = app('rpc.server.map');
|
||||
$this->map = $config['map'];
|
||||
}
|
||||
|
||||
public function handler()
|
||||
|
|
|
@ -74,7 +74,7 @@ class JsonRpcTool
|
|||
|
||||
public function getMethods()
|
||||
{
|
||||
return app('rpc.server.map');
|
||||
return $this->config['map'];
|
||||
}
|
||||
|
||||
protected function desc($class, $method)
|
||||
|
|
Loading…
Reference in New Issue
Block a user