Jaspersoft:如何使用代理服务器调用可视化 js(外部到内部)
Jaspersoft : how to call visualize js using proxy server (external to internal)
我们正在使用 Jaspersoft 生成和检索报告。此服务器在内部网络中 运行(私有 IP 地址)。我们在 Web Api 中有一个代理服务器(外部服务器)来接收可视化 js 和所有其他请求。然后我们将这个请求转发给 Jaspersoft 服务器。我们的做法如下:
protected override async Task<HttpResponseMessage> SendAsync(
HttpRequestMessage request, CancellationToken cancellationToken) {
var uriBuilder = new UriBuilder(request.RequestUri);
uriBuilder.Host = "internal address";
request.RequestUri = uriBuilder.Uri;
if (request.Method == HttpMethod.Get) {
request.Content = null;
}
var response = await new HttpClient().SendAsync(request,
HttpCompletionOption.ResponseHeadersRead, cancellationToken);
return response;
}
此方法可以成功下载 visualize.js,但是当我们从 visualize.js 调用 visualize()
方法时,对于某些请求,jaspersoft 服务器返回 404-Not Found
。
我不确定为什么会出现错误。但我希望问题是您正在为每个请求创建 HttpClient
对象。您应该创建一次该对象并使用该对象。试试这个
//Initiate HttpClient object here
private HttpClient _client = new HttpClient();
protected override async Task<HttpResponseMessage> SendAsync(
HttpRequestMessage request, CancellationToken cancellationToken) {
var uriBuilder = new UriBuilder(request.RequestUri);
uriBuilder.Host = "internal address";
request.RequestUri = uriBuilder.Uri;
if (request.Method == HttpMethod.Get) {
request.Content = null;
}
var response = await _client.SendAsync(request,
HttpCompletionOption.ResponseHeadersRead, cancellationToken);
return response;
}
我们正在使用 Jaspersoft 生成和检索报告。此服务器在内部网络中 运行(私有 IP 地址)。我们在 Web Api 中有一个代理服务器(外部服务器)来接收可视化 js 和所有其他请求。然后我们将这个请求转发给 Jaspersoft 服务器。我们的做法如下:
protected override async Task<HttpResponseMessage> SendAsync(
HttpRequestMessage request, CancellationToken cancellationToken) {
var uriBuilder = new UriBuilder(request.RequestUri);
uriBuilder.Host = "internal address";
request.RequestUri = uriBuilder.Uri;
if (request.Method == HttpMethod.Get) {
request.Content = null;
}
var response = await new HttpClient().SendAsync(request,
HttpCompletionOption.ResponseHeadersRead, cancellationToken);
return response;
}
此方法可以成功下载 visualize.js,但是当我们从 visualize.js 调用 visualize()
方法时,对于某些请求,jaspersoft 服务器返回 404-Not Found
。
我不确定为什么会出现错误。但我希望问题是您正在为每个请求创建 HttpClient
对象。您应该创建一次该对象并使用该对象。试试这个
//Initiate HttpClient object here
private HttpClient _client = new HttpClient();
protected override async Task<HttpResponseMessage> SendAsync(
HttpRequestMessage request, CancellationToken cancellationToken) {
var uriBuilder = new UriBuilder(request.RequestUri);
uriBuilder.Host = "internal address";
request.RequestUri = uriBuilder.Uri;
if (request.Method == HttpMethod.Get) {
request.Content = null;
}
var response = await _client.SendAsync(request,
HttpCompletionOption.ResponseHeadersRead, cancellationToken);
return response;
}