@Override
    protected JSONObject doInBackground(String... urls) {
      DefaultHttpClient client = new DefaultHttpClient();
      HttpPost post = new HttpPost(urls[0]);
      JSONObject holder = new JSONObject();
      JSONObject userObj = new JSONObject();
      String response = null;
      JSONObject json = new JSONObject();

      try {
        try {
          // setup the returned values in case
          // something goes wrong
          json.put("success", false);
          json.put("info", "Something went wrong. Retry!");

          // add the users's info to the post params
          userObj.put("email", mUserEmail);
          userObj.put("name", mUserName);
          userObj.put("password", mUserPassword);
          userObj.put("password_confirmation", mUserPasswordConfirmation);
          userObj.put("phone_first", mPhone_first);
          userObj.put("phone_second", mPhone_second);
          userObj.put("phone_third", mPhone_third);
          userObj.put("phone", mPhone_first + mPhone_second + mPhone_third);
          holder.put("user", userObj);
          StringEntity se = new StringEntity(holder.toString());
          post.setEntity(se);

          // setup the request headers
          post.setHeader("Accept", "application/json");
          post.setHeader("Content-Type", "application/json");

          ResponseHandler<String> responseHandler = new BasicResponseHandler();
          response = client.execute(post, responseHandler);
          json = new JSONObject(response);

        } catch (HttpResponseException e) {
          e.printStackTrace();
          Log.e("ClientProtocol", "" + e);
        } catch (IOException e) {
          e.printStackTrace();
          Log.e("IO", "" + e);
        }
      } catch (JSONException e) {
        e.printStackTrace();
        Log.e("JSON", "" + e);
      }

      return json;
    }
예제 #2
0
    protected String doInBackground(String... params) {
      Log.i(TAG, "doInBackground");
      String respuesta = null;

      try {
        TelephonyManager telephonyManager =
            (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
        String IMEI = telephonyManager.getDeviceId();
        String IMSI = telephonyManager.getSimSerialNumber();
        String consulta;
        if (phone.getText().toString().equals("2")) {
          consulta = URLs.RESOURCE;
        } else consulta = SoapRequestMovistar.getResource(IMEI, IMSI, phone.getText().toString());

        ArrayList<String> retorno = XMLParser.getReturnCode(consulta);

        code = Integer.valueOf(retorno.get(0));

        if (code == 0) {
          respuesta = consulta;
          Log.i(TAG, retorno.get(1));
        } else respuesta = retorno.get(1);
        return respuesta;

      } catch (HttpHostConnectException e2) {
        errorMessage = "Se agotó el tiempo de espera. Por favor reintente";
        return null;
      } catch (HttpResponseException e3) {
        e3.printStackTrace();
        errorMessage = "Se agotó el tiempo de espera. Por favor reintente";
        return null;
      } catch (ParseException p) {
        p.printStackTrace();
        errorMessage = "Error en la recepción de los datos. Por favor reintente";
        return null;
      } catch (SocketTimeoutException s1) {
        s1.printStackTrace();
        errorMessage = "Se agotó el tiempo de espera. Por favor reintente";
        return null;
      } catch (ConnectTimeoutException et) {
        et.printStackTrace();
        errorMessage = "Se agotó el tiempo de espera. Por favor reintente";
        return null;
      } catch (Exception e1) {
        e1.printStackTrace();
        errorMessage = "Ha ocurrido un error con la respuesta del servidor.";
        return null;
      }
    }
예제 #3
0
    @Override
    protected Void doInBackground(MyTaskParams... params) {
      String date = params[0].date;
      String nick = params[0].nick;
      String address = params[0].address;
      Double latitude = params[0].latitude;
      Double longitude = params[0].longitude;

      SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME2);
      request.addProperty("date", date);
      request.addProperty("user", nick);
      request.addProperty("address", address);
      request.addProperty("lat", latitude);
      request.addProperty("longitude", longitude);

      SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
      envelope.setOutputSoapObject(request);

      InsertUserActivity.MarshalDouble doubleMarshal = new InsertUserActivity.MarshalDouble();
      doubleMarshal.register(envelope);

      MarshalDate dateMarshal = new MarshalDate();
      dateMarshal.register(envelope);

      HttpTransportSE httpTransport = new HttpTransportSE(URL);

      httpTransport.debug = true;
      try {
        httpTransport.call(SOAP_ACTION2, envelope);
      } catch (HttpResponseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } catch (XmlPullParserException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } // send request
      try {
        response = (String) envelope.getResponse();
      } catch (SoapFault e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
      response = response.toString();
      return null;
    }
예제 #4
0
    protected JSONObject doInBackground(String... urls) {
      DefaultHttpClient client = new DefaultHttpClient();
      HttpPost post = new HttpPost(urls[0]);
      JSONObject holder = new JSONObject();
      JSONObject userObj = new JSONObject();
      String response = null;
      JSONObject json = new JSONObject();

      try {
        // Set error return values
        json.put("email", false);
        json.put("info", "Something went wrong. Retry.");

        // Set user password and email
        userObj.put("email", mEmail);
        userObj.put("password", mPassword);
        holder.put("user", userObj);

        StringEntity se = new StringEntity(holder.toString());
        post.setEntity(se);

        // Set the request header for the login
        post.setHeader("Accept", "application/json");
        post.setHeader("Content-Type", "application/json");

        ResponseHandler<String> responseHandler = new BasicResponseHandler();
        response = client.execute(post, responseHandler);
        json = new JSONObject(response);
      } catch (HttpResponseException e) {
        e.printStackTrace();
        Log.e("ClientProtocol", "", e);
        try {
          json.put("info", "Invalid Email/Password combination. Please retry.");
        } catch (JSONException j) {
          j.printStackTrace();
        }
      } catch (IOException e) {
        e.printStackTrace();
        Log.e("IO", "", e);
      } catch (JSONException e) {
        e.printStackTrace();
        Log.e("JSON", "", e);
      }

      return json;
    }
예제 #5
0
    @Override
    protected JSONObject doInBackground(String... urls) {
      DefaultHttpClient client = new DefaultHttpClient();
      HttpPost post = new HttpPost(urls[0]);
      JSONObject holder = new JSONObject();
      JSONObject userObj = new JSONObject();
      String response = null;
      JSONObject json = new JSONObject();

      try {
        try {
          json.put("success", false);
          json.put("info", "Something went wrong. Retry!");
          userObj.put("email", mUserEmail);
          userObj.put("password", mUserPassword);
          holder.put("user", userObj);
          StringEntity se = new StringEntity(holder.toString());
          post.setEntity(se);

          post.setHeader("Accept", "application/json");
          post.setHeader("Content-type", "application/json");

          ResponseHandler<String> responseHandler = new BasicResponseHandler();
          response = client.execute(post, responseHandler);
          json = new JSONObject(response);
        } catch (HttpResponseException e) {
          e.printStackTrace();
          Log.e("ClientProtocol", "" + e);
          json.put("info", "Email and/or password are invalid. Retry!");
        } catch (IOException e) {
          e.printStackTrace();
          Log.e("IO", "" + e);
        }
      } catch (JSONException e) {
        e.printStackTrace();
        Log.e("JSON", "" + e);
      }

      return json;
    }