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
Visitor
Posts: 1
Registered: ‎08-23-2010
My Device: Not Specified

Mock HTTPConnection not working in OS 6.0

I have to display static html in my app.

 

In order to support OS4.5 and up in a single release, I've been using the essence of the BrowserFieldDemo sample (i.e. BrowserContent, *not* BrowserField) with a mock HTTPConnection to supply the content.  This has worked very well up until OS 6.0.

 

It would appear that my mock response is not up to spec with the new webkit browser, however.  It grinds a while, then gives a canned network error screen.

 

I've tried stubbing minimal headers along the lines of the following, to no avail:

 

Status:		HTTP/1.1 200
Location:	http://127.0.0.1/
Content-Type:	text/html; charset=UTF-8
Date:		Mon, 23 Aug 2010 14:42:33 GMT	
Expires:	Wed, 22 Sep 2010 14:42:33 GMT	
Server:		Local	
Content-Length:	[actual length]
Connection:	close

 

 

Obviously, my mock response is missing something critical to the new browser that wasn't necessary in the previous ones.  My header fix attempt followed tracing multiple (as in a gajillion) hits against getHeaderField and getHeaderFieldKey, each incrementing the index skyward.  It's like it wants something particular and isn't finding it.

 

My mock extension follows.  I have also tried returning explicit values in much of the methods, btw.  Again, below 6.0 this flies great... 6.0 chokes on it.  Anything stand out to anyone?

 

 

//The header data...
private String[] headerNames_as = { "Status", "Location", "Content-Type", "Date", "Expires", "Server", "Content-Length", "Connection" };
private String[] headerValues_as = { "HTTP/1.1 200", "http://127.0.0.1/", "text/html; charset=UTF-8", "Tue, 15 Nov 1994 08:12:31 GMT", "Fri, 15 Nov 2999 08:12:31 GMT", "local", "0", "close" };


public class Connection_ic implements HttpConnection { private long streamLength_l = 8000; private DataInputStream dataInput_io; private InputStream inStream_io; private String encoding_is = "UTF-8"; //"text/html"; public Connection_ic( String sContent ) { try { streamLength_l = sContent.length(); inStream_io = new ByteArrayInputStream( sContent.getBytes( "UTF-8" ) ); dataInput_io = new DataInputStream( inStream_io ); } catch ( Exception e ) { } } public String getURL() { return ""; } public String getProtocol() { return ""; } public String getHost() { return ""; } public String getFile() { return ""; } public String getRef() { return ""; } public String getQuery() { return ""; } public int getPort() { return 0; } public String getRequestMethod() { return ""; } public void setRequestMethod(String s) throws IOException { } public String getRequestProperty(String s) { return ""; } public void setRequestProperty(String s, String s1) throws IOException { } public int getResponseCode() throws IOException { return 200; } public String getResponseMessage() throws IOException { return ""; } public long getExpiration() throws IOException { return 0; } public long getDate() throws IOException { return 0; } public long getLastModified() throws IOException { return 0; } public String getHeaderField(String s) throws IOException { return ""; } public int getHeaderFieldInt(String s, int i) throws IOException { return 0; } public long getHeaderFieldDate(String s, long l) throws IOException { return 0; } public String getHeaderField ( int i ) throws IOException { if ( i < headerNames_as.length ) return headerNames_as[i]; return ""; } public String getHeaderFieldKey(int i) throws IOException { if ( i < headerValues_as.length ) return headerValues_as[i]; return ""; } public String getType() { return "text/html"; } public String getEncoding() { return encoding_is; } public long getLength() { return streamLength_l; } public InputStream openInputStream() throws IOException { return inStream_io; } public DataInputStream openDataInputStream() throws IOException { return dataInput_io; } public void close() throws IOException { } public OutputStream openOutputStream() throws IOException { return new ByteArrayOutputStream(); } public DataOutputStream openDataOutputStream() throws IOException { return new DataOutputStream(new ByteArrayOutputStream()); } } //Connection_ic

 

 

Highlighted
Developer
Posts: 64
Registered: ‎08-07-2008
My Device: Not Specified

Re: Mock HTTPConnection not working in OS 6.0

I have the same problem. Have you got the problem fixed?

Developer
Posts: 64
Registered: ‎08-07-2008
My Device: Not Specified

Re: Mock HTTPConnection not working in OS 6.0

All anyone from RIM knows the solution of this?

I also found out the Browserfielddemo in 6.0 Sample is not compilable. It uses Utilies class which doesn't exist.

New Contributor
Posts: 9
Registered: ‎11-22-2010
My Device: Not Specified

Re: Mock HTTPConnection not working in OS 6.0

Hi,

 

Were you able to resolve this issue?

 

thanks