在JavaWeb中集成BO报表

 

目录

 

一、获取LogenToken

二、使用LogonToken获取免登报表链接


       在JavaWeb系统中,可以通过BO的webservice来获取LogenToken,然后使用LogonToken来打开BO报表,这样就可以实现在系统中免登陆打开BO报表了。在本文的示例代码中使用到的工具有:HttpClient、fastjson。

一、获取LogenToken

       要想通过BO的webservice获取LogenToken,必须使用post请求,把用户名、密码、认证方式以json的格式放在body中,才能获取到LogonToken。示例代码如下:

    /**
     * 获取URL编码后的LogonToken
     * @param url  BO链接
     * @param username  用户名
     * @param password  密码
     * @param authType  认证类型
     * @return
     * @throws ClientProtocolException
     * @throws IOException
     */
    public static String getBoLogonToken(String url, String username, String password, String authType) throws ClientProtocolException, IOException {
        String token = "";

        /*
         * 1、构建json参数
         */
        JSONObject param = new JSONObject();
        param.put("username", username);
        param.put("password", password);
        param.put("auth", authType);

        /*
         * 2、使用HttpClient发送post请求,获取token
         */
        CloseableHttpClient httpClient = HttpClients.createDefault();
       
        /*
         * 2.1、构建POST请求
         */
        HttpPost httpPost = new HttpPost(url);
        StringEntity stringEntity = new StringEntity(param.toJSONString(), "UTF-8");
        stringEntity.setContentEncoding("UTF-8");
        httpPost.addHeader("Accept", "application/json");
        httpPost.addHeader("Content-Type", "application/json");
       
        /*
         * 2.2、发送请求,获取token
         */
        CloseableHttpResponse httpResponse = httpClient.execute(httpPost);
        HttpEntity httpEntity = httpResponse.getEntity();
        if (httpEntity != null) {
            JSONObject responseBody = JSONObject.parseObject(EntityUtils.toString(httpEntity));
            token = responseBody.getString("logonToken");
        }

        /*
         * 3、将获取到的Token进行URL编码
         */
        if (token != null && !"".equals(token)) {
            token = URLEncoder.encode(token, "UTF-8");
        }

        return token;
    }

 

二、使用LogonToken获取免登报表链接

         BO报表的普通链接为:http://IP:8080/BOE/OpenDocument/opendoc/openDocument.jsp?sIDType=CUID&iDocID=cuid。如果想免登查看BO报表的话,需要在该链接后面添加一个token参数,该参数的值为URL编码后的LogonToken。示例代码如下:

    /**
     * 获取免登陆的BO报表链接
     * @param ip  IP
     * @param cuid  BO报表ID
     * @param token  token
     * @return
     */
    public static String getBoReportUrlByToken(String ip, String cuid, String token) {
        StringBuilder url = new StringBuilder();

        // 拼接URL
        url.append("http://").append(ip).append(":8080")
            .append("/BOE/OpenDocument/opendoc/openDocument.jsp")
            .append("?sIDType=CUID")
            .append("&iDocID=").append(cuid)
            .append("&token=").append(token);

        return url.toString();
    }

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值