Pentaho BIServer 调用API添加用户

官网API文档地址:  https://help.pentaho.com/Documentation/8.3/Developer_center

官网文档写得比较简略,建议将源码下载下来,对比着看,以源码中的调用接口示例作为参考

调用api提供的接口创建用户成功之后会直接在Home下生成文件夹,路径即为/home/<创建用户名>

我用的版本为: pentaho-server-ce-7.1.0.0-12

api: /pentaho/api/userroledao/createUser

代码如下:

public class HttpUtils {

    public static String doPutForPentaho(String url, String data, int timeout){
    	CloseableHttpClient httpClient =  HttpClients.createDefault();
    	try{
    		
	        //超时设置
	        RequestConfig requestConfig =  RequestConfig.custom().setConnectTimeout(timeout) //连接超时
	                .setConnectionRequestTimeout(timeout)//请求超时
	                .setSocketTimeout(timeout)
	                .setRedirectsEnabled(true)  //允许自动重定向
	                .build();
	
	
	        HttpPut httpPut  = new HttpPut(url);
	        httpPut.setConfig(requestConfig);
	        httpPut.addHeader("Content-Type", "application/json");
	
	        
	        Map<String, String> headers = new HashMap<> ();
	        headers.put("Authorization", "Basic " + Base64.encodeBase64String("Admin:password".getBytes()));
	        for (Map.Entry<String, String> e : headers.entrySet()) {
	        	httpPut.addHeader(e.getKey(), e.getValue());
	        }
	        
	        if(data != null && data instanceof  String){ //使用字符串传参
	            StringEntity stringEntity = new StringEntity(data,"UTF-8");
	            httpPut.setEntity(stringEntity);
	        }

                CloseableHttpResponse httpResponse = httpClient.execute(httpPut);
                HttpEntity httpEntity = httpResponse.getEntity();
                if(httpResponse.getStatusLine().getStatusCode() == 200){
                    String result = EntityUtils.toString(httpEntity);
                    return result;
                }

        }catch (Exception e){
            e.printStackTrace();
        }finally {
            try{
                httpClient.close();
            }catch (Exception e){
                e.printStackTrace();
            }
        }

        return null;

    }    

}

测试方法 : 

public String test () {
	Map<String, String> param = new HashMap<> ();
	JSONObject o = new JSONObject ();
	o.put("userName", "leo");
	o.put("password", "123456");
	String rlt = HttpUtils.doPutForPentaho("http://192.168.129.138:8080/pentaho/api/userroledao/createUser", o.toString(), 2000);
}

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值