0
我正在使用Java腳本API來與Web項目進行Tableau集成。我已經使用commnad:tabadmin set wgserver.trusted_hosts「」和相應的命令在Tableau Server中配置了我的IP。但是我無法獲得票證,最終以-1結尾。我遵循了所有配置步驟。Tableau與Web項目的集成
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) {}
}
}
}
感謝您的回覆@merawalaid。我已經設置了目標參數,即時獲取HTML頁面作爲像{<!DOCTYPE html>
Humm ...所以它看起來像Tableau服務器沒有給您一個可信的令牌,並且正試圖將您重定向到它的登錄頁面。如果我在你的地方,我現在只是擺脫'client_ip',直到我有基本的令牌機制工作。另外,我會檢查用戶'raghu'是否具有在tableau服務器上配置到您指定的'target_site'的訪問權限。從代碼的角度來看,我無法找到你在做什麼錯,我有非常類似的代碼工作。所以這個問題一定是因爲一些配置問題。 – merawalaid
我忘了提到的一件事是tableau服務器是在其他一些網絡上,而web服務器是在我的local.Im試圖從我的本地訪問tableau服務器。是否有任何重定向設施? – veera