1717import javax .servlet .http .Cookie ;
1818import javax .servlet .http .HttpServletRequest ;
1919import java .io .IOException ;
20+ import java .net .URI ;
2021import java .net .URISyntaxException ;
2122import java .util .Date ;
2223
@@ -34,7 +35,7 @@ public static String getDbs(String ticketId) {
3435 HttpGet httpGet = new HttpGet (DATABASE_URL );
3536 BasicClientCookie cookie = new BasicClientCookie (CommonConfig .TICKET_ID_STRING ().getValue (), ticketId );
3637 cookie .setVersion (0 );
37- cookie .setDomain (CommonConfig . GATEWAY_IP (). getValue ( ));
38+ cookie .setDomain (getIpFromUrl ( GATEWAY_URL ));
3839 cookie .setPath ("/" );
3940 cookie .setExpiryDate (new Date (System .currentTimeMillis () + 1000 * 60 * 60 * 24 * 30L ));
4041 cookieStore .addCookie (cookie );
@@ -59,7 +60,7 @@ public static String getTables(String ticketId, String hiveDBName) {
5960 HttpGet httpGet = new HttpGet (uriBuilder .build ());
6061 BasicClientCookie cookie = new BasicClientCookie (CommonConfig .TICKET_ID_STRING ().getValue (), ticketId );
6162 cookie .setVersion (0 );
62- cookie .setDomain (CommonConfig . GATEWAY_IP (). getValue ( ));
63+ cookie .setDomain (getIpFromUrl ( GATEWAY_URL ));
6364 cookie .setPath ("/" );
6465 cookieStore .addCookie (cookie );
6566 CloseableHttpResponse response = httpClient .execute (httpGet );
@@ -84,7 +85,7 @@ public static String getColumns(String dbName, String tableName, String ticketId
8485 HttpGet httpGet = new HttpGet (uriBuilder .build ());
8586 BasicClientCookie cookie = new BasicClientCookie (CommonConfig .TICKET_ID_STRING ().getValue (), ticketId );
8687 cookie .setVersion (0 );
87- cookie .setDomain (CommonConfig . GATEWAY_IP (). getValue ( ));
88+ cookie .setDomain (getIpFromUrl ( GATEWAY_URL ));
8889 cookie .setPath ("/" );
8990 cookieStore .addCookie (cookie );
9091 CloseableHttpResponse response = httpClient .execute (httpGet );
@@ -109,6 +110,18 @@ public static String getUserTicketId(HttpServletRequest request) {
109110 return ticketId ;
110111 }
111112
113+ // http://127.0.0.1:9001
114+ private static String getIpFromUrl (String url ) {
115+ URI uri = URI .create (url );
116+ String ip = "" ;
117+ int port = 0 ;
118+ if (null != null ) {
119+ ip = uri .getHost ();
120+ port = uri .getPort ();
121+ }
122+ return ip ;
123+ }
124+
112125}
113126
114127
0 commit comments