Example usage for com.squareup.okhttp FormEncodingBuilder FormEncodingBuilder

List of usage examples for com.squareup.okhttp FormEncodingBuilder FormEncodingBuilder

Introduction

In this page you can find the example usage for com.squareup.okhttp FormEncodingBuilder FormEncodingBuilder.

Prototype

FormEncodingBuilder

Source Link

Usage

From source file:servlets.login.java

private static boolean loggear(String user, String pass, String empresa, String depto) {
    RequestBody rb = new FormEncodingBuilder().add("usuario", user).add("password", pass)
            .add("empresa", empresa).add("departamento", depto).build();
    String res = Conexion.consultar("verificarLogin", rb);
    if (res.equals("existe")) {
        return true;
    } else {/*from   w w w .j a  v  a 2  s. c  om*/
        return false;
    }
}

From source file:servlets.modify.java

private static boolean modificarActivo(String user, String empresa, String depto, String id, String desc) {
    RequestBody rb = new FormEncodingBuilder().add("usuario", user).add("departamento", depto)
            .add("empresa", empresa).add("descripcion", desc).add("id", id).build();
    String res = Conexion.consultar("modificarActivo", rb);
    System.out.println(res);//from   www  . j  a  va2  s.  co  m
    if (res.equals("modificado")) {
        return true;
    } else {
        return false;
    }
}

From source file:servlets.signup.java

private static boolean registrarUser(String user, String pass, String nombre, String empresa, String depto) {
    RequestBody rb = new FormEncodingBuilder().add("nombre", nombre).add("usuario", user)
            .add("departamento", depto).add("empresa", empresa).add("password", pass).build();
    String res = Conexion.consultar("insertarUsuario", rb);
    System.out.println(res);/*ww w  . ja  v  a2  s.c om*/
    if (res.equals("inserto")) {
        return true;
    } else {
        return false;
    }
}

From source file:sistemacontrolvuelos.ControlVuelos.java

private void jbtn_enviarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtn_enviarActionPerformed
    if (jtxt_contra.getText().length() >= 6) {
        try {//w ww  . ja  v  a2 s.c o  m
            // TODO add your handling code here:
            RequestBody formBody = new FormEncodingBuilder().add("id", jtxt_id.getText())
                    .add("nombre", jtxt_nombre.getText()).add("pais", jtxt_pais.getText())
                    .add("contra", jtxt_contra.getText()).build();

            String res = post(servidorDir + "/aeropuerto/crear", formBody);
            String text;
            JSONObject a = new JSONObject(res);
            if (a.get("created").toString().equals("true")) {
                text = "Aeropuerto creado con exito.";
            } else {
                text = "Error!! Aeropuerto no creado, id seleccionado ya exite.";
            }
            JOptionPane.showMessageDialog(null, text);
        } catch (IOException ex) {
            Logger.getLogger(ControlVuelos.class.getName()).log(Level.SEVERE, null, ex);
        }
    } else {
        JOptionPane.showMessageDialog(null, "La Contrasea debe tener almenos 6 caraceres!");
    }
}

