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
Posts: 49
Registered: ‎08-13-2012
My Device: 9300
My Carrier: Airtel
Accepted Solution

Incorrect Header Check

Hi All,

 

 

I am stuck in one problem.

 

		try
		{
		//	Dialog.alert(updateConnectionSuffix());
			connection = (HttpConnection)Connector.open(url+";deviceside=true");
			connection.setRequestMethod(method);
			connection.setRequestProperty(HttpProtocolConstants.HEADER_CONTENT_LENGTH,String.valueOf(sRequestParameter));
			connection.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
			connection.getHeaderField(HttpProtocolConstants.HEADER_CONTENT_ENCODING);
			//connection.setRequestProperty("User-Agent","Profile/MIDP-2.0 Configuration/CLDC-1.0");
			//connection.setRequestProperty("Accept-Encoding","gzip, deflate");
			out = connection.openOutputStream();
			out.write(sRequestParameter.getBytes("UTF-8"));
			out.flush();
			out.close();
			
			int responseCode = connection.getResponseCode();
			
			if (responseCode == HttpConnection.HTTP_OK) 
			{
				String encoding = connection.getEncoding();
				if (encoding != null && encoding.equalsIgnoreCase("gzip")) 
				{
					_in = new GZIPInputStream(connection.openInputStream());
				}
				else 
				{
					_in = connection.openInputStream();
				}
			}
			else {
			}
			
			//input = connection.openInputStream();
			GZIPInputStream gzis = new GZIPInputStream(_in);
			int chunkSize = 1500;
			byte[] data = new byte[chunkSize];
			String reply = "";
			int dataSizeRead = 0;//size of data read from input stream.
			try
			{
			    while((dataSizeRead = gzis.read(data))!= -1)
			    {
			        String newReply = new String(data, 0, dataSizeRead,"UTF-8");
			        reply += newReply;
			    }    
			    
			    
			}
			catch(Exception e)
			{
			    Dialog.alert("Error ::"+e.toString());
			}
			Dialog.alert(reply); 
		}
		catch (Exception e)
		{
			System.out.println("Error"+e.toString());
		}

 

 

While reading data from Inpot stream I am getting exception "Incorrect Header Check"

 

 

Thanks

Ekansh Srivastava

Developer
Posts: 16,992
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Incorrect Header Check

welcome to the support forum.

i am not sure about your problem, but you should not have dialog.alert on your connection code, as this should run on a separate thread.
see
http://supportforums.blackberry.com/t5/Java-Development/What-is-the-Event-Thread/ta-p/446865

back to your issue:
why do you call getHeaderField ?
i usually use http://www.blackberry.com/developers/docs/7.1.0api/net/rim/device/api/io/IOUtilities.html#streamToBy... to read from a connection.

do you get a http ok from your connection? why do you check the encoding and use gzip even if it is not gzip?
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 49
Registered: ‎08-13-2012
My Device: 9300
My Carrier: Airtel

Re: Incorrect Header Check

Hi Simon,

 

Thanks for replying.

 

Applying dialog.alert is my mistake . I got that.

 

My issues is the server sending the data in zip format. So i am using GZIPInputStream to read it. But it gives the above error mentioned in the subject.

 

Thanks

Ekansh

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Incorrect Header Check

I presume that you are in fact using this to read a GZIP file and not a ZIP file?

 

Unfortunately if the data is being sent as a GZIP file, I think your next step is actually not to read the data in as a GZIP Stream, but actually to read it in to the byte array, and then compare the first few bytes of that byte array with the actual GZIP file you are sending to look for some differences. 

Developer
Posts: 49
Registered: ‎08-13-2012
My Device: 9300
My Carrier: Airtel

Re: Incorrect Header Check

HI Peter,

The data which server is sending in gzip format.

Thanks
Ekansh
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Incorrect Header Check

OK,

 

For me, the next step is put the data sent from the server into a byte array and compare the data that was sent with what you expect.  Perhaps you can create a small gzipped file and test that. 

 

Here is the specification for the Gzip file:

http://www.gzip.org/zlib/rfc-gzip.html#file-format

 

You will note that it begins with the hex characters x'1f' and x'8B', it might be useful to check the host file t make sure it does in fact have these hex characters at the start. 

Developer
Posts: 49
Registered: ‎08-13-2012
My Device: 9300
My Carrier: Airtel

Re: Incorrect Header Check

Hi Peter,

Thanks i got the solution.

Server was sometimes plain text. So it was not able to detect it.
I've now handled at my end. Smiley Happy

Thanks
Ekansh