@@ -1001,12 +1001,35 @@ public JSONObject putBalance(@RequestBody String request, HttpSession session) {
10011001 @ SuppressWarnings ("unchecked" )
10021002 @ RequestMapping (value = "/delegate" )
10031003 public String delegate (
1004+ @ RequestParam (value = "$_type" , required = false ) String type ,
10041005 @ RequestParam (value = "$_except_headers" , required = false ) String exceptHeaders ,
10051006 @ RequestParam ("$_delegate_url" ) String url ,
10061007 @ RequestBody (required = false ) String body ,
10071008 HttpMethod method , HttpSession session
10081009 ) {
10091010
1011+ if ("GRPC" .equals (type )) {
1012+ int index = url .indexOf ("://" );
1013+ String endpoint = index < 0 ? url : url .substring (index + 3 );
1014+
1015+ index = endpoint .indexOf ("/" );
1016+ String remoteMethod = index < 0 ? "" : endpoint .substring (index );
1017+
1018+ url = "http://localhost:50050" + remoteMethod ;
1019+
1020+
1021+ JSONObject obj = JSON .parseObject (body );
1022+ if (obj == null ) {
1023+ obj = new JSONObject (true );
1024+ }
1025+ if (obj .get ("endpoint" ) == null ) {
1026+ endpoint = index < 0 ? endpoint : endpoint .substring (0 , index );
1027+ obj .put ("endpoint" , endpoint );
1028+ }
1029+
1030+ body = obj .toJSONString ();
1031+ }
1032+
10101033 Enumeration <String > names = request .getHeaderNames ();
10111034 HttpHeaders headers = null ;
10121035 String name ;
@@ -1059,6 +1082,7 @@ else if (ADD_COOKIE.toLowerCase().equals(name.toLowerCase())) {
10591082
10601083 if (map != null ) {
10611084 map = new HashMap <>(map ); //解决 throw exception: Unmodified Map
1085+ map .remove ("$_type" );
10621086 map .remove ("$_except_headers" );
10631087 map .remove ("$_delegate_url" );
10641088
0 commit comments