Monday, July 4, 2011

Using HttpURLConnection to send request data to servlet server

An code snippet for writing request data from servlet server:
-------------------------------------------------------------------------------------------
URL news = new URL("your URL");
news = new URL("http://140.114.85.85:8080/GetXMLFile/GetXML?key1="+IdList);
String sendIdList = URLEncoder.encode(IdList);
 //for sending data to servlet
 HttpURLConnection connection = (HttpURLConnection) news.openConnection();
  // just want to do an HTTP GET here
connection.setRequestMethod("POST");
connection.setDoOutput(true);
connection.setRequestProperty("key1",sendIdList);
// give it 15 seconds to respond
connection.setReadTimeout(15*1000);
connection.connect();    
            
-------------------------------------------------------------------------------------------

Then, to receive the response data from servlet server:
-------------------------------------------------------------------------------------------

//for reading the data response
BufferedReader in = new BufferedReader(new InputStreamReader(news.openStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
    {
       response.getWriter().write(inputLine);
    }
in.close();
isDone = true; 

-------------------------------------------------------------------------------------------

on the servlet server side, using the request.getParameter("key") inside the methed doPost.

Thursday, April 14, 2011

HyperTerminal replacement in Ubuntu - Minicom

setup minicom (for serial port)
  1. By default, minicom is not installed in Ubuntu, so you need to install it first.
    sudo apt-get install minicom
  2. Find the name of your Serial Port
    dmesg | grep tty
    In the output look for something like "tty". The output in my case is like this:
    $ dmesg | grep tty
    [ 17.341823] serial8250: ttyS0 at I/O 0x3f8 (irq = 4) is a 16550A
    [ 17.342454] 00:0b: ttyS0 at I/O 0x3f8 (irq = 4) is a 16550A
    This means the device correspond to my serial port is ttyS0.
  3. Configure minicom
    sudo minicom -s
    • Use the keyboard keys to select the menu item Serial port setup.
    • Enter A to change the Serial Device to /dev/ttyS0, and then enter E to change the line speed to 9600 8N1
    • Using arrow keys, select Save setup as dfl
  4. Select Exit from Minicom.
  5. Next time, from the terminal you only need to run sudo minicom in order to access your Cisco box. 
(http://strdoc.com/hyperterminal-replacement-ubuntu-minicom)
Link to grabserial:   http://elinux.org/Grabserial#Download_and_Installation