I am working in a client-server application(web start) which is started by url http:\[ip of server]:[port]. It loads index.html in the browser and main application pops up in another window and here we have several option to see/perform status/action.
Recently i got an issue of server status being displayed as unknown which is default, but it after loading application it should be loaded. I found the cause of it, that method to display server status being executed at start, so i use while loop to check if application loads, then i executed that method. It worked.
But if i exit the pop up(main application) and refresh the url in main browser window, application pops up successfully but without server status, There is nothing about server status. It leads me to think that while cut the pop up, serverStatus class did not unload.
I tried to learn about class loader but did not get anything and not able to find anything in application source code about loading/unloading of a class.
Could someone please guide or give reference to a study materiel that could solve my problem.
Please pardon me if i am not clear in asking the exact question and please ask if more information is required. Thanks in Advance
The changed code is here:
#Override
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{
PrintWriter out = new PrintWriter(
new OutputStreamWriter(response.getOutputStream(), "UTF-8"));
synchronized(this){
while(!notCompleted){
Thraed.sleep(100)}
out.println("<LABEL><B>" + discoveryStatusLabel_ +
" :</B></LABEL> <SPAN ID='DiscoveryStatus'>" +
discoveryStatus_ + "</SPAN>");}
}
where i added the while loop, and notCompleted is variable to check if application loaded fully.
Note: There are more code in doGet() and synchronized block apart from this.
Related
I want to close my Android application with a method, but it should be shown a custom message (which I define for myself).
everything I found yet was "How to close my application" and I got more than 10 ways to close my application but I haven't found a way to set a custom message.
At the moment if my app crashes something like this appears:
[APPNAME] has been stopped
I want something like this
Congratulations! You found a bug, please submit it.
Is there even a way to do that? All methods I found just closed all activities or just forced an unresolveable error.
I don't think you need some code from me, but if you do, tell me.
(Language should be java and javascript/jQuery should be avoided)
You could try making a static stop method:
public static void stop(String message) {
Log.d(message);
System.exit(0);
}
I am using the wicket framework.
I have a requirement to send to the client browser several individual files (a zip file is not relevant).
I have added to my page an AJAXDownload class that extends AbstractAjaxBehavior - a solution for sending files to the client like this:
download = new AJAXDownload(){
#Override
protected IResourceStream getResourceStream(){
return new FileResourceStream(file){
#Override
public void close() throws IOException {
super.close();
file.delete();
}
};
}};
add(download);
At some other point in my code I am trying to initiate the download of several files to the client using an ajax request whilst looping through an arraylist of files and then each time triggering the AJAXDownload:
ArrayList<File> labelList = printLabels();
for(int i=0; i<labelList.size(); i++){
file = labelList.get(i);
//initiate the download
download.initiate(target);
}
However, it is only sending just one of these files to the client. I have checked and the files have definitely been created on the server side. But only one is of them is being sent to the client.
Can anyone give me an idea what I am doing wrong?
Thanks
You are doing everything correct!
I don't know how to solve your problem but I'll try to explain what happens so someone else could help:
The Ajax response has several entries like:
<evaluate>document.location=/some/path/to/a/file</evaluate>
wicket-ajax.js just loops over the evaluations and executes them. If there is one entry then everything is OK - you have the file downloaded. But if there are more then the browser receives several requests for changing its location in very short time. Apparently it drops all but one of them.
An obvious solution would be to use callbacks/promises - when a download finishes then trigger the next one. The problem is that there is no way how to receive a notification from the browser that such download finished. Or at least I don't know about it.
One can roll a solution based on timeouts (i.e. setTimeout) but it would be error prone.
I hope this information is sufficient for someone else to give you the solution!
Is it possible to use getPage().setLocation(...) from the init() method of UI. I have to redirect user to external site, under certain conditions. So far, it does not work (Vaadin 7.0.2).
Here is the code example:
#Override
public void init(VaadinRequest request) {
if (myCondition)
getPage().setLocation("http://www.externalsite.com");
else {
....
}
}
That's strange that it isn't working for you... setLocation is all you need. Here is a working version: VaadinLocationRedirect. mvn package will build the widgetset, mvn jetty:run will host it. Let us know what the problem was if you figure it out.
Found my problem. I used old version of WidgetSet, which was left from 6.X times, and was not re-compiled with Vaadin 7. After I fixed it - it works fine.
Looks like you can call the open( URL ) method of the Window object to open another URL in the same or a new browser window to achieve the redirection to an external site.
As an alternative you can set the exit URL for the application via application.setExitUrl() call and then close the application by calling application.close() - your application session will be closed and browser redirected to the specified address.
I'm making a web application for blackberry and I really need the current URL
In the description of documentUrl, it says
This method will return the URL of the currently loaded page of this BrowserField Instance
My code is:
_bf2.requestContent("google.com";);
add(_bf2);
Global.c = _bf2.getDocumentUrl();
Global.be=new BasicEditField("URL: "+Global.c,Global.c);
add(Global.be);
and the weird thing is that www.google.com gets loaded in the BrowserField and the documentUrl returns null.
This is my current code:
BrowserField _bf2 = new BrowserField();
MYBrowserFieldListener _listener = new MYBrowserFieldListener();
_bf2.requestContent("google.com";);
_bf2.addListener(_listener);
String url=_bf2.getDocumentUrl();
Global.be=new BasicEditField("URL: "+url,url);
add(Global.be);
add(_bf2);
I changed it to
final BrowserField _bf2 = new BrowserField();
_bf2.requestContent("google.com";);
//_bf2.addListener(listener);
Global.be=new BasicEditField("URL: "+Global.c,Global.c);
add(Global.be);
add(_bf2);
_bf2.addListener(new BrowserFieldListener(){
public void documentLoaded(BrowserField _bf2, Document document) throws Exception {
Global.c=_bf2.getDocumentUrl();
}
});
But it still returns null. Can someone please tell me how to fix this? Thanks in advance!
I would say that Arhimed has answered your question. An HTTP request is a very time consuming process (from a CPU perspective) and will block until the server responds. I suspect that RIM programmers have coded the requestContent() method as per their own recommendations and are fetching the web content on a separate thread. So, requestContent() will return immediately, when you call getDocumentUrl() it is still null since the fetch thread has probably not even connected to the server at this point.
You will need to implement a BrowserFieldListener and listen for documentLoaded().
I experience a strange problem. Sometimes our Java app will not start and will raise an IOException when trying to open a OtpNode. Here is the code (really nothing special):
OtpNode oNode = new OtpNode(NODE);
oNode.setCookie(COOKIE);
OtpMbox mbox = oNode.createMbox(MBOX);
NODE, COOKIE and MBOX are hardcoded constants. The error I get is:
class java.io.IOException,
'Nameserver not responding on Martin-PC when publishing jnode',
Stack trace: [Ljava.lang.StackTraceElement;#c3ea5a
That's it. And this happens only sometimes. I observed that when restarting the PC it happens.
Had anyone seen similar problem?
Thank you.
It turned out that after restrat the Erlang virtual machine sometimes is not running. So we need to start it first before Java OtpNode could be started:
erl -sname whatever
http://www.erlang.org/doc/man/erl.html