From source file:sistemacontrolvuelos.ControlVuelos.java

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
    // TODO add your handling code here:
    try {/*from   w w w.j a v  a2 s.c o m*/
        RequestBody formBody = new FormEncodingBuilder().add("id_fly", jtxt_id_c.getText())
                .add("origin", jcb_origen_c.getSelectedItem().toString())
                .add("destiny", jcb_destino_c.getSelectedItem().toString())
                .add("date_out", jtxt_fecha_salida_c.getText()).add("date_in", jtxt_fecha_llegada_c.getText())
                .add("price_fc", jtxt_precio_pc_c.getText()).add("price_tc", jtxt_precio_ct_c.getText())
                .add("price_ec", jtxt_precio_ce_c.getText()).add("amount_fc", jtxt_cantidad_pc_c.getText())
                .add("amount_tc", jtxt_cantidad_ct_c.getText()).add("amount_ec", jtxt_cantidad_ce_c.getText())
                .add("state", jcb_estado_c.getSelectedItem().toString()).build();

        String res = post(servidorDir + "/vuelo/crear", formBody);
        String text;
        JSONObject a = new JSONObject(res);
        if (a.get("created").toString().equals("true")) {
            text = "Vuelo creado con exito.";
            c++;
            jtxt_id_c.setText("vuelo" + c);
            jtxt_fecha_salida_c.setText("");
            jtxt_fecha_llegada_c.setText("");
            jtxt_precio_pc_c.setText("");
            jtxt_precio_ct_c.setText("");
            jtxt_precio_ce_c.setText("");
            jtxt_cantidad_pc_c.setText("");
            jtxt_cantidad_ct_c.setText("");
            jtxt_cantidad_ce_c.setText("");
        } else {
            text = "Error!! Vuelo no creado, id seleccionado ya exite.";
        }
        JOptionPane.showMessageDialog(null, text);
    } catch (IOException ex) {
        Logger.getLogger(ControlVuelos.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:sistemacontrolvuelos.ControlVuelos.java

private void jbtn_seleccionarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtn_seleccionarActionPerformed
    // TODO add your handling code here:
    try {//from ww  w  .  ja v a2 s  .c om
        if (jcb_vuelos_e.getSelectedItem() != null) {
            RequestBody formBody = new FormEncodingBuilder()
                    .add("id_fly", jcb_vuelos_e.getSelectedItem().toString()).build();

            String res = post(servidorDir + "/vuelo/id", formBody);
            JSONObject a = new JSONObject(res);
            jtxt_origen_e.setText((String) a.get("origin"));
            jtxt_destino_e.setText((String) a.get("destiny"));
            jtxt_fecha_salida_e.setText((String) a.get("date_out"));
            jtxt_fecha_llegada_e.setText((String) a.get("date_in"));
            jtxt_precio_pc_e.setText((String) a.get("price_fc"));
            jtxt_precio_ct_e.setText((String) a.get("price_tc"));
            jtxt_precio_ce_e.setText((String) a.get("price_ec"));
            jtxt_cantidad_pc_e.setText((String) a.get("amount_fc"));
            jtxt_cantidad_ct_e.setText((String) a.get("amount_tc"));
            jtxt_cantidad_ce_e.setText((String) a.get("amount_ec"));
            jtxt_estado_e.setText((String) a.get("state"));
            jbtn_enArribo.setEnabled(true);
            jbtn_enVuelo.setEnabled(true);
            jbtn_actualizar.setEnabled(true);
        } else {
            JOptionPane.showMessageDialog(null, "Seleccione un vuelo");
        }
    } catch (IOException ex) {
        Logger.getLogger(ControlVuelos.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:sistemacontrolvuelos.ControlVuelos.java

private void jbtn_eliminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtn_eliminarActionPerformed
    // TODO add your handling code here:
    try {/*  w  w w.j ava  2  s .co  m*/
        RequestBody formBody = new FormEncodingBuilder()
                .add("id_fly", jcb_vuelos_e.getSelectedItem().toString()).add("state", jtxt_estado_e.getText())
                .build();

        String res = post(servidorDir + "/vuelo/eliminar", formBody);
        String text = "";
        JSONObject a = new JSONObject(res);
        System.out.println(a.get("deleted"));
        if (a.get("deleted").toString().equals("true")) {
            text = "Vuelo elimininado con exito.";
            actualizarEditar();
        } else {
            text = "Vuelo no elimininado, actualmente volando.";
        }
        JOptionPane.showMessageDialog(null, text);
    } catch (IOException ex) {
        Logger.getLogger(ControlVuelos.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:sistemacontrolvuelos.ControlVuelos.java

private void actualizarVuelo() {
    try {/*from w w w . ja v a  2 s . c om*/
        RequestBody formBody = new FormEncodingBuilder()
                .add("id_fly", jcb_vuelos_e.getSelectedItem().toString())
                .add("date_out", jtxt_fecha_salida_e.getText()).add("date_in", jtxt_fecha_llegada_e.getText())
                .add("price_fc", jtxt_precio_pc_e.getText()).add("price_tc", jtxt_precio_ct_e.getText())
                .add("price_ec", jtxt_precio_ce_e.getText()).add("amount_fc", jtxt_cantidad_pc_e.getText())
                .add("amount_tc", jtxt_cantidad_ct_e.getText()).add("amount_ec", jtxt_cantidad_ce_e.getText())
                .add("state", jtxt_estado_e.getText()).build();

        String res = post(servidorDir + "/vuelo/actualizar", formBody);
        String text = "";
        JSONObject a = new JSONObject(res);
        if (a.get("updated").toString().equals("true")) {
            text = "Vuelo actualizado con exito.";
        }
        JOptionPane.showMessageDialog(null, text);
    } catch (IOException ex) {
        Logger.getLogger(ControlVuelos.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:studio.imedia.vehicleinspection.activity.PersonalInfoActivity.java

/**
 * ?/*  ww w  .  ja va  2  s.  co m*/
 *
 * @param urlSB
 * @param avatarPath
 */
private void uploadInfo(StringBuffer urlSB, String avatarPath) {
    Log.d("submit", "url " + urlSB.toString());
    String url = urlSB.toString();
    int id = (int) SPUtil.get(mContext, Constant.Key.USER_ID, Constant.Type.INTEGER);
    mUsername = tvUsername.getText().toString().trim();
    String gender = tvGender.getText().toString();
    if (gender.equals(""))
        mGender = MALE;
    else
        mGender = FEMALE;
    mSignature = etSignature.getText().toString().trim();

    // ?
    FormEncodingBuilder formEncodingBuilder = new FormEncodingBuilder();
    formEncodingBuilder.add("id", String.valueOf(id)).add("name", mUsername)
            .add("gender", String.valueOf(mGender)).add("signature", mSignature);
    if (isAvatarUpdate && avatarPath != null)
        formEncodingBuilder.add("avatar", avatarPath);

    RequestBody formBody = formEncodingBuilder.build();

    final Request request = new Request.Builder().url(url).post(formBody).build();

    mClient.newCall(request).enqueue(new Callback() {
        @Override
        public void onFailure(Request request, IOException e) {
            Toast.makeText(mContext, "??", Toast.LENGTH_SHORT).show();
            e.printStackTrace();
        }

        @Override
        public void onResponse(Response response) throws IOException {
            if (!response.isSuccessful())
                throw new IOException("Unexpected code " + response);

            String jsonStr = response.body().string();
            Log.d("submit", "json " + jsonStr);
            try {
                int status = new JSONObject(jsonStr).getInt("status");
                if (status == 0)
                    mHandler.sendEmptyMessage(MSG_UPLOAD_INFO_SUCCESS);
                else
                    mHandler.sendEmptyMessage(MSG_UPLOAD_INFO_FAIL);
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    });
}

From source file:studio.imedia.vehicleinspection.fragments.CarInfoFragment.java

/**
 * ?/*from  w w w .  j  av  a  2s .  c  o m*/
 */
private void uploadCarInfo(StringBuffer urlSB, String picPath) {
    String url = urlSB.toString();
    // ??
    mLicensePicPath = picPath;
    mDetailedAddress = tvCity.getText().toString().trim();
    mEngineNum = etEngineNum.getText().toString().trim();
    mRegisterTime = tvRegisterDate.getText().toString().trim();

    // ?...
    FormEncodingBuilder formEncodingBuilder = new FormEncodingBuilder().add("id", String.valueOf(mId))
            .add("carBrandId", String.valueOf(mCarBrandId)).add("carTypeId", String.valueOf(mCarTypeId))
            .add("engineNum", mEngineNum).add("registerTime", mRegisterTime)
            .add("provinId", String.valueOf(mProvinceId)) // ?id
            .add("cityId", String.valueOf(mCityId)).add("countyId", String.valueOf(mCountyId))
            .add("detailedAddress", mDetailedAddress);
    if (isLicenseUpdate && picPath != null)
        formEncodingBuilder.add("licensePic", mLicensePicPath);

    RequestBody formBody = formEncodingBuilder.build();

    Request request = new Request.Builder().url(url).post(formBody).build();

    mClient.newCall(request).enqueue(new Callback() {
        @Override
        public void onFailure(Request request, IOException e) {
            mHandler.sendEmptyMessage(CONNECT_FAIL);
        }

        @Override
        public void onResponse(Response response) throws IOException {
            if (!response.isSuccessful())
                throw new IOException("Unexpected code " + response);

            String jsonStr = response.body().string();
            try {
                int status = new JSONObject(jsonStr).getInt("status");
                if (status == 0) {
                    mHandler.sendEmptyMessage(MSG_UP_INFO_SUCCESS);
                } else {
                    mHandler.sendEmptyMessage(MSG_UP_INFO_FAIL);
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    });
}