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
Contributor
rashmi1986
Posts: 10
Registered: ‎09-15-2011
My Device: Curve 8250

GET keyword automatically appended to username and loginid in server

I am facing this unusual problem. I am sending username,email,password ,confirm password and location fields to a local server. I am not using POST. I am trying to fetch the server return value and depending on that, I will get to know if form is submitted or not. When I complete the registration form and check the server, for username and email fields, GET is appended at the end of the string passed:-o. The putput in the server database looks like this :


Name                        Email 

abcGET              abc@k.comGET

 

 

My connection code is as follows. I have done similar work using webview.loadurl() in android and it was working fine.I cant use BrowserField because it will start loading the browser which is not my requrirement. No clue why it is causing problem here in blackberry.

 


try

{

 

ConnectionFactory connFact = new ConnectionFactory();

 

ConnectionDescriptor connDesc;
             connDesc = connFact.getConnection("http://www.*******.com"+loginid+"&name="+name+"&password="+pwd+"&country="+str+"&type=C");         

 

  String url="http://www.*********.com*******/?action=ru&login_id="+loginid+"&name="+name+"&password="+pwd+"&country="+str+"&type=C";


            System.out.println("URL CONTENTS ="+url);     

       if (connDesc != null)       

     {       

         HttpConnection httpConn;       

         httpConn = (HttpConnection)connDesc.getConnection();


                      InputStream isText = httpConn.openInputStream();


                    byte[] bytes=new byte[isText.available()];           

        isText.read(bytes);           

        final String s = new String(bytes);


                    if(s.equals("success"))     

              {                       

 

   UiApplication.getUiApplication().invokeLater(new Runnable()           

            {                       

    public void run()                   

       {                     

        Dialog.alert(("success"));
                         } 

 

             });

Please use plain text.
Developer
amrishodiq
Posts: 112
Registered: ‎09-23-2009
My Device: Not Specified

Re: GET keyword automatically appended to username and loginid in server

Network connection in Blackberry is rather complicated. It was a big issue to use http connection in Blackberry. Blackberry has numerous transport type that is not a big deal in Android. In Blackberry you need to choose between WiFi connection, BES connection, BIS connection, Direct TCP connection, WAP or WAP2 connection.

 

Ok, your URL seems fine. But to use ConnectionFactory you need to set preferred transport type. Here is a sample code how to use ConnectionFactory:

 

factory = new ConnectionFactory();

int[] preferredTransportTypes;
if (DeviceInfo.isSimulator()) {
	preferredTransportTypes = new int[] {
		TransportInfo.TRANSPORT_TCP_CELLULAR
	};
} else {
	preferredTransportTypes = new int[] {
		TransportInfo.TRANSPORT_TCP_WIFI,
		TransportInfo.TRANSPORT_BIS_B, 
		TransportInfo.TRANSPORT_MDS,
		TransportInfo.TRANSPORT_TCP_CELLULAR
	};
}

factory.setPreferredTransportTypes(preferredTransportTypes);

// if you wish to use BIS-B connection, use these lines
BisBOptions bisOptions = new BisBOptions("magic-words-for-alliance");
factory.setTransportTypeOptions(TransportInfo.TRANSPORT_BIS_B, bisOptions);

 

Please use plain text.
Contributor
rashmi1986
Posts: 10
Registered: ‎09-15-2011
My Device: Curve 8250

Re: GET keyword automatically appended to username and loginid in server

Thanks for you reply Amrish. With the code you just mentioned above, should I apply this before setting up connectionfactory or after? I am using this for the first time so I am sorry if my queries are bothering you. I understand network connections are rather complicated in BlackBerry but is it mandatory that each time you need to choose either of the 5 types of connections?

 

Please use plain text.
Contributor
rashmi1986
Posts: 10
Registered: ‎09-15-2011
My Device: Curve 8250

Re: GET keyword automatically appended to username and loginid in server

I tried your code for Transport types.....When I put it, the flow stops at URL content....after that it does not enter the loop where it check if connection!=null
Please use plain text.
Developer
amrishodiq
Posts: 112
Registered: ‎09-23-2009
My Device: Not Specified

Re: GET keyword automatically appended to username and loginid in server

Rashmi, you only need one ConnectionFactory. And by the way, ConnectionFactory is a singleton class I think.

 

Would you share what is URL CONTENTS = value? There might be a mistake in the URL if you have your connection descriptor null.

Please use plain text.
Contributor
rashmi1986
Posts: 10
Registered: ‎09-15-2011
My Device: Curve 8250

Re: GET keyword automatically appended to username and loginid in server

 ConnectionFactory connFact = new ConnectionFactory();         

 ConnectionDescriptor connDesc;     

 connDesc = connFact.getConnection("http://www.XXX.XXX.com/XXXXXXX/?action=ru&login_id="+loginid+"&name="+name+"&password="+pwd+"&country="+str+"&type=C";

 

      if (connDesc != null)     

        {               

  HttpConnection httpConn;       

          httpConn = (HttpConnection)connDesc.getConnection();     

         InputStream isText;try {isText = httpConn.openInputStream();       

         byte[] bytes=new byte[isText.available()];             

         isText.read(bytes);                  

final String s = new String(bytes);       

          System.out.println("STRING S="+s);     

              if(s.equals("unavailable"))   

                     {               

    UiApplication.getUiApplication().invokeLater(new Runnable()   

                     {                   

         public void run()             

               {               

             Dialog.alert(("Loginid already exists!"));   

                               }//dialog                   

    });//uiapp ends         

               }//inner if ends

} catch (IOException e)

{// TODO Auto-generated catch blocke.printStackTrace();}   

          }//if ends

Please use plain text.
Contributor
rashmi1986
Posts: 10
Registered: ‎09-15-2011
My Device: Curve 8250

Re: GET keyword automatically appended to username and loginid in server

When I register using the above code and check the server....all the fields have GET appended to them

 

PaulGET     paul@k.comGET  

Please use plain text.