@@ -1001,12 +1001,35 @@ public JSONObject putBalance(@RequestBody String request, HttpSession session) {
1001
1001
@ SuppressWarnings ("unchecked" )
1002
1002
@ RequestMapping (value = "/delegate" )
1003
1003
public String delegate (
1004
+ @ RequestParam (value = "$_type" , required = false ) String type ,
1004
1005
@ RequestParam (value = "$_except_headers" , required = false ) String exceptHeaders ,
1005
1006
@ RequestParam ("$_delegate_url" ) String url ,
1006
1007
@ RequestBody (required = false ) String body ,
1007
1008
HttpMethod method , HttpSession session
1008
1009
) {
1009
1010
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
+
1010
1033
Enumeration <String > names = request .getHeaderNames ();
1011
1034
HttpHeaders headers = null ;
1012
1035
String name ;
@@ -1059,6 +1082,7 @@ else if (ADD_COOKIE.toLowerCase().equals(name.toLowerCase())) {
1059
1082
1060
1083
if (map != null ) {
1061
1084
map = new HashMap <>(map ); //解决 throw exception: Unmodified Map
1085
+ map .remove ("$_type" );
1062
1086
map .remove ("$_except_headers" );
1063
1087
map .remove ("$_delegate_url" );
1064
1088
0 commit comments