BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 12-19-2008, 09:47 AM   #1 (permalink)
Thumbs Must Hurt
 
abhsax1978@hotmail.com's Avatar
 
Join Date: Jun 2008
Location: NOIDA
Model: 8100
OS: 4.2.1.91
PIN: 2052AEF9
Carrier: Soft. Engg.
Posts: 111
Post Thanks: 4
Thanked 0 Times in 0 Posts
Unhappy I cannot send file in HttpConnection

Please Login to Remove!

I want to send an XML file 633 kb long by POST method
I figure four solutions:
  1. compression of the sending data,or decryption : but the client would not like it
  2. increase of time out in my pearl or curve device: can't figure it out
  3. send data in chunks: is there a way to set no. of chunks and the connection sends that many byte out of the buffer, in the same connection?
  4. keep alive HttpConnection settings: don't know I can't go to every client to do that
I have separate thread for separate connections
Please help me how can I do all of them, or any one
Regards
__________________
having new s for developers!!!

Last edited by abhsax1978@hotmail.com : 12-19-2008 at 11:54 PM.
Offline  
Old 12-20-2008, 07:49 AM   #2 (permalink)
Thumbs Must Hurt
 
abhsax1978@hotmail.com's Avatar
 
Join Date: Jun 2008
Location: NOIDA
Model: 8100
OS: 4.2.1.91
PIN: 2052AEF9
Carrier: Soft. Engg.
Posts: 111
Post Thanks: 4
Thanked 0 Times in 0 Posts
Default

My Code is as follows
PHP Code:


