Tableau 与 Web 项目集成

问题描述 投票:0回答:2

我正在使用 java script api 将 Tableau 与 Web 项目集成。我已经使用 commnad :tabadmin set wgserver.trusted_hosts "" 和相应的命令在 tableau 服务器中配置了我的 IP。但我无法获取票证,最终得到 -1。我已遵循所有配置步骤。

 public class TableauServlet extends javax.servlet.http.HttpServlet {
private static final long serialVersionUID = 1L;

public TableauServlet() {
    super();
}       

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    final String user = "raghu";
    final String wgserver = "103.xxx.xxx.xx";
    final String dst = "views/Regional/College?:iid=1";
    final String params = ":embed=yes&:toolbar=yes";

    String ticket = getTrustedTicket(wgserver, user, request.getRemoteAddr());

    if ( !ticket.equals("-1") ) {
        response.setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY);
        response.setHeader("Location", "http://" + wgserver + "/trusted/" + ticket + "/" + dst + "?" + params);
    }
    else
        // handle error
        throw new ServletException("Invalid ticket " + ticket);
}   

// the client_ip parameter isn't necessary to send in the POST unless you have
// wgserver.extended_trusted_ip_checking enabled (it's disabled by default)
private String getTrustedTicket(String wgserver, String user, String remoteAddr) 
    throws ServletException 
{
    OutputStreamWriter out = null;
    BufferedReader in = null;
    try {
        // Encode the parameters
        StringBuffer data = new StringBuffer();
        data.append(URLEncoder.encode("username", "UTF-8"));
        data.append("=");
        data.append(URLEncoder.encode(user, "UTF-8"));
        data.append("&");
        data.append(URLEncoder.encode("client_ip", "UTF-8"));
        data.append("=");
        data.append(URLEncoder.encode(remoteAddr, "UTF-8"));

        // Send the request
        URL url = new URL("http://" + wgserver + "/trusted");
        URLConnection conn = url.openConnection();
        conn.setDoOutput(true);
        out = new OutputStreamWriter(conn.getOutputStream());
        out.write(data.toString());
        out.flush();

        // Read the response
        StringBuffer rsp = new StringBuffer();
        in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
        String line;
        while ( (line = in.readLine()) != null) {
            rsp.append(line);
        }

        return rsp.toString();

    } catch (Exception e) {
        throw new ServletException(e);
    }
    finally {
        try {
            if (in != null) in.close();
            if (out != null) out.close();
        }
        catch (IOException e) {}
    }
}

}

javascript java tableau-api
2个回答
0
投票

我认为您在获得受信任票证的网址中缺少“target_site”参数,如果您的默认站点中没有“views/Regional/College”,则需要该参数。

我也因“-1”票而经历了很多挫折! 您可以尝试的一件事是将 Web 服务器 IP 添加到 tableau 的 trust_hosts 后重新启动 tableau 服务器。

我们最终做的另一件事是将Web服务器的内部IP和外部IP添加到tableau上的trusted_hosts中。由于您使用 103.xxx.xxx.xx 作为 tableau 服务器,我假设两台服务器位于同一内部网络上。如果其他一切都失败了,你可以尝试一下。

我的代码与你的几乎完全相同并且工作正常。因此,如果您的问题仍然存在,则一定与配置有关。 这是我的代码:

private String getAuthenticationTicket(String tableauServerUserName,String tableauServerUrl, String targetSite) {

        OutputStreamWriter out = null;
        BufferedReader in = null;
        try {
            StringBuffer data = new StringBuffer();
            data.append(URLEncoder.encode("username", Constant.UTF_8));
            data.append("=");
            data.append(URLEncoder.encode(tableauServerUserName, Constant.UTF_8));
            data.append("&");
            data.append(URLEncoder.encode("target_site", Constant.UTF_8));
            data.append("=");
            data.append(URLEncoder.encode(targetSite, Constant.UTF_8));
            URL url = new URL(tableauServerUrl + "/" + "trusted");

            URLConnection conn = url.openConnection();
            conn.setDoOutput(true);
            out = new OutputStreamWriter(conn.getOutputStream());
            out.write(data.toString());
            out.flush();
            StringBuffer rsp = new StringBuffer();
            in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
            String line;
            while ((line = in.readLine()) != null) {
                rsp.append(line);
            }
            return rsp.toString();
        } catch (Exception ex) {
            //log stuff, handle error
            return null;
        } finally {
            try {
                if (in != null)
                    in.close();
                if (out != null)
                    out.close();
            } catch (IOException ex) {
               //log stuff, handle error
            }
        }
    }

0
投票

您可以使用 Odoo-Tableau 连接器将 Tableau Desktop 与 Odoo ERP 集成。我亲自为我的项目实施了这个解决方案。

https://techfinna.com/odoo-tableau-connector/

© www.soinside.com 2019 - 2024. All rights reserved.