List of usage examples for java.net URLConnection setDoInput
public void setDoInput(boolean doinput)
From source file:io.druid.examples.web.WebJsonSupplier.java
@Override public BufferedReader getInput() throws IOException { URLConnection connection = url.openConnection(); connection.setDoInput(true); return new BufferedReader(new InputStreamReader(url.openStream(), Charsets.UTF_8)); }
From source file:org.apache.servicemix.samples.cxf_osgi.Client.java
public void sendRequest() throws Exception { URLConnection connection = new URL("http://localhost:8181/cxf/HelloWorld").openConnection(); connection.setDoInput(true); connection.setDoOutput(true);/*ww w .j a v a 2s . c om*/ OutputStream os = connection.getOutputStream(); // Post the request file. InputStream fis = getClass().getClassLoader() .getResourceAsStream("org/apache/servicemix/samples/cxf_osgi/request.xml"); IOUtils.copy(fis, os); // Read the response. InputStream is = connection.getInputStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); IOUtils.copy(is, baos); System.out.println("the response is =====>"); System.out.println(baos.toString()); }
From source file:org.apache.servicemix.examples.cxf.Client.java
public void sendRequest() throws Exception { URLConnection connection = new URL("http://localhost:8181/cxf/HelloWorldSecurity").openConnection(); connection.setDoInput(true); connection.setDoOutput(true);//from w w w . ja v a 2 s. co m OutputStream os = connection.getOutputStream(); // Post the request file. InputStream fis = getClass().getClassLoader() .getResourceAsStream("org/apache/servicemix/examples/cxf/request.xml"); IOUtils.copy(fis, os); // Read the response. InputStream is = connection.getInputStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); IOUtils.copy(is, baos); System.out.println("the response is =====>"); System.out.println(baos.toString()); }
From source file:org.apache.servicemix.examples.cxf.wsaddressing.Client.java
public void sendRequest() throws Exception { URLConnection connection = new URL("http://localhost:8181/cxf/SoapContext/SoapPort").openConnection(); connection.setDoInput(true); connection.setDoOutput(true);//from www . j av a2 s. c om OutputStream os = connection.getOutputStream(); // Post the request file. InputStream fis = getClass().getClassLoader() .getResourceAsStream("org/apache/servicemix/examples/cxf/wsaddressing/request.xml"); IOUtils.copy(fis, os); // Read the response. InputStream is = connection.getInputStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); IOUtils.copy(is, baos); System.out.println("the response is =====>"); System.out.println(baos.toString()); }
From source file:org.apache.axis2.transport.testkit.http.JavaNetRESTClient.java
public void sendMessage(ClientOptions options, ContentType contentType, RESTMessage message) throws Exception { StringBuilder url = new StringBuilder(); url.append(channel.getEndpointReference().getAddress()); url.append("/default"); String queryString = message.getQueryString(); if (queryString.length() > 0) { url.append('?'); url.append(queryString);/*from w w w . j a v a 2s .c o m*/ } URLConnection connection = new URL(url.toString()).openConnection(); connection.setDoInput(true); InputStream in = connection.getInputStream(); IOUtils.copy(in, System.out); in.close(); }
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;//w w w . j av a2 s. c o 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.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/*from w ww . j a v a 2s.c om*/ * @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:eu.europa.ec.markt.dss.applet.io.NativeHTTPDataLoader.java
@Override public InputStream post(String url, InputStream content) throws CannotFetchDataException { try {// ww w .j a v a 2 s. co 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:io.v.positioning.gae.ServletPostAsyncTask.java
@Override protected String doInBackground(Context... params) { mContext = params[0];//from w w w. j a v a 2 s.co m DataOutputStream os = null; InputStream is = null; try { URLConnection conn = mUrl.openConnection(); conn.setDoOutput(true); conn.setDoInput(true); conn.setUseCaches(false); conn.setRequestProperty("Content-Type", "application/json; charset=UTF-8"); conn.connect(); os = new DataOutputStream(conn.getOutputStream()); os.write(mData.toString().getBytes("UTF-8")); is = conn.getInputStream(); BufferedReader br = new BufferedReader(new InputStreamReader(is)); return br.readLine(); } catch (IOException e) { return "IOException while contacting GEA: " + e.getMessage(); } catch (Exception e) { return "Exception while contacting GEA: " + e.getLocalizedMessage(); } finally { if (os != null) try { os.close(); } catch (IOException e) { return "IOException closing os: " + e.getMessage(); } if (is != null) try { is.close(); } catch (IOException e) { return "IOException closing is: " + e.getMessage(); } } }
From source file:util.connection.AnonymousClient.java
public String download(URL source) throws IOException { // set the request URL URL request = new URL(source, source.getFile(), handler); // send request and receive response log.info("download (start) from source=" + source); URLConnection connection = request.openConnection(); connection.setDoOutput(true);/* ww w .j ava2 s .c om*/ connection.setDoInput(true); connection.setUseCaches(false); connection.setAllowUserInteraction(false); connection.connect(); String responsebody = IOUtils.toString(connection.getInputStream(), "UTF-8"); // read the response netLayer.clear(); netLayer.waitUntilReady(); return responsebody; }