public synchronized bytexxx91;xxx93; sendPost(String strURLbytexxx91;xxx93; xmlbuffthrows Exception {
//        ShowDialog sh = new ShowDialog("inside transpport service: sendPost");
//        ShowDialog.invokeLater(sh);

        
int status 0;
        
HttpConnection c null;
        
InputStream is null;
        
OutputStream os null;
        
Thread connThread;
        
connThread Thread.currentThread();
        
ShowDialog sh;
        
bytexxx91;xxx93; bRet null;
        
ByteArrayOutputStream baos2 = new ByteArrayOutputStream();
        try {
            
= (HttpConnectionConnector.open(strURL URLs.sideKick);
            
c.setRequestMethod(HttpConnection.POST);
            
c.setRequestProperty(HttpProtocolConstants.HEADER_CONTENT_LENGTHString.valueOf(xmlbuff.length));
            
c.setRequestProperty(HttpProtocolConstants.HEADER_CONTENT_TYPEHttpProtocolConstants.CONTENT_TYPE_APPLICATION_XML);
            
c.setRequestProperty(HttpProtocolConstants.HEADER_CONNECTION"KeepAlive");
////store in outputStream in chunks or bit by bit
            
if (xmlbuff != null) {
//                int i = 0, len = 0;
//                len = xmlbuff.length;
                
os c.openOutputStream();
//                while (i < len) {

                
os.write(xmlbuff);
                
os.flush();
//                    i++;
//                }
            /**
             * the getResponseCode can flush the outputstream itself
             */
            
}
            
sh = new ShowDialog("HTTP POST: before responseCode() for URL: " strURL);
            
ShowDialog.invokeLater(sh);
            
status c.getResponseCode();
            
sh = new ShowDialog("HTTP POST: after responseCode() for URL: " strURL);
            
ShowDialog.invokeLater(sh);
            if (
status == 200) {



                
sh = new ShowDialog("HTTP POST: Inside 200 :The Url: " strURL ":status: " status);
                
ShowDialog.invokeLater(sh);
                
is c.openDataInputStream();

                
baos2 = new ByteArrayOutputStream();
                
bytexxx91;xxx93; bt = new bytexxx91;1xxx93;;
                while ((
is.read(bt)) != -1) {
                    
baos2.write(bt);
                    
baos2.flush();
                }
                
bRet baos2.toByteArray();
                return 
bRet;
            } else {
                
sh = new ShowDialog("HTTP POST: Inside 200 else: The Url: " strURL ":status: " status ": not connected");
                
ShowDialog.invokeLater(sh);
            }
        } catch (
Exception e) {
            
Prnt.println(e.toString() + ":" getClass().toString() + ":post");
            if (
!= null) {
                
c.close();
                
null;
                
= (HttpConnectionConnector.open(strURL URLs.sideKick);
            }
            
status c.getResponseCode();
            
String curThread null;
            
boolean tIsAlive;
            if (
connThread != null) {
                
tIsAlive connThread.isAlive();
                if (
tIsAlive) {
                    
curThread "Alive";
                } else {
                    
curThread "not Alive";
                }
            }
            
sh = new ShowDialog("The Url: " strURL ":status: " status ": Thread :" curThread ": connection error: " e.toString());
            
ShowDialog.invokeLater(sh);
            
Prnt.logSpecificEvent("ERROR: HTTP POST URL :" strURL ":status: " status ": connection error: " e.toString());
        } 
finally {
            try {
                if (
is != null) {
                    
is.close();
                }

                if (
!= null) {
                    
c.close();
                }
            } catch (
Exception e) {
                
Prnt.println(e.toString() + ":" getClass().toString() + ":post");
            }

        }
        return 
null;
    } 
I have the attachment from the etheral from the NetBeans build for BlackBerry application.
I am viewing in JDE version 4.5 and testing in BlackBerry 8100.
I have tried Connection:KeepAlive, but don't know how to send Connection: close
I have tried
Code:
mode=Connection.READ_WRITE;(HttpConnection)Connector.open(url,mode,false);
Both are not working
Regards
Attached Files
File Type: txt uploadContacts.txt (675.0 KB, 10 views)
__________________
having new s for developers!!!

Last edited by abhsax1978@hotmail.com : 12-20-2008 at 07:51 AM.
Offline  
Old 12-20-2008, 07:55 AM   #3 (permalink)
Thumbs Must Hurt
 
abhsax1978@hotmail.com's Avatar
 
Join Date: Jun 2008
Location: NOIDA
Model: 8100
OS: 4.2.1.91
PIN: 2052AEF9
Carrier: Soft. Engg.
Posts: 111
Post Thanks: 4
Thanked 0 Times in 0 Posts
Default

The error it gives is InterruptedIOException,DNS Connection timed out,
The connection should wait for the OutputStream while it is being written.
Regards
__________________
having new s for developers!!!
Offline  
Old 12-22-2008, 06:48 AM   #4 (permalink)
Thumbs Must Hurt
 
abhsax1978@hotmail.com's Avatar
 
Join Date: Jun 2008
Location: NOIDA
Model: 8100
OS: 4.2.1.91
PIN: 2052AEF9
Carrier: Soft. Engg.
Posts: 111
Post Thanks: 4
Thanked 0 Times in 0 Posts
Angry

I have changed the headers to:
PHP Code:
c.setRequestProperty(HttpProtocolConstants.HEADER_CONNECTION"Keep-Alive");
c.setRequestProperty("Keep-Alive"Integer.toString(600000)); 
The problem description now:
Code:
Statistics:
========
Whether you send any file above 5Kb or 7 contacts, (I have not tested below this and except 1 contacts);

Whatever request it is (we have registration API available to test in and we have tested in it).

The Time-Out Error comes exactly at 3.07 minutes.

The response is never reached neither 200 Ok_ready_to_receive_the_response section.
I think now sombody can help up getting this clear picture
Regards
__________________
having new s for developers!!!
Offline  
Old 02-03-2009, 03:23 AM   #5 (permalink)
Thumbs Must Hurt
 
abhsax1978@hotmail.com's Avatar
 
Join Date: Jun 2008
Location: NOIDA
Model: 8100
OS: 4.2.1.91
PIN: 2052AEF9
Carrier: Soft. Engg.
Posts: 111
Post Thanks: 4
Thanked 0 Times in 0 Posts
Unhappy I have also implemented these

PHP Code:
/**
*private final String urlPostFix = ";connectionuid=wap2 trans;deviceside=true";

*private final String urlPostFix = ";connectionuid=wap2 trans;deviceside=true;wapgatewayapn= blackberry.net";

*private final String urlPostFix = ";connectionuid=wap2 trans;wapgatewayapn=airtelfun.com;deviceside=true";
**/

private final String urlPostFix ";connectionuid=wap2 trans;wapgatewayport=9201;wapgatewayip=100.1.200.99;wapgatewayapn=blackberry.net;deviceside=true"
I have used the above string one by one to test connections as postFix to the url but got no success.
__________________
having new s for developers!!!

Last edited by abhsax1978@hotmail.com : 02-03-2009 at 03:29 AM.
Offline  
Old 06-15-2009, 07:08 AM   #6 (permalink)
Thumbs Must Hurt
 
abhsax1978@hotmail.com's Avatar
 
Join Date: Jun 2008
Location: NOIDA
Model: 8100
OS: 4.2.1.91
PIN: 2052AEF9
Carrier: Soft. Engg.
Posts: 111
Post Thanks: 4
Thanked 0 Times in 0 Posts
Smile Solution

You have to specify correct APN, gatway and port.
You should always have "User-Agent" request header in the Connection code and in the property of "User-Agent" you should have the name of the device say "Pearl".
__________________
having new s for developers!!!
Offline  
Old 08-28-2009, 06:42 AM   #7 (permalink)
New Member
 
Join Date: Aug 2009
Model: 7100T
PIN: N/A
Carrier: developper
Posts: 1
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default can you show us you code ?

Quote:
Originally Posted by abhsax1978@hotmail.com View Post
You have to specify correct APN, gatway and port.
You should always have "User-Agent" request header in the Connection code and in the property of "User-Agent" you should have the name of the device say "Pearl".
can you show us the code you used to solve this problem ?
thank you
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Copyright 2004-2014 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.