Hi All,

please help, i'm stuck here since 10 days.

I'm not getting response from webservice.

i want to connect my server through the my apps to provide proper login
credential, but "resposne = httpclient.execute(httpget)" not responding.
herewith my code -

LoginDetails.java

public class LoginDetails extends Activity implements OnClickListener {

    private static final int SERVER_PORT = 2853;

    private static final String DEB_TAG = "Json_Android";

    private String SERVER_HOST = "10.91.28.203";
    // http://79.161.183.197/RestaurantPOS/Login.aspx?username=r&password=r
    public static final String PREFS_NAME = "HelloAndroidPREFS";
    private SharedPreferences settings;

    private ProgressDialog progress;
    JSONObject json;

    /*
     * protected LoginScreen(Context paramContext) { super(paramContext);
     * AppInstance.getInstance().LoadPreferences(paramContext); }
     */

    /** Called when the activity is first created. */

    @Override
    public void onCreate(Bundle icicle) {

        requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
        super.onCreate(icicle);
        settings = getSharedPreferences(PREFS_NAME, 0);
        setContentView(R.layout.main3);
        Button login = (Button) findViewById(R.id.login_button);
        Log.i(DEB_TAG, "onCreate");

        login.setOnClickListener(this);
        setUserNameText(settings.getString("Login", ""));
        setPasswordText(settings.getString("Password", ""));
    }
    public void setUserNameText(String $username) {
        EditText usernameEditText = (EditText)
findViewById(R.id.txt_username);
        usernameEditText.setText($username);
    }

    public void setPasswordText(String username) {
        EditText passwordEditText = (EditText)
findViewById(R.id.txt_password);
        passwordEditText.setText(username);

    }


    public void onClick(View v) {

        Log.i(DEB_TAG + " onClick ", "onClick");

        EditText usernameEditText = (EditText)
findViewById(R.id.txt_username);
        EditText passwordEditText = (EditText)
findViewById(R.id.txt_password);
        String sUserName = usernameEditText.getText().toString();
        String sPassword = passwordEditText.getText().toString();

        String address = "http://"; + SERVER_HOST + ":" + SERVER_PORT
                + "/Login.aspx?action=login&username=" + sUserName
                + "&password=" + sPassword + "";

        address = "
http://10.91.28.203/Login.aspx?action=login&username=r&password=r";;
        if ((usernameEditText == null) || (passwordEditText == null)) {
            System.out.println("User Name does not exit");
            Toast.makeText(this.getBaseContext(),
                    "Invalid Username or password", 0).show();
        } else {

            try {

                showBusyCursor(true);

                progress = ProgressDialog.show(this,

                "Please wait...", "Login in process", true);

                Log.i(DEB_TAG, "Username: " + sUserName + " Password: "
                        + sPassword);

                Log.i(DEB_TAG, "Requesting to " + address);

                // json = RestJsonClient.connect(address);
                StringBuilder strBuilder = RestfullClient.connect(address);

            } catch (Exception e) {

                // TODO Auto-generated catch block

                e.printStackTrace();

                showBusyCursor(false);

            }// end try

            progress.dismiss();

            SharedPreferences.Editor editor = settings.edit();
            editor.putString("Login", sUserName);
            editor.putString("Password", sPassword);

            editor.commit();
            showBusyCursor(false);
            next();

        }// end else

    }// end OnClick

    /*

     *

     */

    private void showBusyCursor(Boolean $show) {
        setProgressBarIndeterminateVisibility($show);
    }

    private void next() {
        // you can call another activity by uncommenting the above lines
        Intent myIntent = new Intent(this.getBaseContext(),
                RestaurantHome.class);
        startActivityForResult(myIntent, 0);
    }
    /*
     * protected String doInBackground(String[] paramArrayOfString) {
WebService
     * localWebService = new WebService(); WebService.WebServiceCall
     * localWebServiceCall = WebService.WebServiceCall.LOGIN; Object[]
     * arrayOfObject = new Object[2]; String str1 = paramArrayOfString[0];
     * arrayOfObject[0] = str1; String str2 = paramArrayOfString[1];
     * arrayOfObject[1] = str2; return
     * localWebService.execute(localWebServiceCall, true, arrayOfObject); }
     */

}

my Json code -

public class RestJsonClient {

    public static JSONObject connect(String url) {
        String result = null;
        System.out.println("result = " + result);
        HttpParams params = new BasicHttpParams();
        HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
        HttpProtocolParams.setContentCharset(params, "utf-8");
        params.setBooleanParameter("http.protocol.expect-continue", false);
        HttpClient httpclient = new DefaultHttpClient(params);

        // Prepare a request object
        HttpGet httpget = new HttpGet("http://localhost:2853";);

        // Execute the request
        HttpResponse response = null;

        JSONObject json = new JSONObject();
        System.out.println("result = " + result);
        System.out.println("json object " + json.toString());

        try {
            System.out.println("inside try 1");
            response = httpclient.execute(httpget);
            Log.d("RestJsonCleint ", response.getStatusLine().toString());

            System.out.println("inside try 2");
            HttpEntity entity = response.getEntity();


            System.out.println("entity.getContent()  =" +
entity.getContent());

            if (entity != null) {
                System.out.println("inside the entity");
                entity = new BufferedHttpEntity(entity);

                // A Simple JSON Response Read
                InputStream instream = entity.getContent();

                result = convertStreamToString(instream);
                // System.out.println("result = " + result);


                json = new JSONObject(result);

                instream.close();
            }
            httpclient.getConnectionManager().shutdown();

        } catch (ClientProtocolException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        return json;
    }


    public static String convertStreamToString(InputStream is)
            throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(is,
                "ISO-8859-1"));
        StringBuilder sb = new StringBuilder();
        String line = null;
        while ((line = reader.readLine()) != null) {
            sb.append(line + "\n");
        }
        is.close();
        System.out.println("result =" + sb.toString());
        return "{\"Results\":" + sb.substring(11, sb.length() - 2) + "}\n";

    }


}

my xml file

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android";
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >

    <TextView android:id="@+id/welcome_text"
        android:text = "Welcome to My Application Restaurant SST"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        />

    <TextView android:id="@+id/username_text"
        android:text = "username:"
        android:layout_centerHorizontal="true"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/welcome_text"
        />

    <EditText android:id="@+id/txt_username"
              android:layout_height="wrap_content"
              android:layout_width="250px"
              android:layout_centerHorizontal="true"
              android:layout_below="@+id/username_text"
              android:singleLine="true" />

    <TextView android:id="@+id/password_text"
        android:text = "password:"
        android:layout_centerHorizontal="true"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/txt_username"
        />

    <EditText android:id="@+id/txt_password"
              android:password="true"
              android:layout_height="wrap_content"
              android:layout_width="250px"
              android:layout_centerHorizontal="true"
              android:layout_below="@+id/password_text"
              android:singleLine="true" />

    <Button android:id="@+id/login_button"
        android:text="Login!"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_below="@+id/txt_password"
        />

</RelativeLayout>


while
http://localhost:2853/Login.aspx?action=login&username=r&password=r
returning true, i.e. login is correct.

my localsystem IP address - 10.91.28.203

please help, i'm stuck here since 10 days



-- 
Thanks & Regards

Rakesh Kumar Jha

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to