List of usage examples for com.squareup.okhttp FormEncodingBuilder FormEncodingBuilder
FormEncodingBuilder
From source file:au.com.wallaceit.reddinator.RedditData.java
License:Open Source License
private String redditApiRequest(String urlStr, String method, int oauthMode, HashMap<String, String> formData) throws RedditApiException { String json;//from w w w . j a v a2 s . c o m // create client if null if (httpClient == null) { createHttpClient(); } try { Request.Builder httpRequest = new Request.Builder().url(urlStr); RequestBody httpRequestBody; String requestStr = ""; if (formData != null) { FormEncodingBuilder formBuilder = new FormEncodingBuilder(); Iterator iterator = formData.keySet().iterator(); String key; while (iterator.hasNext()) { key = (String) iterator.next(); formBuilder.add(key, formData.get(key)); } httpRequestBody = formBuilder.build(); } else { if (!method.equals("GET")) { int queryIndex = urlStr.indexOf("?"); if (queryIndex != -1) urlStr = urlStr.substring(queryIndex); requestStr = URLEncoder.encode(urlStr, "UTF-8"); } httpRequestBody = RequestBody.create(POST_ENCODED, requestStr); } switch (method) { case "POST": httpRequest.post(httpRequestBody); break; case "PUT": httpRequest.put(httpRequestBody); break; case "DELETE": httpRequest.delete(httpRequestBody); break; case "GET": default: httpRequest.get(); break; } if (oauthMode == REQUEST_MODE_OAUTHREQ) { // For oauth token retrieval and refresh httpRequest.addHeader("Authorization", "Basic " + Base64 .encodeToString((OAUTH_CLIENTID + ":").getBytes(), Base64.URL_SAFE | Base64.NO_WRAP)); } else if (isLoggedIn() && oauthMode == REQUEST_MODE_AUTHED) { if (isTokenExpired()) { refreshToken(); } // add auth headers String tokenStr = getTokenValue("token_type") + " " + getTokenValue("access_token"); httpRequest.addHeader("Authorization", tokenStr); } Response response = httpClient.newCall(httpRequest.build()).execute(); json = response.body().string(); int errorCode = response.code(); if (errorCode < 200 && errorCode > 202) { String errorMsg = getErrorText(json); throw new RedditApiException( "Error " + String.valueOf(errorCode) + ": " + (errorMsg.equals("") ? response.message() : errorMsg) + (errorCode == 403 ? " (Authorization with Reddit required)" : ""), errorCode == 403, errorCode); } } catch (IOException e) { e.printStackTrace(); throw new RedditApiException("Error: " + e.getMessage()); } return json; }
From source file:clienteconecta.cola.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed if (!this.jTextField1.getText().equals("") && esNumero(this.jTextField1.getText())) { String parametro = this.jTextField1.getText(); RequestBody formBody = new FormEncodingBuilder().add("parametro", parametro).build(); String salida = getString("queue", formBody); String cmd = "cmd /c dot -Tpng C:\\Users\\Ottoniel\\Desktop\\ytemporal\\cola.dot > C:\\Users\\Ottoniel\\Desktop\\ytemporal\\cola.png"; try {//w w w . j a v a 2 s . c o m Process child = Runtime.getRuntime().exec(cmd); } catch (IOException ex) { Logger.getLogger(lista.class.getName()).log(Level.SEVERE, null, ex); } this.jTextField1.setText(""); } //GEN-LAST:event_jButton1ActionPerformed }
From source file:clienteconecta.cola.java
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed String parametro = " xdd"; RequestBody formBody = new FormEncodingBuilder().add("parametro", parametro).build(); String salida = getString("dequeue", formBody); System.out.println(salida);//from w ww . ja v a 2s. c o m String cmd = "cmd /c dot -Tpng C:\\Users\\Ottoniel\\Desktop\\ytemporal\\cola.dot > C:\\Users\\Ottoniel\\Desktop\\ytemporal\\cola.png"; try { Process child = Runtime.getRuntime().exec(cmd); } catch (IOException ex) { Logger.getLogger(lista.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:clienteconecta.lista.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed if (!this.jTextField1.getText().equals("")) { String parametro = this.jTextField1.getText(); RequestBody formBody = new FormEncodingBuilder().add("parametro", parametro).build(); String salida = getString("insertarLista", formBody); String cmd = "cmd /c dot -Tpng C:\\Users\\Ottoniel\\Desktop\\ytemporal\\lista.dot > C:\\Users\\Ottoniel\\Desktop\\ytemporal\\lista.png"; try {/* w ww . j a va2 s .c om*/ Process child = Runtime.getRuntime().exec(cmd); } catch (IOException ex) { Logger.getLogger(lista.class.getName()).log(Level.SEVERE, null, ex); } this.jTextField1.setText(""); } }
From source file:clienteconecta.lista.java
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed if (!this.jTextField2.getText().equals("") && esNumero(this.jTextField2.getText())) { String parametro = this.jTextField2.getText(); RequestBody formBody = new FormEncodingBuilder().add("parametro", parametro).build(); String salida = getString("eliminarLista", formBody); String cmd = "cmd /c dot -Tpng C:\\Users\\Ottoniel\\Desktop\\ytemporal\\lista.dot > C:\\Users\\Ottoniel\\Desktop\\ytemporal\\lista.png"; try {/*from w w w.j a v a2 s . c om*/ Process child = Runtime.getRuntime().exec(cmd); } catch (IOException ex) { Logger.getLogger(lista.class.getName()).log(Level.SEVERE, null, ex); } this.jTextField2.setText(""); } }
From source file:clienteconecta.lista.java
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed if (!this.jTextField3.getText().equals("")) { String parametro = this.jTextField3.getText(); RequestBody formBody = new FormEncodingBuilder().add("parametro", parametro).build(); String salida = getString("buscarLista", formBody); System.out.println(salida); this.jTextField3.setText(""); }/*from w w w. j a v a 2s.co m*/ }
From source file:clienteconecta.matriz.java
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed if (!this.jTextField2.getText().equals("")) { String parametro = this.jTextField2.getText(); RequestBody formBody = new FormEncodingBuilder().add("parametro", parametro).build(); String salida = getString("eliminarMatriz", formBody); String cmd = "cmd /c dot -Tpng C:\\Users\\Ottoniel\\Desktop\\ytemporal\\matriz.dot > C:\\Users\\Ottoniel\\Desktop\\ytemporal\\matriz.png"; try {//from w w w . j a v a 2 s . c o m Process child = Runtime.getRuntime().exec(cmd); } catch (IOException ex) { Logger.getLogger(lista.class.getName()).log(Level.SEVERE, null, ex); } this.jTextField2.setText(""); } // TODO add your handling code here: }
From source file:clienteconecta.matriz.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed if (!this.jTextField1.getText().equals("")) { String parametro = this.jTextField1.getText(); RequestBody formBody = new FormEncodingBuilder().add("parametro", parametro).build(); String salida = getString("insertarMatriz", formBody); String cmd = "cmd /c dot -Tpng C:\\Users\\Ottoniel\\Desktop\\ytemporal\\matriz.dot > C:\\Users\\Ottoniel\\Desktop\\ytemporal\\matriz.png"; try {/*from ww w. ja v a 2 s . c om*/ Process child = Runtime.getRuntime().exec(cmd); } catch (IOException ex) { Logger.getLogger(lista.class.getName()).log(Level.SEVERE, null, ex); } this.jTextField1.setText(""); } }
From source file:clienteconecta.matriz.java
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed if (!this.jTextField3.getText().equals("") && esChar(this.jTextField3.getText())) { String parametro = this.jTextField3.getText(); RequestBody formBody = new FormEncodingBuilder().add("parametro", parametro).build(); String salida = getString("buscarPorLetra", formBody); System.out.println(salida); String cmd = "cmd /c dot -Tpng C:\\Users\\Ottoniel\\Desktop\\ytemporal\\matriz.dot > C:\\Users\\Ottoniel\\Desktop\\ytemporal\\matriz.png"; try {/*from w ww. j a v a 2 s. c o m*/ Process child = Runtime.getRuntime().exec(cmd); } catch (IOException ex) { Logger.getLogger(lista.class.getName()).log(Level.SEVERE, null, ex); } this.jTextField3.setText(""); } }
From source file:clienteconecta.matriz.java
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed if (!this.jTextField4.getText().equals("")) { String parametro = this.jTextField4.getText(); RequestBody formBody = new FormEncodingBuilder().add("parametro", parametro).build(); String salida = getString("buscarPorDominio", formBody); System.out.println(salida); String cmd = "cmd /c dot -Tpng C:\\Users\\Ottoniel\\Desktop\\ytemporal\\matriz.dot > C:\\Users\\Ottoniel\\Desktop\\ytemporal\\matriz.png"; try {//from www .jav a2 s. c om Process child = Runtime.getRuntime().exec(cmd); } catch (IOException ex) { Logger.getLogger(lista.class.getName()).log(Level.SEVERE, null, ex); } this.jTextField4.setText(""); } }