[英]Getting data from one tomcat server to another tomcat server
我正在使用saiku服务器进行数据分析,该服务器在一个tomcat中运行,而我的spring boot应用程序在另一个tomcat中运行,我想将数据从saiku服务器获取到我的spring boot应用程序中,以便从一个tomcat服务器生成图表(即) tomcat server.i出现如下错误
这是我的代码,用于将数据从saiku获取到我的springboot应用程序
<script type="text/javascript" data-ng-hide=true>
var myClient = new SaikuClient({
server: "http://localhost:8080/saiku",
path: "/rest/saiku/embed",
user: "admin",
password: "admin"
});
myClient.execute({
file: "/homes/home:admin/sample_reports/.saiku",
htmlObject: "#saiku2",
render: "chart",
mode: "line",
chartDefinition: {
width: 560,
colors: ['grey','red','blue'],
extensionPoints: {
legend: true,
legendShape: 'circle',
legendSize: {width: '100%'},
legendLabel_textStyle: "#990000",
legendFont: 'normal 11px "Open Sans"'
}
},
zoom: true
});
function displayChart(path, htmlDiv){
myClient.execute({
file: path,
htmlObject: "#"+htmlDiv,
render: "chart",
mode: "line",
chartDefinition: {
width: 560,
colors: ['grey','red','blue'],
extensionPoints: {
legend: true,
legendShape: 'circle',
legendSize: {width: '100%'},
legendLabel_textStyle: "#990000",
legendFont: 'normal 11px "Open Sans"'
}
},
zoom: true
});
}
$(document).ready(function(){
console.log("Hello world")
});
$.get( "http://localhost:8080/saiku/rest/saiku/api/repository?type=saiku,sdb", function( data ) {
console.log(data);
console.log(data.length);
var response = (data);
for(var i=0;i<data.length;i++){
console.log("JSON ==>"+data[i].type);
// get reports only under homes
if(data[i].type=="FOLDER" && data[i].name=="homes"){
console.log("data[i].repoObjects ==>"+data[i].repoObjects)
// for file only we generate the saiku reports
if(data[i].repoObjects && data[i].repoObjects.length>0){
console.log("i am inside"+data[i].repoObjects.length)
var arr = [];
arr = (data[i].repoObjects);
for (var k=0;k<arr.length;k++){
console.log("repo ==>"+arr[k].name);
if(arr[k].name=="home:admin"){
// retrieve all reports under home:admin folder
console.log("repo ==>"+JSON.stringify(arr[k].repoObjects[0].repoObjects));
// arr[k] is the home:admin folder. iterate all the files
for(var z=0;z<arr[k].repoObjects.length;z++){
// this is now the list of files and folders under homes/home:admin
if(arr[k].repoObjects[z]){
var folderObjects =new Array(arr[k].repoObjects[z].repoObjects);
console.log(arr[k].repoObjects[z].repoObjects.length)
for(var x=0;x<arr[k].repoObjects[z].repoObjects.length;x++){
console.log(x)
if(arr[k].repoObjects[z].repoObjects[x]){
console.log(arr[k].repoObjects[z].repoObjects[x].path)
displayChart(arr[k].repoObjects[z].repoObjects[x].path,"saiku"+x);
}
}
}
}
}
}
}
}
}
});
</script>
我的错误是
XMLHttpRequest cannot load http://localhost:8080/saiku/rest/saiku/embed/export/saiku/json?formatter=fl…ned&file=%2Fhomes%2Fhome%3Aadmin%2Fsample_reports%2F.saiku&_=1470641532009. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8081' is therefore not allowed access. The response had HTTP status code 401
我从未使用过Saiku服务器,但是也许我可以给您一个有关为什么会发生此错误的一般想法。
您应该禁用访问控制或正确实施它。
这里有关于正确实现Spring功能的详尽指南: https : //spring.io/guides/gs/rest-service-cors/
另外,您还应该在此处查找什么是“跨源资源共享”以及为什么需要它: https : //en.wikipedia.org/wiki/Cross-origin_resource_sharing
如果您的@SpringBootApplication类扩展了WebMvcAutoConfigurationAdapter,则可以像这样禁用CORS:
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**");
}
您也可以直接在Tomcat中禁用CORS: http : //enable-cors.org/server_tomcat.html
但是在执行此操作之前,请先阅读CORS并了解为什么需要使用它,以及禁用它会带来什么后果。
您需要使用saiku rest API进行登录。 例如:
$ .post(“ http:// localhost:8080 / saiku / rest / saiku / session / ”,{用户名:“ admin”,密码:“ admin”});
检查以下内容: https : //groups.google.com/a/saiku.meteorite.bi/forum/#!msg/user/djic697fUbk/IPWlTyazAwAJ
如果saiku在其他tomcat上运行,则可以在saiku tomcat web.xml中使用CorsFilter
用户Cors仔细...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.