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
New Developer
newbie_abc
Posts: 5
Registered: ‎08-26-2008
My Device: Not Specified

access a protected xml file on Internet

hi, I just started leaning java development on BlackBerry about ten days ago.

Honestly, I feel a little bit frustrated. I read a lot of document, manual, watched instructional videos on the forum.

I havn't find a good starting point to accomplish my task yet.

 

Here is what I want to accomplish, I want to check an xml file on Internet, if the xml file is newer than the copy on BB, I have to download it, the access needs username/password. Then I have to parse the file, show the information on screen in different categories. for example, first screen would be all book names(should be a list, user can scroll down), then the user can pick a book, next screen will should show other details about the boot.

 

sounds not that complicate, right.

I have problem with the first step though. accessing the protected xml file.

when I started, I found two sample programs coming with JDE might help me.

BrowerFieldDemo and HTTPDemo.

 

The problem is when I typed the URL for the xml file(http://www.example.com/example.xml) in Internet Explorer, a message box will pop up and ask for username/password, but on BB, something else returned, a blank page with website name on the title, but the page is blank. I set breakpoint within the HTTPDemo program, I found the the response code is HttpConnection.HTTP_OK, instead of HttpConnection.HTTP_UNAUTHORIZED, which was I expected. I think that's why I don't even have a chance to provide the username/password to the website.

 

I am stuck here now. Any one can give me some direction? any link, document, sample code will help.

 

Thanks a million in advance.

Please use plain text.
Administrator
MSohm
Posts: 14,528
Registered: ‎07-09-2008
My Device: BlackBerry Z30, BlackBerry PlayBook
My Carrier: Bell

Re: access a protected xml file on Internet

Assuming your web server is using HTTP basic authentication, this sample should help you.

 

How To - Implement basic HTTP authentication
Article Number: DB-00468

 

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800429/How_To_...

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Please use plain text.
New Developer
newbie_abc
Posts: 5
Registered: ‎08-26-2008
My Device: Not Specified

Re: access a protected xml file on Internet

Thank you for your reply.

 

Actually, that's excatly what frustrated me.

I already tried the code you gave me .

 

the program goes to HttpConnection.HTTP_OK branch, instead of HttpConnection.HTTP_UNAUTHORIZED branch.

 

in IE, if I type the url for the xml file, a messagebox will pop out and ask for username/password, if I click Cancel on that messagebox, then I can see Error 401, which is Unauthorized.

 

On BB, it gets the response HTTP_OK in the first place, then keepGoing = false and the loop is over. it won't do anything more.

 

I really don't know what I should do now.

Please use plain text.
Administrator
MSohm
Posts: 14,528
Registered: ‎07-09-2008
My Device: BlackBerry Z30, BlackBerry PlayBook
My Carrier: Bell

Re: access a protected xml file on Internet

Is your web server configured to use basic HTTP authentication or something else?  You'll need this information before you can start to create an application that implements the correct authentication scheme.

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Please use plain text.
New Developer
newbie_abc
Posts: 5
Registered: ‎08-26-2008
My Device: Not Specified

Re: access a protected xml file on Internet

In this article, http://na.blackberry.com/eng/developers/resources/journals/nov_2003/calling_all_networks.jsp

 

HTTP Authentication section, I see

 

"The Mobile Data Service supports Basic Authentication only." and "By default, HTTP authentication is disabled on the Mobile Data Service. "

 

Are these true? So if the web server is not Basic Authentication, there is nothing else I can do?

And is the "By default, HTTP authentication is disabled on the Mobile Data Service." has anything to do with my program problem?

Please use plain text.
Administrator
MSohm
Posts: 14,528
Registered: ‎07-09-2008
My Device: BlackBerry Z30, BlackBerry PlayBook
My Carrier: Bell

Re: access a protected xml file on Internet

That article is out of date.

 

However, note that the MDS Connection Service does handle authentication for the BlackBerry Browser.  The BlackBerry Browser will prompt a user for their login information, which will be used when making the connection.

 

This is not done automatically for third party applications.  This means your application will need to set up the connection, request the login credentials from the user and provide them to the server in a manor appropriate with the authentication scheme in use on the server.

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Please use plain text.
New Developer
newbie_abc
Posts: 5
Registered: ‎08-26-2008
My Device: Not Specified

Re: access a protected xml file on Internet

thank you. your reply enlightened me to try BB browser(not third party program) to test the link.

 

yes, it did prompt user the login screen(Great!).

But after I typed in username and password(I tried several times, to make sure I didn't typed them wrong), the page goes to a blank page with "abc company" as the title. after waiting long enough(just in case the slow downloading speed), still blank, so I believe it's not going anywhere. in IE, I do see the xml file content displaying. so the link is not invalid.

 and one more different thing from IE is when I click Cancel on the login screen, IE gives me a page says Error 401: Unanthenticated. but on BB, when I click Cancel, it goes a blank page, same as I provide username/password, and click OK.

Please use plain text.
Administrator
MSohm
Posts: 14,528
Registered: ‎07-09-2008
My Device: BlackBerry Z30, BlackBerry PlayBook
My Carrier: Bell

Re: access a protected xml file on Internet

Please note that the BlackBerry Browser does not support the display of raw XML data.  It sounds like it is able to log in though.
Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Please use plain text.