Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
peter_strange
Posts: 19,599
Registered: ‎07-14-2008
My Device: Not Specified

Re: httpConnection can´t send query, difficulties with setRequestProperty

Now a 401 indicates that the Server you are connected to requires a sign on.  by turning off everything but WiFi, we have confirmed as best we can, that there is no Server between your phone and the target Server that is requesting authentication.  So by elimination, your Server requires a sign-on. 

 

Normally when a 401 is supplied, the processing (Browser in this case) will display a popup requesting a userid and password.  It will then supply these along with the next request to Server. 

 

I presume that you sign in when you are using this Server via your PC Browser?

 

I understand that you do not think we should proceed with this.  However I do not think it will be easy for you to get anything working via the download and supply data to the browser method.  I can see too many pitfalls with that approach and it certainly not one that I would feel comfortable advising you with. 

 

I understand that you have connected to the server and downloaded data and you think that proves this works.  But I suspect that you will eventually hit the same problem that you are seeing with the Browser.  Logically I can not see how a program on your BlackBerry will be able to get data better than the Browser.  Most problems reported on this forum say the reverse - like, how come my application program can't connect but my Browser can?

 

************************* Question ******************************************

Is there a simple solution to get the HTML data  displayed that I downloaded into a byte field, (without saving them to a file) and then displaying the file in the browser ? It means displaying the byte data directly wit h the assistance of the browser.

******************************************************************************

 

You can try this:

http://supportforums.blackberry.com/t5/Java-Development/Invoke-the-browser-with-raw-HTML/ta-p/442950

 

The other alternative is to use a BrowserField and either replace the ProtocolHandler with your own, or change the way it connects to improve the reading and writing of data, since you think the BrowserField's supplied code does not work properly.  There are a number of KB articles that you will find useful - type BrowserField in the Search bix and see what happens.  This one looks interesting:

http://supportforums.blackberry.com/t5/Java-Development/Sample-Code-Using-the-ConnectionFactory-clas...

 

But of all the things I found that I thought might be useful, this is where I would start...

http://supportforums.blackberry.com/t5/Java-Development/How-to-enable-HTTP-Authentication-in-your-Br...

Please use plain text.
Contributor
bb_eibl
Posts: 26
Registered: ‎04-09-2013
My Device: not specified
My Carrier: not speciefied

Re: httpConnection can´t send query, difficulties with setRequestProperty

But of all the things I found that I thought might be useful, this is where I would start...

http://supportforums.blackberry.com/t5/Java-Development/How-to-enable-HTTP-Authentication-in-your-Br...

 

Thank´s very much for this article, it is very interesting, I did not get to it !

 

I just checked it on the paper: the method httpAuthenticate is the back bone, it should allow me to debug step by step the authentication procedure and see where it gets stuck.

 

***************************Question *****************************************

 

Was this your intention ?? How can I debug the credentials, they should be visible by the debugger, right ?

*******************************************************************************

For the first time I see some very tiny light at the end of the tunnel. :smileyhappy:

Please use plain text.
Developer
peter_strange
Posts: 19,599
Registered: ‎07-14-2008
My Device: Not Specified

Re: httpConnection can´t send query, difficulties with setRequestProperty

"Was this your intention ?? How can I debug the credentials, they should be visible by the debugger, right ?"

 

Sorry, the closest I have got to understanding this was finding the KB article.  I have never used this or even looked hard at it. 

 

Let us know how you get on.  Others have more experience and might be able to help. 

Please use plain text.
Contributor
bb_eibl
Posts: 26
Registered: ‎04-09-2013
My Device: not specified
My Carrier: not speciefied

Re: httpConnection can´t send query, difficulties with setRequestProperty

I implemented the sample code you suggested in a project, I still get 401 when trying to request the server.

 

However, I have a good feeling to get to the point: I am debugging the method setUserCredentials. It appears that the problem is there:

 

The String usernameAndPassword is always null !!!

 

********************* Question *********************

 

please explain what "realm" means in the following statement:

 String[] usernameAndPassword = (String[])_credentials.get(_authScheme.getParameter("realm"));

It seems obvious that with "null" in usernameAnd Password I will not be successful.

 

What am I doing wrong ?

I tried to set usernameAndPassword by the set funktion but it does not work, why not ?

*********************************************************************************************************

 

I am controlling the debugging quite nicely and found all the parameters in the debugger, so that is fine.

 

 

 private boolean setUserCredentials(boolean showAuthFailed) {
    	String username="****";
    	String password="****";
    	_authScheme.setParameter("****", username);
        _authScheme.setParameter("****", password);
       
        String[] usernameAndPassword = (String[])_credentials.get(_authScheme.getParameter("realm"));
        _authScheme.setParameter("****", usernameAndPassword[0]);
        _authScheme.setParameter("****", usernameAndPassword[1]);
        if (usernameAndPassword == null) {

 

Please use plain text.
Contributor
bb_eibl
Posts: 26
Registered: ‎04-09-2013
My Device: not specified
My Carrier: not speciefied

Re: httpConnection can´t send query, difficulties with setRequestProperty

Final statement on this thread:

 

I wrote a program based on this template

 

But of all the things I found that I thought might be useful, this is where I would start...

http://supportforums.blackberry.com/t5/Java-Development/How-to-enable-HTTP-Authentication-in-your-Br...

 

and implemented a number of servers as URL addresess in this app requiring authentication: one external the rest servers that I have under my control.

 

I implemented a menu to chosse the URL/server leaving everything else unchanged. The app accesses the servers by a BROWSER REQUEST.

 

Blackberry simulator could access the external server withauthentication, could access also my servers, except one.

 

This server could still be accessed by FIREFOX and IE via PC or Android Browsers but not wit hthe BB browser.

 

I swithched off the authenitication of this server, then I could also access it by the bb Browser.

 

Summary: the BB browser and the server have the difficulties managing the headers and reading the information.

 

I found this upper link very useful.

 

I wrote this final message for PETER STRANGE who asked me to do so and helped a lot during this exercise (saga), Thank´s a lot for this.:smileyhappy:

 

 

 

 

 

 

 

 

Please use plain text.