user1531389
user1531389

Reputation: 1

developing android application with server using web service

I am developing client/server apps (the client is an Android application which sends data to the server). I am developing the server using Java. I already connected the sever application "using NetBeans" using SQL Navigator 5.5. I want to use Json as a middle ware, but I don't know how! What is the most suitable, XML or Json? Do i need to use HTTP? If so, how (as I want to be able to secure the application)?

The other thing that the server should respond to is the Android application by sending "longitude and latitude", for which Android should "geocode" and display on the form of map "location." Also, I need to understand more about the concept of web service that should work on the application.

This is the server code: (The values that the server should get from the client are "long and lat") /* * To change this template, choose Tools | Templates * and open the template in the editor. */

package pkg;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.jws.WebParam;


@WebService(serviceName = "lbsws")
public class lbsws {

    /** This is a sample web service operation */
    @WebMethod(operationName = "hello")
    public String hello(@WebParam(name = "name") String longg) {


        String result=null;
        try
        {



        Connection con = dbConnection.getdbConnection("system","lbs","orcll", "localhost");
        Statement st = con.createStatement(); 


        String lat ="10";

        String query="select longg,lat,abs(("+longg+"-longg))/abs(("+lat+"-lat)) as function1 from lbs where abs(("+longg+"-longg))/abs(("+lat+"-lat)) = ("+
        "select min(abs(("+longg+"-longg))/abs(("+lat+"-lat))) from lbs)";

        ResultSet rs = st.executeQuery(query);
        while(rs.next())
        {
            result = rs.getFloat("longg")+","+ rs.getFloat("lat")+"-"+ rs.getFloat("function1");
        }
        }
        catch(Exception e)
        {
            System.out.println(e.toString());
        }
        return result;
    }

}

Upvotes: 0

Views: 1498

Answers (1)

Code Droid
Code Droid

Reputation: 10472

A few things:

1) JSON Thumbs up for the transport layer. Don't give it a second thought.

2) Consuming JSON Web Services. Use HttpClient in Java based systems. Just to get the response back than you can convert JSON to objects as needed. But calling web service is via HttpClient

3) Creating JSON Services. Well you could use Jersey. There are a few choices. I would recommend developing in Tomcat server. Its faster and not so much up/down as with Java EE servers. There are some other good choices beside Jersey.

But mainly write the simplest thing first and get it working from end-to-end. Thats what you want to do.

Just produce a service that returns the Sytem time and send that back via JSON consume it on the client and display. Then re-evaluate Jersey vs. whatever. But get something running end to end.

So step one is write a JSON Web Service and just test it in the browser. Don't worry about client side right now. Just get the service running and invoke it using the browser. BTW, there are reason to go with RESTful JSON web service. Its a good way to structure your web services.

Never attack two problems at the same time. Forget about connecting to a database until you have got the service up and running with just data that is stubbed out.

Upvotes: 2

Related Questions