runtime transferred through the interface kms

runtime transferred through the interface kms

Mainly through kms accessToken accessible interface to pick up tools in which accessToken, the following is an example of
adding methods documentUtil, according to the request acquisition accessToken

//获取accessToken
public String getAccessToken(HttpServletRequest request){
    String accessToken="";
    request.getCookies();
    Cookie[] cookies = request.getCookies();
    for (Cookie cookie : cookies) {
        String name = cookie.getName();
        if ("accessToken".equals(name)) {
            accessToken =  cookie.getValue();
            break;
        }
    }
    return accessToken;
}

Request interface:

	public String testOne(String accessToken) throws Exception{
		String response = null;
		String url="http://192.168.10.136:8888/kms/kms/teams/serialNumber";

		System.out.println("url: " + url);
		try {
			CloseableHttpClient httpclient = null;
			CloseableHttpResponse httpresponse = null;
			try {
				httpclient = HttpClients.createDefault();
				HttpGet httpGet = new HttpGet(url);
				httpGet.addHeader("accessToken", accessToken);

				httpresponse = httpclient.execute(httpGet);
				response = EntityUtils.toString(httpresponse.getEntity());
				JSONObject jsonObject = JSONObject.fromObject(response.toString());
				System.out.println(jsonObject.toString());
			} finally {
				if (httpclient != null) {
					httpclient.close();
				}
				if (httpresponse != null) {
					httpresponse.close();
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

Script calls

(function(){  
     var request = $WEB.getParamsTable().getHttpRequest(); 
     var util = new Packages.cn.myapps.runtime.dynaform.document.DocumentUtil(); 
     var accessToken = util.getAccessToken(request); 
     var number = util.testOne(accessToken);
     return number; 
  })()
Published 20 original articles · won praise 0 · Views 62

Guess you like

Origin blog.csdn.net/qq_42745404/article/details/105019740