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
Highlighted
New Developer
Posts: 23
Registered: ‎10-20-2008
My Device: Not Specified
Accepted Solution

Data from SmartPhone to Server

I am attempting to write a prototype where I am sending data from my Java Server app to the BB device through MDS. That works just fine. But I also want to allow the user on the BB device to send select data from the device back to my Java application running on my server on demand. Is there any example you have or can site that shows how to establish the http connection on the device back to the server side and transfer data from the device back to the server?

Thanks
New Developer
Posts: 23
Registered: ‎10-20-2008
My Device: Not Specified

Re: Data from SmartPhone to Server

I have made some progress on this.  I am using JDE 4.2.1 and the MDS Simulator 4.1.4 for the prototype I am doing.

 

Thus far the data is getting from the device to the server application just fine.  However, when I check the response code on the client I am getting a "400 Bad Request - The request could not be understood by the server due to malformed syntax."

 

The code I have on the device Simulator to send data from the device to the server (I am using "http://dev14.wpt.local:7778/" as the URL string I am passing in as the parameter) using the method below:

 

void postViaHttpConnection(String url) throws IOException

{
        HttpConnection c = null;
        InputStream is = null;
        OutputStream os = null;
        int rc;

        try
        {   
            c = (HttpConnection)Connector.open(url);

            // Set the request method and headers
            c.setRequestMethod(HttpConnection..POST);

// Getting the output stream may flush the headers
            os = c.openOutputStream();
            os.write("Data Sent From Device Simulator".getBytes());
            os.flush();           // Optional, getResponseCode will flush

            // Getting the response code will open the connection,
            // send the request, and read the HTTP response headers.
            // The headers are stored until requested.
            rc = c.getResponseCode();
            if (rc != HttpConnection.HTTP_OK) {
                throw new IOException("HTTP response code: " + rc);
            }

     } catch (ClassCastException e) {
            throw new IllegalArgumentException("Not an HTTP URL");
        } finally {
            if (is != null)
                is.close();
            if (os != null)
                os.close();
            if (c != null)
                c.close();
        }
    }

 

The code on the server that is accepting the data from the device is below:

 

    public class NotificationThread extends Thread {

        public void run()
        {
            try {
                System.out.println("Waiting for notification on port " + 7778 + "...");
                while (true)
                {
                    ServerSocket serverSocket = new ServerSocket(7778);
                    serverSocket.setSoTimeout(120000);
                    try {
                        System.out.println("Before serverSocket.accept() on port " + 7778 + "...");
                        Socket clientSocket = serverSocket.accept();
                        System.out.println("After serverSocket.accept() on port " + 7778 + "...");
                        _notification.setText("Received notification:");
                        InputStream input = clientSocket.getInputStream();
                        StringBuffer str= new StringBuffer();
                        int byteRead = input.read();
                        while ((byteRead != -1) && (input.available() > 0))
                        {
                            str.append((char)byteRead);
                            byteRead = input.read();
                        }
                        _notification.append(str.toString());
                        PrintWriter output = new PrintWriter(clientSocket.getOutputStream());
                        output.close();
                        clientSocket.close();
                    } catch (SocketTimeoutException ste) {
                        System.out.println("Notification connection timeout. Restarting...");
                    }              
                    serverSocket.close();
                }
            } catch (Exception exception) {
                exception.printStackTrace();
            }

        }
    }

 

Any ideas on why I am getting the HTTP Response Code of 400? 

New Developer
Posts: 23
Registered: ‎10-20-2008
My Device: Not Specified

Re: Data from SmartPhone to Server

For some reason when I cut and pasted the code examples in the post above it put smiley faces in place of )

 

Sorry

BlackBerry Development Advisor
Posts: 15,506
Registered: ‎07-09-2008
My Device: BlackBerry PRIV
My Carrier: Bell

Re: Data from SmartPhone to Server

Please verify where the 400 error is originating from.  It is coming from your web server or from the MDS Simulator?

 

If it is from the MDS Simulator, try to perform a network capture on the return value from your web server to see what data is being returned.

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
New Developer
Posts: 23
Registered: ‎10-20-2008
My Device: Not Specified

Re: Data from SmartPhone to Server

Thanks the 400 was received on the device and I have been able to correct the problem.  Thanks for your help.
New Developer
Posts: 49
Registered: ‎07-16-2008
My Device: Not Specified

Re: Data from SmartPhone to Server

Hi,

 

I m writing a program for playing video in BB 8330. I m using JDE 4.3.0. I m getting "HTTP Error 400: Bad Request" error from the instruction

.........

.........

player = Manager.createPlayer("http://mob.i-waves.com/mdirectAPP/T/sample2.3gp"+ ";deviceside=false");

........

........

What could be reason and how to solve it pls?

 

Thanks.

 

BlackBerry Development Advisor
Posts: 15,506
Registered: ‎07-09-2008
My Device: BlackBerry PRIV
My Carrier: Bell

Re: Data from SmartPhone to Server

Are you able to access the same URL in the BlackBerry Browser?  This error would be from either the web server or the MDS Connection Service of a BlackBerry Enterprise Server.  You may want to check the logs on your web 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
New Developer
Posts: 49
Registered: ‎07-16-2008
My Device: Not Specified

Re: Data from SmartPhone to Server

Hi,

 

Thanks for your reply. You are right. This URL is not accessing from BlackBerry Browser too.
I have checked the log file. It is printed as below:

 

BlackBerry Device Simulator version 2.8.0.56
Built May 24 2008 19:21:54 by absadmin

 

> I used BB 8330 Simulator 4.3.0.124 But unable to understand, why the log file saying my device version 2.8.0.56.

And, what could be the solution for this problem?

 

Thanks.

BlackBerry Development Advisor
Posts: 15,506
Registered: ‎07-09-2008
My Device: BlackBerry PRIV
My Carrier: Bell

Re: Data from SmartPhone to Server

What log file are you looking in?  One for your web server or one for the BlackBerry Simulator?  Version 4.3.0.x is the version of BlackBerry handheld software being simulated.  Version 2.8.0.56 sounds like the version of the BlackBerry Simulation tool itself.
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
New Developer
Posts: 49
Registered: ‎07-16-2008
My Device: Not Specified

Re: Data from SmartPhone to Server

Hi,

 

I got "failure.zip" file after saving log file and it has 3 files
1. 8330.bug
2. fledge.xml
3. info.txt

 

I have looked "info.txt" file and it contain following information :

BlackBerry Device Simulator version 2.8.0.56
Built May 24 2008 19:21:54 by absadmin


.................

 

The system configuration i used is :
BB JDE 4.3.0
BB 8330 Simulator 4.3.0.124
JDK 1.5

 

> Is this the info.txt file for BlackBerry Simulator and fledge.xml for web server?

> what could be the reason for not playing video in this configuration?