0

In my application I have create the login page in that login page I have enter the user name and password details and I send the request parameter,when I try to click the login button the webservice call and get username and pasword as response from the given SOAP URL but when I try to get an respose the xml pull parser exception will occer where I have done mistakes here with I have attached my code would any one help me from this exception.

LoginActivity

 public class LoginActivity extends Activity {
        //Set Error Status
        static boolean errored = false;
        Button Login;
        TextView Showtext;
        EditText userName , passWord;   
        ProgressBar webservicePG;
        String editTextUsername;
        boolean loginStatus;
        String editTextPassword;
        public static   String nameValue;
        public static   String passwordvalue;

        int MC_loginRequest = 0;
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.login);
             SharedPreferences prefs = this.getSharedPreferences("com.hubino.sozo", Context.MODE_PRIVATE);
            StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
            StrictMode.setThreadPolicy(policy); 
            userName = (EditText) findViewById(R.id.usernametext);
            passWord = (EditText) findViewById(R.id.passwordtext);
            Showtext = (TextView) findViewById(R.id.showtext);
            Login = (Button) findViewById(R.id.login);
            webservicePG = (ProgressBar) findViewById(R.id.progressBar1);
            Login.setOnClickListener(new OnClickListener() {

                public void onClick(View v) {
                    userName.setHintTextColor(getResources().getColor(R.color.red));
                    userName.setHint(Html.fromHtml("<small><small>" + 
                             getString(R.string.hint) + "</small></small>"));
                    passWord.setHintTextColor(getResources().getColor(R.color.red));
                    passWord.setHint(Html.fromHtml("<small><small>" + 
                             getString(R.string.password) + "</small></small>"));

                    if (userName.getText().length() != 0 && userName.getText().toString() != "") {
                        if(passWord.getText().length() != 0 && passWord.getText().toString() != ""){
                            editTextUsername = userName.getText().toString();
                            editTextPassword = passWord.getText().toString();
                            Showtext.setText("");
                            nameValue = userName.getText().toString();
                            passwordvalue = passWord.getText().toString();
                    haredPreferences.Editor prefs = LoginActivity.this.getSharedPreferences(
                                    "com.hubino.sozo", Context.MODE_PRIVATE).edit();

                        prefs.putString("name",nameValue);  
                        prefs.putString("number",passwordvalue);    
                        prefs.commit();
                        AsyncCallWS task = new AsyncCallWS();
                        task.execute();
                        }

                    } 
                }

          });

          }

           private class AsyncCallWS extends AsyncTask<String, Void, String> {
            @Override
            protected String doInBackground(String... params) {

                loginStatus = WebService.Loginvalue(editTextUsername,editTextPassword,"mc_login");
                loginStatus = true;
                return null;
            }

            @Override
            protected void onPostExecute(String result) {
                webservicePG.setVisibility(View.INVISIBLE);
                Intent intObj = new Intent(LoginActivity.this,MenuActivity.class);
                if(!errored){
                        if(loginStatus){
                        startActivity(intObj);
                    }else{

                        Showtext.setText("Login Failed, try again");
                    }

                }else{
                    Showtext.setText("Error occured in invoking webservice");
                }

                errored = false;
                    }

            @Override
            protected void onPreExecute() {
                webservicePG.setVisibility(View.VISIBLE);
            }

            @Override
            protected void onProgressUpdate(Void... values) {
            }
        }
        public static Object password() {
            // TODO Auto-generated method stub
            return null;
        }
    }



    **WebService**

        public class WebService extends AsyncTask<String, Void, String> {
        private static mc_loginRequest MC_loginRequest = null;
        private static final String NAMESPACE = "    ";
        private static final String URL = "    ";
        private static final String SOAP_ACTION = "  ";
        private static final String METHOD = "mc_login";

        @SuppressWarnings("null")
        public static boolean Loginvalue(String usrname,String passwd, String mc_login) {
            MC_loginRequest = new mc_loginRequest();
            boolean loginStatus = false;
            SoapObject request = new SoapObject(NAMESPACE, METHOD);
            PropertyInfo pi = new PropertyInfo();
            MC_loginRequest.username=usrname;
            MC_loginRequest.password=passwd;
            pi.setName("MC_loginRequest");
            pi.setValue(MC_loginRequest);
            pi.setType(MC_loginRequest.getClass());
            request.addProperty(pi);

            SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
            envelope.setOutputSoapObject(request);
            envelope.addMapping(NAMESPACE, "MC_loginRequest", mc_loginRequest.class);
            envelope.bodyOut = request;
            HttpTransportSE transport = new HttpTransportSE(URL);
            transport.debug = true;
            envelope.dotNet = true;
            envelope.encodingStyle = SoapEnvelope.ENC;
            try {
                transport.call(SOAP_ACTION+METHOD, envelope);
                SoapPrimitive loginresponse = (SoapPrimitive) envelope.getResponse();
                loginStatus = Boolean.parseBoolean(loginresponse.toString());
                }
            catch (Exception e) 
            {
                LoginActivity.errored = false;
            e.printStackTrace();
                Log.e("YOUR_APP_LOG_TAG", "I got an error", e);
            } 
            return loginStatus;
            }
        protected SoapObject doInBackground(Integer... branchNumber) {
            return null;
        }
        @Override
        protected String doInBackground(String... params) {
            // TODO Auto-generated method stub
            return null;
        }
    }


    **mc_loginRequest**

          public class mc_loginRequest implements KvmSerializable {

        public  String username;
        public  String password;
        @Override
        public Object getProperty(int arg0) {
            switch (arg0){
            case 0:
                return username;
            case 1:
                return password;

             default:
                 return null;
            }
        }

        @Override
        public int getPropertyCount() {
            // TODO Auto-generated method stub
            return 1;
        }
        @Override
        public void getPropertyInfo(int index, Hashtable arg1, PropertyInfo info) {
            switch(index)
            {
            case 0:
                info.type = PropertyInfo.STRING_CLASS;
                info.name = "username";
                break;
            case 1:
                info.type = PropertyInfo.STRING_CLASS;
                info.name = "password";
                break;

            default:
                break;
            }
    }
        @Override
        public void setProperty(int index, Object value) {
            switch(index)
            {
            case 0:
                username = value.toString();
                break;
            case 1:
                password = value.toString();
                break;
             default:
            break;
           }
        }
    }

