IoT CAS Frameworks/IOT_Applications/Admin_GUI_Application/source/SA-DeskAdminTool/src/java/OrderDetails/HttpRequestPoster.java
public static void postData(Reader data, URL endpoint, Writer output) throws Exception {
        HttpURLConnection urlc = null;
        try {
            urlc = (HttpURLConnection) endpoint.openConnection();
            try {
                urlc.setRequestMethod("POST");
            } catch (ProtocolException e) {
                throw new Exception("Shouldn't happen: HttpURLConnection doesn't support POST??", e);
            }
            urlc.setDoOutput(true);
            urlc.setDoInput(true);
            urlc.setUseCaches(false);
            urlc.setAllowUserInteraction(false);
            urlc.setRequestProperty("Content-type", "text/xml; charset=" + "UTF-8");

            OutputStream out = urlc.getOutputStream();

            try {
                log.info("=============== Storing the file ===============");
                Writer writer = new OutputStreamWriter(out, "UTF-8");
                pipe(data, writer);
                writer.close();
            } catch (IOException e) {
                throw new Exception("IOException while posting data", e);
            } finally {
                if (out != null) {
                    out.close();
                }
            }

            InputStream in = urlc.getInputStream();
            try {
                log.info("************** Getting the file ****************");
                Reader reader = new InputStreamReader(in);
                pipe(reader, output);
                reader.close();
                log.debug("=================== Reader object closed ================");
            } catch (IOException e) {
                throw new Exception("IOException while reading response", e);
            } finally {
                if (in != null) {
                    in.close();
                }
            }

        } catch (IOException e) {
            throw new Exception("Connection error (is server running at " + endpoint + " ?): " + e);
        } finally {
            if (urlc != null) {
                urlc.disconnect();
            }
        }
    }
/**
     * Reads data from the data reader and posts it to a server via POST request.
     * data - The data you want to send
     * endpoint - The server's address
     * output - writes the server's response to output
     * @throws Exception
     */
Reads data from the data reader and posts it to a server via POST request.
data - The data you want to send
endpoint - The server's address
output - writes the server's response to output
@throws Exception
Reads data from the data reader and posts it to a server via POST request . data - The data you want to send endpoint - The server ' s address output - writes the server ' s response to output @throws Exception
public static void postData(Reader data, URL endpoint, Writer output) throws Exception {
        HttpURLConnection urlc = null;
        try {
            urlc = (HttpURLConnection) endpoint.openConnection();
            try {
                urlc.setRequestMethod("POST");
            } catch (ProtocolException e) {
                throw new Exception("Shouldn't happen: HttpURLConnection doesn't support POST??", e);
            }
            urlc.setDoOutput(true);
            urlc.setDoInput(true);
            urlc.setUseCaches(false);
            urlc.setAllowUserInteraction(false);
            urlc.setRequestProperty("Content-type", "text/xml; charset=" + "UTF-8");
            OutputStream out = urlc.getOutputStream();
            try {
                log.info("=============== Storing the file ===============");
                Writer writer = new OutputStreamWriter(out, "UTF-8");
                pipe(data, writer);
                writer.close();
            } catch (IOException e) {
                throw new Exception("IOException while posting data", e);
            } finally {
                if (out != null) {
                    out.close();
                }
            }
            InputStream in = urlc.getInputStream();
            try {
                log.info("************** Getting the file ****************");
                Reader reader = new InputStreamReader(in);
                pipe(reader, output);
                reader.close();
                log.debug("=================== Reader object closed ================");
            } catch (IOException e) {
                throw new Exception("IOException while reading response", e);
            } finally {
                if (in != null) {
                    in.close();
                }
            }
        } catch (IOException e) {
            throw new Exception("Connection error (is server running at " + endpoint + " ?): " + e);
        } finally {
            if (urlc != null) {
                urlc.disconnect();
            }
        }
    }
public static void postData ( Reader data , URL endpoint , Writer output ) throws Exception { HttpURLConnection urlc = null ; try { urlc = ( HttpURLConnection ) endpoint . openConnection ( ) ; try { urlc . setRequestMethod ( "POST" ) ; } catch ( ProtocolException e ) { throw new Exception ( "Shouldn't happen: HttpURLConnection doesn't support POST??" , e ) ; } urlc . setDoOutput ( true ) ; urlc . setDoInput ( true ) ; urlc . setUseCaches ( false ) ; urlc . setAllowUserInteraction ( false ) ; urlc . setRequestProperty ( "Content-type" , "text/xml; charset=" + "UTF-8" ) ; OutputStream out = urlc . getOutputStream ( ) ; try { log . info ( "=============== Storing the file ===============" ) ; Writer writer = new OutputStreamWriter ( out , "UTF-8" ) ; pipe ( data , writer ) ; writer . close ( ) ; } catch ( IOException e ) { throw new Exception ( "IOException while posting data" , e ) ; } finally { if ( out != null ) { out . close ( ) ; } } InputStream in = urlc . getInputStream ( ) ; try { log . info ( "************** Getting the file ****************" ) ; Reader reader = new InputStreamReader ( in ) ; pipe ( reader , output ) ; reader . close ( ) ; log . debug ( "=================== Reader object closed ================" ) ; } catch ( IOException e ) { throw new Exception ( "IOException while reading response" , e ) ; } finally { if ( in != null ) { in . close ( ) ; } } } catch ( IOException e ) { throw new Exception ( "Connection error (is server running at " + endpoint + " ?): " + e ) ; } finally { if ( urlc != null ) { urlc . disconnect ( ) ; } } }
Reads data from the data reader and posts it to a server via POST request.
Reads data from the data reader and posts it to a server via POST request .