List of usage examples for java.net URLConnection setDoOutput
public void setDoOutput(boolean dooutput)
From source file:org.silverpeas.calendar.ServletConnector.java
/** * Open a connection to the Silverpeas calendar importation servlet. * * @return a URLConnection object to connect to the Silverpeas calendar importation servlet. * @throws MalformedURLException/*ww w .j av a 2 s .c o m*/ * @throws IOException */ private final URLConnection getServletConnection() throws MalformedURLException, IOException { URL urlServlet = new URL(servletURL); URLConnection con = urlServlet.openConnection(); con.setDoInput(true); con.setDoOutput(true); con.setUseCaches(false); con.setRequestProperty("Content-Type", "application/json"); return con; }
From source file:org.digidoc4j.impl.bdoc.SKTimestampDataLoader.java
@Override public byte[] post(String url, byte[] content) { logger.info("Getting timestamp from " + url); OutputStream out = null;/*from w ww. java 2 s . co m*/ InputStream inputStream = null; byte[] result = null; try { URLConnection connection = new URL(url).openConnection(); connection.setDoInput(true); connection.setDoOutput(true); connection.setUseCaches(false); connection.setRequestProperty("Content-Type", "application/timestamp-query"); connection.setRequestProperty("Content-Transfer-Encoding", "binary"); connection.setRequestProperty("User-Agent", userAgent); out = connection.getOutputStream(); IOUtils.write(content, out); inputStream = connection.getInputStream(); result = IOUtils.toByteArray(inputStream); } catch (IOException e) { throw new DSSException("An error occured while HTTP POST for url '" + url + "' : " + e.getMessage(), e); } finally { IOUtils.closeQuietly(out); IOUtils.closeQuietly(inputStream); } return result; }
From source file:org.apache.servicemix.http.HttpAddressingTest.java
public void testOkFromUrl() throws Exception { URLConnection connection = new URL("http://localhost:8192/Service/").openConnection(); connection.setDoOutput(true); connection.setDoInput(true);/* w w w .ja va 2 s.c o m*/ OutputStream os = connection.getOutputStream(); // Post the request file. InputStream fis = getClass().getResourceAsStream("addressing-request.xml"); FileUtil.copyInputStream(fis, os); // Read the response. InputStream is = connection.getInputStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); FileUtil.copyInputStream(is, baos); log.info(baos.toString()); }
From source file:org.wisdom.openid.connect.service.internal.DefaultIssuer.java
@Validate public void start() throws Exception { URL endpoint = new URL(endpointUrl); URLConnection connection = endpoint.openConnection(); connection.setDoOutput(true); connection.setDoInput(true);//ww w . j a v a2 s . co m InputStream stream = connection.getInputStream(); config = new ObjectMapper().readValue(stream, WellKnownOpenIdConfiguration.class); stream.close(); issuerId = config.getIssuer(); }
From source file:com.simplenoteapp.test.Test.java
/** * Base 64 encode the given data and post it to uri. * @param uri to which the data is to be posted * @param postData string to be converted to UTF-8, then encoded * as base 64 and posted to uri/*from ww w . ja v a 2s. c o m*/ * @return content returned from the request * @throws IOException */ public String postBase64(String uriString, String postData) throws IOException { Test.log("postBase64 uri=" + uriString + " data=" + postData); byte[] base64 = Base64.encodeBase64(postData.getBytes(), false, false); Test.log("base64=" + new String(base64)); URL url = new URL(uriString); URLConnection conn = url.openConnection(); conn.setDoOutput(true); OutputStream out = conn.getOutputStream(); out.write(base64); out.flush(); String response = readResponse(conn.getInputStream()); out.close(); return response; }
From source file:key.access.manager.HttpHandler.java
public String connect(String url, ArrayList data) throws IOException { try {//w w w. j a v a 2 s. com // open a connection to the site URL connectionUrl = new URL(url); URLConnection con = connectionUrl.openConnection(); // activate the output con.setDoOutput(true); PrintStream ps = new PrintStream(con.getOutputStream()); // send your parameters to your site for (int i = 0; i < data.size(); i++) { ps.print(data.get(i)); //System.out.println(data.get(i)); if (i != data.size() - 1) { ps.print("&"); } } // we have to get the input stream in order to actually send the request InputStream inStream = con.getInputStream(); Scanner s = new Scanner(inStream).useDelimiter("\\A"); String result = s.hasNext() ? s.next() : ""; System.out.println(result); // close the print stream ps.close(); return result; } catch (MalformedURLException e) { e.printStackTrace(); return "error"; } catch (IOException e) { e.printStackTrace(); return "error"; } }
From source file:org.intermine.bio.web.logic.LiftOverService.java
/** * Send a HTTP POST request to liftOver service. * * @param grsc the Genomic Region Search constraint * @param org human or mouse// w ww . j a va2 s . c o m * @param genomeVersionSource older genome version * @param genomeVersionTarget intermine genome version * @param liftOverServerURL url * @return a list of GenomicRegion */ public String doLiftOver(GenomicRegionSearchConstraint grsc, String org, String genomeVersionSource, String genomeVersionTarget, String liftOverServerURL) { List<GenomicRegion> genomicRegionList = grsc.getGenomicRegionList(); String liftOverResponse; String coords = converToBED(genomicRegionList); String organism = ORGANISM_COMMON_NAME_MAP.get(org); try { // Construct data String data = URLEncoder.encode("coords", "UTF-8") + "=" + URLEncoder.encode(coords, "UTF-8"); data += "&" + URLEncoder.encode("source", "UTF-8") + "=" + URLEncoder.encode(genomeVersionSource, "UTF-8"); data += "&" + URLEncoder.encode("target", "UTF-8") + "=" + URLEncoder.encode(genomeVersionTarget, "UTF-8"); // Send data URL url; // liftOverServerURL ends with "/" if (!liftOverServerURL.endsWith("/")) { url = new URL(liftOverServerURL + "/" + organism); } else { url = new URL(liftOverServerURL + organism); } URLConnection conn = url.openConnection(); conn.setDoOutput(true); OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream()); wr.write(data); wr.flush(); wr.close(); liftOverResponse = new String(IOUtils.toCharArray(conn.getInputStream())); LOG.info("LiftOver response message: \n" + liftOverResponse); } catch (Exception e) { e.printStackTrace(); return null; } return liftOverResponse; }
From source file:eu.europa.ec.markt.dss.applet.io.NativeHTTPDataLoader.java
@Override public InputStream post(String url, InputStream content) throws CannotFetchDataException { try {// w w w.java 2s . c o m URLConnection connection = new URL(url).openConnection(); connection.setDoInput(true); connection.setDoOutput(true); connection.setUseCaches(false); OutputStream out = connection.getOutputStream(); IOUtils.copy(content, out); out.close(); return connection.getInputStream(); } catch (IOException ex) { throw new CannotFetchDataException(ex, url); } }
From source file:org.fusesource.cloudmix.agent.webapp.WebappTest.java
protected HttpURLConnection getHttpConnection(String target, boolean doOutput) throws Exception { URL url = new URL(target); URLConnection connection = url.openConnection(); connection.setDoOutput(doOutput); assertTrue(connection instanceof HttpURLConnection); return (HttpURLConnection) connection; }
From source file:com.google.ie.common.util.ReCaptchaUtility.java
/** * /*ww w . java 2 s.co m*/ * This method makes a post request to captcha server for verification of * captcha. * * @param postUrl the url of the server * @param postParameters the parameters making the post request * @return String the message from the server in response to the request * posted * @throws IOException */ private String sendPostRequest(String postUrl, String postParameters) throws IOException { OutputStream out = null; String message = null; InputStream in = null; try { URL url = new URL(postUrl); /* open connection with settings */ URLConnection urlConnection = url.openConnection(); urlConnection.setDoOutput(true); urlConnection.setDoInput(true); /* open output stream */ out = urlConnection.getOutputStream(); out.write(postParameters.getBytes()); out.flush(); /* open input stream */ in = urlConnection.getInputStream(); /* get output */ ByteArrayOutputStream bout = new ByteArrayOutputStream(); byte[] buf = new byte[1024]; while (true) { int rc = in.read(buf); if (rc <= 0) break; bout.write(buf, 0, rc); } message = bout.toString(); /* close streams */ out.close(); in.close(); return message; } catch (IOException e) { LOG.error("Cannot load URL: " + e.getMessage()); out.close(); in.close(); return null; } }