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.
Related
my boss asked me to develop an webservice that should work in this matter:
an external app contact my app and:
if the method used is GET and the url contacted is:
http://localhost:8080/webapp/webservice/?findall
will return all rows find in a table;
If the same external app contact my app in the same method but send a key and a value like:
http://localhost:8080/webapp/webservice/?field1=value1
my app will return a set of rows filtered by field/value.
And soon on with with any method sending request and with other fields.
I know how do the operations using JPA 2.1 but how mapping the actions?
Someone could help me to starting in the right direction with JDK1.8?
I know that returning a value from a JWSapp to the "calling" page cannot be done.
However, I use this JWSapp to get user ID from its biometric information.
The idea is that when you try to login, a button allows to launch the JWSapp that will deal with the biometric tasks and then return the user's idea.
Still, as I said, from a JWSapp I cannot send back the id to auto-complete the field. I found this post: Returning a value from a java web start application but I really need to keep the JWS (external constraints)...
So there's my question: is there any workaround to get the id back?
Thank you in advance :)
I'll first say that I'm sure it is just me since people have probably got this to work out of the box without having to edit the ADAL 4 Android Library without editing the source.
When running the sample program and authenticating with a token I get an error from AZURE that it is not passing the client_secret in the message body. I can confirm that this is in fact the case - it is not passing the client_secret.
Although if I edit the OAuth2.java file and change the method buildTokenRequestMessage to something like the following the workflow works perfectly
public String buildTokenRequestMessage(String code) throws UnsupportedEncodingException {
String message = String.format("%s=%s&%s=%s&%s=%s&%s=%s&%s=%s",
AuthenticationConstants.OAuth2.GRANT_TYPE,
StringExtensions.URLFormEncode(AuthenticationConstants.OAuth2.AUTHORIZATION_CODE),
AuthenticationConstants.OAuth2.CODE, StringExtensions.URLFormEncode(code),
AuthenticationConstants.OAuth2.CLIENT_ID,
StringExtensions.URLFormEncode(mRequest.getClientId()),
AuthenticationConstants.OAuth2.REDIRECT_URI,
StringExtensions.URLFormEncode(mRequest.getRedirectUri())
// these are the two lines I've added to make it work
AuthenticationConstants.OAuth2.CLIENT_SECRET,
StringExtensions.URLFormEncode("<MY CLIENT SECRET>")
);
return message;
}
Am I doing something wrong? If not, what is the correct way to access the client secret?
My implementation is straight from the demo application with only changes being setting up the strings to match my endpoints.
Thanks
You need to register your app as a Native application at Azure AD portal. You don't need client secret for native app.
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 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!