`

Pans
  • 199
  • 17

1 Answers1

1

You will get "XML pull parser exception" when you have corrupted file getting from request, probably wrong enclosed tag or something like "HTTP error 503" as result, when server is unavailable will rise this kind of exception.

I will recommend you to provide additional catch closes for different kinds of exception in SOAPObject call

P.S: provide what you get in response

Top Cat
  • 2,473
  • 3
  • 22
  • 34
  • Your answer is valuable before that please check my code if there may be an mistakes to get response. – Pans Aug 02 '14 at 07:20
  • I didnt get any response while calling response i am getting the exception. – Pans Aug 02 '14 at 07:28
  • Hello fvh in my code I have pass the correct parameter vales in request even I have send the correct NAMESPACE ,URL ,SOAP_ACTION,METHOD but i have the same exception here and my server also working fine. – Pans Aug 02 '14 at 12:56
  • @Pans try to remove transport.debug = true; there is chance than answer is too big, and when it trying to convert to string (in internal part) in falls into exception –  Aug 03 '14 at 13:05
  • @Pans also your code is very tricky, it can be rewritten in more compact and clear way.. –  Aug 03 '14 at 13:06
  • Thanks for your quick reply i have remove transport.debug = true; in my code and can you tel me how to covert response as string in my code. – Pans Aug 04 '14 at 04:08
  • @Pans it will be much better if you map your json into some class and convert it to string when needed responseContent = gson.fromJson(input, Response.class); –  Aug 04 '14 at 12:58