I have some problem when proceed downloading or uploading file (WebClient.DownloadFileAsync|UploadFileAsync or by HttpWebRequest) and simultaneously calling SignalR-hub methods:
SignalR calls were stopped until file loading finished.
It seems like that: all signalr calls enqueuing. All enqueued calls are performed further (after file loading).
My code fragment:
hubProxy.Invoke("TraceDocumentUploadingRequest", callerId, fileName, "File loading started ", 0);
DownloadFileByKey(fileKey, (progressPercentage, bytesSent) => { hubProxy.Invoke("TraceDocumentUploadingRequest", callerId, fileName, "File loading in progress", progressPercentage); });
hubProxy.Invoke("TraceDocumentUploadingRequest", callerId, fileName, "File loading finished", 100);
Second "TraceDocumentUploadingRequest" hub method call (in file load handler) will be executed on the hub after file downloading completion.
File load handler executes both in current thread or in another (related on DownloadFileByKey method realization) - result is the same.
How I can avoid this behavior and force hub-method calls at the right time?
To summarize David Fowl's comments, the issue was a bug in SignalR version 1.1.3 but fixed in later version. Specifically version 2.0.0
Related
In my robot framework script I use the browser library to open a webpage and click on a button to get a receipt in PDF.
The button does not contain the direct link to the PDF: when you click the button, it opens a new page and after ~0.5 second the page returns a PDF file generated by the server.
I was not able to get and access the generated file in the Robot Framework script.
My tentative #1
I thought the PDF file could be captured by downloading it with a promise but it failed:
Click button.okButton
Switch Page NEW
${dl_promise} Promise To Wait For Download ./${SUITE_NAME}/downloads
${file_obj}= Wait For ${dl_promise}
File Should Exist ${file_obj}[saveAs]
Failure:
Tentative #1bis
${dl_promise} Promise To Wait For Download ./${SUITE_NAME}/downloads
Click button.okButton
Switch Page NEW
${file_obj}= Wait For ${dl_promise}
File Should Exist ${file_obj}[saveAs]
Same failure (TimeoutError: page.waitForEvent: Timeout 20000ms exceeded while waiting for event "download")
My tentative #2
The new page source code is the following:
<html><head></head><body><embed name="9AF27FA0E167C8860EB51FD926BE211B" src="about:blank" type="application/pdf" internalid="9AF27FA0E167C8860EB51FD926BE211B"></body></html>
I thought it is a local storage ID, am I right? So I tried the following:
Click button.okButton
Switch Page NEW
${sourceCode} = Get Page Source
${storageItem} = Get Regexp Matches ${sourceCode} (?<=(internalid="))(.*)(?=(">))
${myPDFfile} = Local Storage Get Item ${storageItem}
Log ${myPDFfile}
But seems it does not work:
... any idea how I should proceed? Thanks so much for your help and suggestions.
Keyword Promise To Wait For Download should be before triggering action. So the logic should be the following:
Promise
Trigger download
Wait for promise
I'm using milton, and my upload code as follows:
#PutChild
#Transactional
public FileContentItem uploadFile(FolderContentItem parent, String name, byte[] bytes){
String traceId = UuidGenUtil.createUuid();
try {
QUERY_LOGGER.info("[uploadFile][NetdiskController],action=Request, name={}, size={},traceId={}",name,bytes.length,traceId);
In windows, i can upload file successfully, but with Mac Finder, the length of bytes is always 0, and the error as follow:
The Finder can't complete the operation because some data in "Shot.png" can't be read or written (Error code -36)
Anyone know why? Thanks
Update: I try ForkLift webdav client in mac and can upload file successfully
The problem is that mac finder sends first request for creating new file without any byte
After it - call LOCK, which is not available for Dav Level 1, that's why you have bad response from server and mac stop uploading a file. This method availiable only for Dav level 2, so you have to get enterprise license of milton to make it work
After Locking object Finder uploads the file
After - calls UNLOCK method
SO if you want to use mac finder for webdav in milton you have several options:
Get the trial enterprise license and look into this example:https://github.com/miltonio/milton2/tree/master/examples/milton-anno-ref
Realize these methods by yourself by webdav specs
Mock it - extend from MiltonFilter or look into MyOwnServlet in example and in method doFilter/service write something like this:
//mock method, do not use it in production!
HttpServletRequest request = (HttpServletRequest)req;
HttpServletResponse response = (HttpServletResponse) resp;
if(request.getMethod().equals("LOCK")){
response.setStatus(200);
response.addHeader("Lock-Token", "<opaquelocktoken:e71d4fae-5dec-22d6-fea5-00a0c91e6be4>");
} else if(request.getMethod().equals("UNLOCK")){
response.setStatus(204);
}else {
doMiltonProcessing((HttpServletRequest) req, (HttpServletResponse) resp);
}
I've checked this code working in the examble by link above: make in web.xml method serving by MyOwnServlet, disable authentication in init by implementing empty security manager, set controller packages to scan "com.mycompany"
p.s. to build the example project I've to delete milton client dependency from pom.xml file
How to wait for the page to load like say for 5 seconds.
In my program the sites wait for browser checks for 5 seconds before showing the content, Hence I want my http.get(url) function to wait for at least 5 seconds.
Without wait it doesn't show any content.
Thanks.
Based upon your comments, I now understand what you are trying to do and have modified this answer.
Unfortunately, there is no way to configure Meteor HTTP (which really uses
request to make the service call) to "wait" after the request has been initiated before obtaining a response. The best thing for you to do is to check out PhantomJS. It is a headless browser that you can use to load and render the page and then access dynamically generated content via javascript.
Check out this answer for a brief PhantomJS example and you can use the gadicohen:phantomjs package to install for meteor.
On a side note, it can still be useful to use the below function to pause execution in Meteor, but of course this is not useful for what you are trying to solve.
Meteor._sleepForMs(5000); // pause execution for 5 seconds
the http package is built upon npm's request package. You can do it as such with the request package directly:
var request = require('request');
var reqOptions = {
url: path,
method: 'GET',
encoding: "utf8",
jar: false,
timeout: null,
body: null,
followRedirect: null,
followAllRedirects: null,
headers: {},
time:true
};
request(reqOptions, function(error, response, body) {
console.log("time: "+response.elapsedTime)
console.log(body.toString()); //res.content returned by http.get
});
require('sleep').sleep(5); //synchronously slowing execution
You might also be able to do the same by setting {time:true} in the npmOptions parameter of the http call and then synchronously
I'm using SignalR but have run into a problem. When a connection is started in one browser window and then a user logs in in another browser window the User identity is changed (this causes the error 'System.InvalidOperationException: Unrecognized user identity. The user identity cannot change during an active SignalR connection' on the server when a method is called on the hub.
I'm using this code on the client:
proxy.server.analyze(content)
.done(function () {
console.log('Success!');
})
.always(function () {
console.log('This is always called!');
})
.fail(function (error) {
console.log('This is never called!');
});
When I'm seeing errors on the server the fail function is never being called so there appears to be no way on the client to handle this problem and stop and start the connection.
So is there a "best practice" way of handling this case? How can I detect on the client that the user identity has changed in another browser window and stop and re-start the connection?
This is a known issue.
It is fixed in the next release. Here's the issue that ended up also fixing your issue: https://github.com/SignalR/SignalR/issues/2106.
Lastly, in the next release (0.2.0) what will happen is the connection will throw an error and stop itself. Therefore you'll be able to handle your case via either the error handler or you can of course you can tie into the "disconnected" event.
If you're willing to try a pre-releases you can always pull from the offical source or webstack nightly (http://www.myget.org/F/aspnetwebstacknightly/)
to download a console returns the following error:
Frame load interrupted by policy change
Example:
Start Download
Console Preview:
Should I configure something in the Compiler or QWebSettings?
I discovered.
In conventional Webkit browsers, the place to download the console shows how the request canceled, so before turning to "download manager" of the browser the request should be canceled.
solution:
//replace [QWebView] by your WebView
connect([QWebView]->page(), SIGNAL(unsupportedContent(QNetworkReply*)),
this, SLOT(downloadContent(QNetworkReply*)));
...
void [main class]::downloadContent(QNetworkReply *reply){
//Replace "[main class]" by "Class" having the signs used in WebView.
[QWebView]->stop();
//solution: stop loading --replace [QWebView] by your WebView
/*function to donwload*/
}
Edit: hard to tell without a proper backtrace I requested in the comments, but it looks like the warning might actually be harmless.
Original:
That's because the QWebView doesn't know what to do with your app.exe file -- it's not an HTML page or a text/plain document or a supported image, after all. The QWebView class is not a web browser; you apparently want to start a download of some file, but there's no full-blown download manager in that class. You will have to provide your own code for this -- the code will have to ask for a proper location to save it, etc.
You can start with QWebPage::setLinkDelegationPolicy and handle this particular click yourself.