@Override
  protected void onHandleIntent(Intent intent) {

    ApplicationController app = ((ApplicationController) getApplicationContext());
    UsuarioDTO user = app.getUserLogin();

    Map<String, Integer> parms = new HashMap<String, Integer>();
    parms.put("id", user.getId());

    restTemp.setErrorHandler(new RestResponseErrorHandler<String>(String.class));
    Intent intentBack = new Intent(Constantes.GET_AMIGOS_FILTRO_ACTION);

    try {

      UsuarioDTO[] respuesta =
          restTemp.getForObject(Constantes.GET_AMIGOS_SERVICE_URL, UsuarioDTO[].class, parms);

      intentBack.putExtra("respuesta", Util.getArrayListUsuarioDTO(respuesta));

    } catch (RestResponseException e) {
      String msg = e.getMensaje();
      intentBack.putExtra("error", msg);
    } catch (ResourceAccessException e) {
      Log.e(TAG, e.getMessage());
      intentBack.putExtra("error", Constantes.MSG_ERROR_TIMEOUT);
    }

    this.sendBroadcast(intentBack);
  }
    @Override
    protected Message doInBackground(Void... params) {
      final String url = getString(R.string.base_uri) + "/getmessage";

      // Populate the HTTP Basic Authentitcation header with the username and password
      HttpAuthentication authHeader = new HttpBasicAuthentication(username, password);
      HttpHeaders requestHeaders = new HttpHeaders();
      requestHeaders.setAuthorization(authHeader);
      requestHeaders.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));

      // Create a new RestTemplate instance
      RestTemplate restTemplate = new RestTemplate();
      restTemplate.getMessageConverters().add(new MappingJacksonHttpMessageConverter());

      try {
        // Make the network request
        Log.d(TAG, url);
        ResponseEntity<Message> response =
            restTemplate.exchange(
                url, HttpMethod.GET, new HttpEntity<Object>(requestHeaders), Message.class);
        return response.getBody();
      } catch (HttpClientErrorException e) {
        Log.e(TAG, e.getLocalizedMessage(), e);
        return new Message(0, e.getStatusText(), e.getLocalizedMessage());
      } catch (ResourceAccessException e) {
        Log.e(TAG, e.getLocalizedMessage(), e);
        return new Message(0, e.getClass().getSimpleName(), e.getLocalizedMessage());
      }
    }
Example #3
0
 public void validateServer() throws ServerValidationException {
   try {
     AdminConfig adminConfig = new AdminConfig();
     adminConfig.setHost(host);
     adminConfig.setUsername(username);
     adminConfig.setPassword(password);
     AdminManager am = new AdminManager(adminConfig);
     String versionString = am.getServerVersion();
     int major = Integer.parseInt(versionString.substring(0, 1));
     int minor = Integer.parseInt(versionString.substring(2, 3) + versionString.substring(4, 5));
     if (major < 8 || minor < 4) {
       throw new ServerValidationException("Invalid MarkLogic Server Version: " + versionString);
     }
   } catch (ResourceAccessException e) {
     throw new ServerValidationException(e.toString());
   }
 }
  @Override
  protected void onHandleIntent(Intent intent) {

    String pass = intent.getStringExtra("pass");
    String email = intent.getStringExtra("email");
    Intent intentLogin = new Intent(Constantes.LOGIN_FILTRO_ACTION);
    try {

      Map<String, String> parms = new HashMap<String, String>();
      parms.put("email", email);
      parms.put("pass", pass);
      restTemp.setErrorHandler(new RestResponseErrorHandler<String>(String.class));

      UsuarioDTO user =
          restTemp.getForObject(Constantes.LOGIN_SERVICE_URL, UsuarioDTO.class, parms);

      if (user.getEmail() != null) {
        ApplicationController app = ((ApplicationController) getApplicationContext());
        app.setUserLogin(user);

        // /////////////////////////////////////////////////
        // Cargo las categorias

        CategoriaDTO[] respuesta =
            restTemp.getForObject(Constantes.GET_CATEGORIAS_SERVICE_URL, CategoriaDTO[].class);

        CategoriasUtil.cargarCategorias(this, Util.getArrayListCategoriaDTO(respuesta));
        // ///////////////////////////////////////////////

      }
      intentLogin.putExtra("usuario", user);
      sendBroadcast(intentLogin);

    } catch (RestResponseException e) {

      intentLogin.putExtra("error", (String) e.getResponseEntity().getBody());
      Log.e(TAG, (String) e.getResponseEntity().getBody());
      sendBroadcast(intentLogin);
    } catch (ResourceAccessException e) {
      intentLogin.putExtra("error", Constantes.MSG_ERROR_TIMEOUT);
      Log.e(TAG, e.getMessage());
      sendBroadcast(intentLogin);
    }
  }