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().
Related
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!
i was trying to call the following web service from my android app, it hung then completed without returning the result:
web service:http://androidexample.com/media/webservice/JsonReturn.php
However when I clicked on the link, it worked fine - the json file displayed. yet it would not work in my app..
but now, it works fine now in my android app, perhaps it was temporarily down is what I am guessing. How can I know if a web service is up and running for an android app to consume ?
Typically, web services are designed to have a status page that can return status text or a HTTP return code to indicate service status.
If it doesn't have that, you can design a function to periodically do a very basic request with a known result to determine state. This is much better than doing a simple ping.
If it was down it would most likely show a HTML error page, which your app would try to parse, which would cause an error.
I had a similar issue, because I needed to know if the user was returning HTML or the correct JSON, to do this I created the ArrayList I was about to use outside of the try/catch of the parse area. You should do the same if you are using a string.
What I mean is, use:
ArrayList<Something> arrayList = new ArrayList<Something>();
String testString = ""; instead of String testString = null;
I was using only ArrayList<Something> arrayList; at one point which is incorrect. If the user then returns HTML, you won't get an error, the user will simply return an empty arraylist or empty string.
You can then plan for that and show some sort of error message. This way you only need one network request but you can still plan for getting the data back, and the server being down.
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.
I have the method below in AppEngine:
#ApiMethod(name = "authed", path = "greeting/authed")
public HelloGreeting authedGreeting(User user) {
...
}
My doInBackground method in Android AsyncTask:
HelloGreeting hg = null;
try {
hg = service.authed().execute();
} catch (IOException e) {
Log.d("error", e.getMessage(), e);
}
return hg;
I encountered the ff error:
/_ah/api/.../v1/greeting/authed: java.io.EOFException
In logcat:
Problem accessing /_ah/api/.../v1/greeting/authed. Reason: INTERNAL_SERVER_ERROR
at java.util.zip.GZIPInputStream.readUByte
at java.util.zip.GZIPInputStream.readUShort
at java.util.zip.GZIPInputStream.readUShort
It only work when calling non-auth method. How to fix it?
Im using the local server.
I was running into a similar problem with when making a call for inserting values. Mine differs slightly because I am not using authentication, however I was getting the same exception. I am using appengine-java-sdk-1.8.8. I was able to make other endpoint calls having this error. I looked at the generated code and the difference that I saw with the working calls versus the non-working calls, was the HttpMethod. The failing call was defined as "POST". I was able to change this using the annotation attribute httpMethod=ApiMethod.HttpMethod.GET in the #ApiMethod annotation.
#ApiMethod(httpMethod = ApiMethod.HttpMethod.GET, name = "insertUserArtist", path = "insertUserArtist")
I then regenerated the client code and I was able to make the call without getting the dreaded EOFException. I am not sure why POST doesn't work properly but changing it to GET worked. This does possibly present some questions on how much data can be sent across and should be addressed (possibly a library issue). I am going to look into creating a demonstration app to submit to Google.
If you passed an "entity" object, then the POST will work. If you are passing primitive data type, you'll be stuck with using HttpMethod.GET.
If you are running on the local dev server,
then add the following snippet in MyApi.Builder to set it up properly after setting root url.
.setGoogleClientRequestInitializer(new GoogleClientRequestInitializer() {
#Override
public void initialize(AbstractGoogleClientRequest<?> abstractGoogleClientRequest) throws IOException {
abstractGoogleClientRequest.setDisableGZipContent(true);
}
})
Source: https://github.com/GoogleCloudPlatform/gradle-appengine-templates/tree/master/HelloEndpoints
I am writing a phoneGap plugin to allow multitouch on android devices (hoping to get this included in phonegap/callback eventually)
Event delegation is taking ~200ms using the plugin success callback and ~50ms with the WebView.loadUrl('javascript:somecodehere()') call
Unfortunately loadUrl has the side-effect of flickering the soft keyboard which isn't acceptable for a general solution.
Phonegap's Plugin.success uses an internal web server and an XmlHttpRequest object to send data, this method is way too slow.
Is there any 3rd method of sending javascript to the web browser? (or even sending a poke to the javascript engine to cause an event to happen, so that event could check a custom jsInterface object)
Take a look at addJavascriptInterface in the WebView class. It sounds more like what you are looking for.
In you plugin try calling:
this.ctx.sendJavascript(statement);
Not quite as fast as loadUrl but it may be a bit faster than returning a PluginResult.
You could roll your own stripped down message queue with a java object that is basically an arraylist and an accessor, then use addJavascriptInterface to bind it into the javascript context and inject a javascript polling loop that uses setTimeout to call the accessor method of your queue. Whenever you have javascript to execute, just add it to your arraylist. I'm not sure how it would perform, but perhaps it's worth a try?
class JSQueue {
private ArrayList<String> messages;
public String getMessage() {
String message = "";
if(messages.size() >0) {
message = messages.remove(0);
}
return message;
}
public void addMessage(String message) {
messages.add(message);
}
}
JSQueue jsq = new JSQueue();
dc.appMobiCanvas.hiddenView.addJavascriptInterface(jsq, "jsq");
dc.appMobiCanvas.hiddenView.loadUrl("javascript:(function checkJSQ(){eval(jsq.getMessage());setTimeout(checkJSQ, 50);}})();");
//add messages via jsq.addMessage();
It seems we have developed something similar
https://github.com/Philzen/webview-multitouch-polyfill
However, i have never experienced the issue you're describing before, but maybe you would like to test on your device or maybe contribute your expertise to the project. It has already been suggested on the Cordova (Phonegap) Roadmap, so we'll happy about every user and/or contributor to help this cause!