List of usage examples for java.net HttpURLConnection setUseCaches
public void setUseCaches(boolean usecaches)
From source file:com.mycompany.grupo6ti.GenericResource.java
@POST @Produces("application/json") @Path("/pagarFactura/{id}") public String pagarFactura(@PathParam("id") String id) { try {/* w w w . j a va2 s. c o m*/ URL url = new URL("http://localhost:85/pay"); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); InputStream is; conn.setRequestProperty("Accept-Charset", "UTF-8"); conn.setRequestProperty("Content-Type", "application/json"); conn.setUseCaches(true); conn.setRequestMethod("POST"); conn.setDoOutput(true); conn.setDoInput(true); String idJson = "{\n" + " \"id\": \"" + id + "\"\n" + "}"; //String idJson2 = "[\"Test\", \"Funcionando Bien\"]"; OutputStreamWriter out = new OutputStreamWriter(conn.getOutputStream()); out.write(idJson); out.flush(); out.close(); if (conn.getResponseCode() >= 400) { is = conn.getErrorStream(); } else { is = conn.getInputStream(); } String result2 = ""; BufferedReader rd = new BufferedReader(new InputStreamReader(is)); String line; while ((line = rd.readLine()) != null) { result2 += line; } rd.close(); return result2; } catch (IOException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } return ("[\"Test\", \"Funcionando Bien\"]"); }
From source file:com.mycompany.grupo6ti.GenericResource.java
@POST @Produces("application/json") @Path("/rechazarFactura/{id}/{motivo}") public String rechazarFactura(@PathParam("id") String id, @PathParam("motivo") String motivo) { try {/* w w w . ja v a 2s . c o m*/ URL url = new URL("http://localhost:85/reject/"); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); InputStream is; conn.setRequestProperty("Accept-Charset", "UTF-8"); conn.setRequestProperty("Content-Type", "application/json"); conn.setUseCaches(true); conn.setRequestMethod("POST"); conn.setDoOutput(true); conn.setDoInput(true); String idJson = "{\n" + " \"id\": \"" + id + "\",\n" + " \"motivo\": \"" + motivo + "\"\n" + "}"; //String idJson2 = "[\"Test\", \"Funcionando Bien\"]"; OutputStreamWriter out = new OutputStreamWriter(conn.getOutputStream()); out.write(idJson); out.flush(); out.close(); if (conn.getResponseCode() >= 400) { is = conn.getErrorStream(); } else { is = conn.getInputStream(); } String result2 = ""; BufferedReader rd = new BufferedReader(new InputStreamReader(is)); String line; while ((line = rd.readLine()) != null) { result2 += line; } rd.close(); return result2; } catch (IOException e) { e.printStackTrace(); return ("[\"Test\", \"Funcionando Bien1\"]"); } catch (Exception e) { e.printStackTrace(); return ("[\"Test\", \"Funcionando Bien2\"]"); } //return ("[\"Test\", \"Funcionando Bien\"]"); }
From source file:com.mycompany.grupo6ti.GenericResource.java
@POST @Produces("application/json") @Path("/recepcionarOc/{id}") public String recepcionarOc(@PathParam("id") String id) { try {//from ww w.j a v a 2s. co m URL url = new URL("http://localhost:83/recepcionar/" + id); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); InputStream is; conn.setRequestProperty("Accept-Charset", "UTF-8"); conn.setRequestProperty("Content-Type", "application/json"); conn.setUseCaches(true); conn.setRequestMethod("POST"); conn.setDoOutput(true); conn.setDoInput(true); String idJson = "{\n" + " \"id\": \"" + id + "\"\n" + "}"; //String idJson2 = "[\"Test\", \"Funcionando Bien\"]"; OutputStreamWriter out = new OutputStreamWriter(conn.getOutputStream()); out.write(idJson); out.flush(); out.close(); if (conn.getResponseCode() >= 400) { is = conn.getErrorStream(); } else { is = conn.getInputStream(); } String result2 = ""; BufferedReader rd = new BufferedReader(new InputStreamReader(is)); String line; while ((line = rd.readLine()) != null) { result2 += line; } rd.close(); return result2; } catch (IOException e) { e.printStackTrace(); return ("[\"Test\", \"Funcionando Bien1\"]"); } catch (Exception e) { e.printStackTrace(); return ("[\"Test\", \"Funcionando Bien2\"]"); } //return ("[\"Test\", \"Funcionando Bien\"]"); }
From source file:com.mycompany.grupo6ti.GenericResource.java
@POST @Produces("application/json") @Path("/rechazarOc/{id}/{rechazo}") public String rechazarOc(@PathParam("id") String id, @PathParam("rechazo") String rechazo) { try {/*from w w w . ja v a2 s . c om*/ URL url = new URL("http://localhost:83/rechazar/" + id); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); InputStream is; conn.setRequestProperty("Accept-Charset", "UTF-8"); conn.setRequestProperty("Content-Type", "application/json"); conn.setUseCaches(true); conn.setRequestMethod("POST"); conn.setDoOutput(true); conn.setDoInput(true); String idJson = "{\n" + " \"rechazo\": \"" + rechazo + "\"\n" + "}"; //String idJson2 = "[\"Test\", \"Funcionando Bien\"]"; OutputStreamWriter out = new OutputStreamWriter(conn.getOutputStream()); out.write(idJson); out.flush(); out.close(); if (conn.getResponseCode() >= 400) { is = conn.getErrorStream(); } else { is = conn.getInputStream(); } String result2 = ""; BufferedReader rd = new BufferedReader(new InputStreamReader(is)); String line; while ((line = rd.readLine()) != null) { result2 += line; } rd.close(); return result2; } catch (IOException e) { e.printStackTrace(); return ("[\"Test\", \"Funcionando Bien1\"]"); } catch (Exception e) { e.printStackTrace(); return ("[\"Test\", \"Funcionando Bien2\"]"); } //return ("[\"Test\", \"Funcionando Bien\"]"); }
From source file:com.mycompany.grupo6ti.GenericResource.java
@POST //? @Produces("application/json") @Path("/despacharProducto/{id}") public String despacharOc(@PathParam("id") String id) { try {// w ww . jav a2 s . com URL url = new URL("http://localhost:83/despachar/" + id); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); InputStream is; conn.setRequestProperty("Accept-Charset", "UTF-8"); conn.setRequestProperty("Content-Type", "application/json"); conn.setUseCaches(true); conn.setRequestMethod("POST"); conn.setDoOutput(true); conn.setDoInput(true); String idJson = "{\n" + " \"id\": \"" + id + "\"\n" + "}"; //String idJson2 = "[\"Test\", \"Funcionando Bien\"]"; OutputStreamWriter out = new OutputStreamWriter(conn.getOutputStream()); out.write(idJson); out.flush(); out.close(); if (conn.getResponseCode() >= 400) { is = conn.getErrorStream(); } else { is = conn.getInputStream(); } String result2 = ""; BufferedReader rd = new BufferedReader(new InputStreamReader(is)); String line; while ((line = rd.readLine()) != null) { result2 += line; } rd.close(); return result2; } catch (IOException e) { e.printStackTrace(); return ("[\"Test\", \"Funcionando Bien1\"]"); } catch (Exception e) { e.printStackTrace(); return ("[\"Test\", \"Funcionando Bien2\"]"); } //return ("[\"Test\", \"Funcionando Bien\"]"); }
From source file:com.openshift.internal.restclient.http.UrlConnectionHttpClient.java
protected HttpURLConnection createConnection(URL url, String userAgent, String acceptedVersion, String acceptedMediaType, ISSLCertificateCallback callback, int timeout) throws IOException { HttpURLConnection connection = (HttpURLConnection) url.openConnection(); if (isHttps(url)) { HttpsURLConnection httpsConnection = (HttpsURLConnection) connection; SSLContext sslContext = setSSLCallback(sslAuthorizationCallback, url, httpsConnection); setFilteredCiphers(excludedSSLCipherRegex, sslContext, httpsConnection); }/*from ww w . ja v a2 s . co m*/ setAuthorization(connection); connection.setUseCaches(false); connection.setDoInput(true); connection.setAllowUserInteraction(false); setConnectTimeout(NO_TIMEOUT, connection); setReadTimeout(timeout, connection); // wont work when switching http->https // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4620571 connection.setInstanceFollowRedirects(true); setUserAgent(userAgent, connection); setAcceptHeader(acceptedVersion, acceptedMediaType, connection); return connection; }
From source file:com.mycompany.grupo6ti.GenericResource.java
@PUT @Produces("application/json") @Path("/nuevaOc/{canal}/{cant}/{sku}/{proveedor}/{cliente}/{precio}/{fechae}") public String hacerOrdenCompra(@PathParam("canal") String canal, @PathParam("cant") String cant, @PathParam("sku") String sku, @PathParam("proveedor") String proveedor, @PathParam("cliente") String cliente, @PathParam("precio") String precio, @PathParam("fechae") String fechae) throws MalformedURLException, IOException { try {/*from w w w . j a v a 2 s.c o m*/ URL url = new URL("http://localhost:83/crear"); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); InputStream is; conn.setRequestProperty("Accept-Charset", "UTF-8"); conn.setRequestProperty("Content-Type", "application/json"); conn.setUseCaches(true); conn.setRequestMethod("PUT"); conn.setDoOutput(true); conn.setDoInput(true); String sss = "{\n" + " \"cliente\": \"" + cliente + "\",\n" + " \"proveedor\": \"" + proveedor + "\",\n" + " \"sku\": \"" + sku + "\",\n" + " \"fechaEntrega\": \"" + fechae + "\",\n" + " \"precioUnitario\": \"" + precio + "\",\n" + " \"cantidad\": \"" + cant + "\",\n" + " \"canal\": \"" + canal + "\"\n" + "}"; OutputStreamWriter out = new OutputStreamWriter(conn.getOutputStream()); out.write(sss); out.flush(); out.close(); if (conn.getResponseCode() >= 400) { is = conn.getErrorStream(); } else { is = conn.getInputStream(); } String result2 = ""; BufferedReader rd = new BufferedReader(new InputStreamReader(is)); String line; while ((line = rd.readLine()) != null) { result2 += line; } rd.close(); return result2; } catch (IOException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } return ("[\"Test\", \"Funcionando Bien\"]"); }
From source file:com.mycompany.grupo6ti.GenericResource.java
@DELETE @Produces("application/json") @Path("/anularOc/{id}/{motivo}") public String anularOc(@PathParam("id") String id, @PathParam("motivo") String motivo) { try {//from w w w. j a v a 2 s . c om URL url = new URL("http://localhost:83/anular/" + id); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); InputStream is; conn.setRequestProperty("Accept-Charset", "UTF-8"); conn.setRequestProperty("Content-Type", "application/json"); conn.setUseCaches(true); //conn.setRequestMethod("DELETE"); conn.setRequestMethod("POST"); // We have to override the post method so we can send data conn.setRequestProperty("X-HTTP-Method-Override", "DELETE"); conn.setDoOutput(true); conn.setDoInput(true); String idJson = "{\n" + " \"anulacion\": \"" + motivo + "\"\n" + "}"; //String idJson2 = "[\"Test\", \"Funcionando Bien\"]"; OutputStreamWriter out = new OutputStreamWriter(conn.getOutputStream()); out.write(idJson); out.flush(); out.close(); if (conn.getResponseCode() >= 400) { is = conn.getErrorStream(); } else { is = conn.getInputStream(); } String result2 = ""; BufferedReader rd = new BufferedReader(new InputStreamReader(is)); String line; while ((line = rd.readLine()) != null) { result2 += line; } rd.close(); return result2; } catch (IOException e) { e.printStackTrace(); return ("[\"Test\", \"Funcionando Bien1\"]"); } catch (Exception e) { e.printStackTrace(); return ("[\"Test\", \"Funcionando Bien2\"]"); } }
From source file:org.atricore.idbus.capabilities.josso.test.JOSSO11WebSSORouteTest.java
private String executePost(String targetURL, String urlParameters) { URL url;/*w w w .j a v a 2s .com*/ HttpURLConnection connection = null; try { //Create connection url = new URL(targetURL); connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("POST"); connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); connection.setRequestProperty("Content-Length", "" + Integer.toString(urlParameters.getBytes().length)); connection.setRequestProperty("Content-Language", "en-US"); connection.setUseCaches(false); connection.setDoInput(true); connection.setDoOutput(true); //Send request DataOutputStream wr = new DataOutputStream(connection.getOutputStream()); wr.writeBytes(urlParameters); wr.flush(); wr.close(); //Get Response InputStream is = connection.getInputStream(); BufferedReader rd = new BufferedReader(new InputStreamReader(is)); String line; StringBuffer response = new StringBuffer(); while ((line = rd.readLine()) != null) { response.append(line); response.append('\r'); } rd.close(); return response.toString(); } catch (Exception e) { e.printStackTrace(); return null; } finally { if (connection != null) { connection.disconnect(); } } }
From source file:calliope.db.CouchConnection.java
/** * Remove a document from the database/*from w ww.ja v a 2 s. co m*/ * @param db the database name * @param docID the docid of the resource * @param json the json to put there * @return the server response */ @Override public String removeFromDb(String db, String docID) throws AeseException { HttpURLConnection conn = null; try { String login = (user == null) ? "" : user + ":" + password + "@"; docID = convertDocID(docID); String revid = getRevId(db, docID); if (revid != null && revid.length() > 0) { String url = "http://" + login + host + ":" + dbPort + "/" + db + "/" + docID + "?rev=" + revid; URL u = new URL(url); conn = (HttpURLConnection) u.openConnection(); conn.setRequestMethod("DELETE"); conn.setUseCaches(false); conn.setDoOutput(true); //Get Response return readResponse(conn, 0L, ""); } else // it's not there, so do nothing return ""; } catch (Exception e) { throw new AeseException(e); } }