OutputStreamWriter to String??

I am trying to read in an XML file (which works correctly) and write the output to a String. I have the following code which works correctly:
public void characters( char[] ch, int start, int length )
throws SAXException {
try {
OutputStreamWriter outw = new OutputStreamWriter(System.out);
outw.write( ch, start,length );
outw.flush();
} catch (Exception e) {
e.printStackTrace();
I'm sure my problem is not difficult, instead of writing the string to the screen ... :
OutputStreamWriter outw = new OutputStreamWriter(System.out);
outw.write( ch, start,length ); //writes to screen
... I would like to write this data to a string and use it later. I need someone who is familiar with OutputStreamWriter to tell me how to do this.
Please help, I can't afford to rip any more hair out!!!

Hello Mike,
If all you need to do is read an Xml and assign its contents to a string, once you have a document object (instance of class: org.w3c.dom.Document) created, you can extract the string representation of it using its toString method.
eg: String strXml = document.toString();
Hope that helps.
Regards,
Kunal

Similar Messages

  • OutputStreamWriter encoding for XML

    Hi all,
    I am trying to write a string to a XML file and I tried using OutputStreamWriter as follows.Altough it creates the file,it does not write anything to the file.Can someone tell me why it is not writing to the file?Is it necessary to specify the encoding 8859_1 for writing to a XML file?
    try
    OutputStreamWriter out;
    String path="sample.xml";
    FileOutputStream fout = new FileOutputStream(path);
    BufferedOutputStream bout= new BufferedOutputStream(fout);
    out = new OutputStreamWriter(bout, "8859_1");
    out.write("Writing to XML file");
              catch(Exception e)
                   System.out.println("Error");
    Thanks for your help.

    You need to close the OutputStreamWriter.
    Edited by: sabre150 on Jan 24, 2008 11:31 AM

  • How to upload file from java client to php

    hi
    i am trying to upload/send a file from client using swing/applet
    and receiving it with php code.
    here is the php code which uploads the post file from the client
    $uploaddir = "/home/raghavendra/Documents/";
    $file = basename( $_FILES["uploadedfile"]["name"]);
    echo "file:\n".$file;
    $uploadfile = $uploaddir. $file;
    if (move_uploaded_file($_FILES["uploadedfile"]["tmp_name"],$uploadfile)) {
    echo "File is valid, and was successfully uploaded.\n";
    else {
    echo "File upload failure Possible file upload attack!\n";
    and corresponding different java code which post the
    1)
    public void postmethodTest(String filefrom){
    try{
    String hostname = "localhost";
    int port = 80;
    InetAddress addr = InetAddress.getByName(hostname);
    Socket socket = new Socket(addr, port);
    // Send header
    String path ="/php_prgs/var/www/nsboxng/htdocs/tryupdate.php";
    File theFile = new File(filefrom);
    System.out.println ("size: " + (int) theFile.length());
    DataInputStream fis = new DataInputStream(new BufferedInputStream(new FileInputStream(theFile)));
    byte[] theData = new byte[(int) theFile.length( )];
    fis.readFully(theData);
    fis.close();
    DataOutputStream raw = new DataOutputStream(socket.getOutputStream());
    Writer wr = new OutputStreamWriter(raw);
    String command =
    "POST "+path+" HTTP/1.0\r\n"
    + "Content-type: multipart/form-data, boundary=mango\r\n"
    + "Content-length: " + ((int) theFile.length()) + "\r\n"
    + "\r\n"
    + "--mango\r\n"
    + "content-disposition: name=\"MAX_FILE_SIZE\"\r\n"
    + "\r\n"
    + "\r\n--mango\r\n"
    + "content-disposition: attachment; name=\"datafile\"" ;
    String filename="test.doc\"\r\n"
    + "Content-Type: text/doc\r\n"
    + "Content-Transfer-Encoding: binary\r\n"
    + "\r\n";
    wr.write(command);
    wr.flush();
    raw.write(theData);
    raw.flush( );
    wr.write("\r\n--mango--\r\n");
    wr.flush( );
    BufferedReader rd = new BufferedReader(new
    InputStreamReader(socket.getInputStream()));
    String line;
    while ((line = rd.readLine()) != null) {
    System.out.println("out"+line);
    wr.close();
    raw.close();
    socket.close();
    } catch (Exception e) {System.out.println(e.toString());}
    2)
    public void postMethod(String strURL, String filefrom){
    try {
    String fname = filefrom.substring(filefrom.lastIndexOf("/")+1, filefrom.length());
    File input=new File(filefrom);
    // Prepare HTTP post
    PostMethod post = new PostMethod(strURL);
    // Request content will be retrieved directly
    // from the input stream
    // Per default, the request content needs to be buffered
    // in order to determine its length.
    // Request body buffering can be avoided when
    // content length is explicitly specified
    post.setRequestEntity(new InputStreamRequestEntity(new FileInputStream(input), input.length()));
    // Specify content type and encoding
    // If content encoding is not explicitly specified
    // ISO-8859-1 is assumed
    //post.setRequestHeader("Content-type", "text/xml; charset=ISO-8859-1");
    post.setRequestHeader("Content-Type","multipart/form-data");
    post.setRequestHeader("Content-Disposition", "form-data; name="+fname);
    // Get HTTP client
    HttpClient httpclient = new HttpClient();
    // Execute request
    try {
    int result=httpclient.executeMethod(post);
    // Display status code
    System.out.println("Response status code: " +result);
    // Display response
    System.out.println("Response body: ");
    // System.out.println(post.getResponseBodyAsString());
    BufferedReader console = new BufferedReader(new InputStreamReader(post.getResponseBodyAsStream()));
    String name = null;
    String line = null;
    try {
    while ((line = console.readLine()) != null) {
    System.out.println("output"+line);
    //name = console.readLine();
    catch (IOException e) { name = "<" + e + ">"; }
    // System.out.println("Hello " + name);
    } finally {
    // Release current connection to the connection pool
    // once you are done
    post.releaseConnection();
    catch(IOException e){
    but am getting else condition response from php code
    but if i post with html code it is working fine.
    can anybody help me please where i have to change the code
    please suggest me. am in a big trouble and i have to complete this as soon as possible

    One thread is enough.
    http://forum.java.sun.com/thread.jspa?threadID=5198449
    You could have bumped it instead. Also, you still just posted a junk of unformatted stuff. Furthermore, for HttpClient support ask at an HttpClient mailing list of rorum.

  • Exact same request works in browser but not in my app!!!

    Hello all, I have an application that posts requests through an https connection to a web server. When everything goes well, the server is supposed to send me an xml file. Once my String is encoded and ready to be sent, it looks something like this:
    InputSegments=%3c%3fxml+version%3d%221.0%22+encoding%3d%22UTF-8%22%3f%3e%3cCNCustTransmitToEfx+So when I send it, I receive an error from the server saying that the request is incorrect. But when I copy paste the request String to the browser, it works great!!! I tried to change requestMethod to GET, but I still get the error message from the server. So I can't figure out what is wrong here... I am posting my function hoping that somebody will be able to help me:
    private static class SecuredConnectionInstantiator extends Thread
        public boolean stop = false;
        private int returnCode = -1;
        private String securedUrl = null;
        private String xmlRequest = null;
        private String outputFile = null;
        public void run()
          try
            URL objUrl = null;
            HttpsURLConnection urlc = null;
            String inputLine = null;
            StringBuffer xmlResponse = null;
            xmlResponse = new StringBuffer();
            objUrl = new URL(securedUrl);
            urlc = (HttpsURLConnection)objUrl.openConnection();
            if (urlc == null || objUrl == null)
              throw new MalformedURLException();
            urlc.setUseCaches(false);
            urlc.setDoInput(true);
            urlc.setDoOutput(true);
            urlc.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
            urlc.setRequestMethod("POST");
            OutputStream out = urlc.getOutputStream();
            OutputStreamWriter writer = new OutputStreamWriter(out);
            String tmp = encode(xmlRequest);
            tmp = "InputSegments=" + tmp + "&cmdSubmit=Submit";
            System.out.println(tmp);
            writer.write(tmp);
            writer.flush();
            writer.close();
            //Si le thread n'a pas �t� intterompu, on obtient la r�ponse et on
            //l'enregistre sur disque.
            if (!stop)
              BufferedReader xmlResponseReader = new BufferedReader(new InputStreamReader(objUrl.openStream()));
              BufferedWriter xmlFileWriter = new BufferedWriter(new FileWriter(outputFile));
              while ((inputLine = xmlResponseReader.readLine()) != null)
                xmlResponse.append(inputLine + EOL);
                xmlFileWriter.write(inputLine);
                xmlFileWriter.flush();
              xmlResponseReader.close();
              xmlFileWriter.close();
              //La requ�te s'est termin�e normalement...
              returnCode = 0;
          catch (MalformedURLException e)
            //Erreur lors de l'appel...
            //returnCode = code d'erreur...
          catch (IOException e)
            //Erreur d'E/S...
            //returnCode = code d'erreur...
        }Your help will be greatly appreciated!
    Alex

    I solved the problem, I dont know if it's a good way to do this, but here's what I've done: Instead of opening a connection to the server and the send the request throug the stream, I open the connection and pass the request next to the server's address:
            xmlResponse = new StringBuffer();
            objUrl = new URL(securedUrl + "?InputSegments=" + URLEncoder.encode(xmlRequest, "UTF-8") + "&cmdSubmit=Submit");
            urlc = (HttpsURLConnection)objUrl.openConnection();Anyway thank you all for your help!

  • How to upload a file from java to php

    hi
    i am trying to upload/send a file from client using swing/applet
    and receiving it with php code.
    here is the php code which uploads the post file from the client
    $uploaddir = "/home/raghavendra/Documents/";
    $file = basename( $_FILES["uploadedfile"]["name"]);
    echo "file:\n".$file;
    $uploadfile = $uploaddir. $file;
    if (move_uploaded_file($_FILES["uploadedfile"]["tmp_name"],$uploadfile)) {
    echo "File is valid, and was successfully uploaded.\n";
    else {
    echo "File upload failure Possible file upload attack!\n";
    and corresponding different java code which post the
    1)
    public void postmethodTest(String filefrom){
    try{
    String hostname = "localhost";
    int port = 80;
    InetAddress addr = InetAddress.getByName(hostname);
    Socket socket = new Socket(addr, port);
    // Send header
    String path ="/php_prgs/var/www/nsboxng/htdocs/tryupdate.php";
    File theFile = new File(filefrom);
    System.out.println ("size: " + (int) theFile.length());
    DataInputStream fis = new DataInputStream(new BufferedInputStream(new FileInputStream(theFile)));
    byte[] theData = new byte[(int) theFile.length( )];
    fis.readFully(theData);
    fis.close();
    DataOutputStream raw = new DataOutputStream(socket.getOutputStream());
    Writer wr = new OutputStreamWriter(raw);
    String command =
    "POST "+path+" HTTP/1.0\r\n"
    + "Content-type: multipart/form-data, boundary=mango\r\n"
    + "Content-length: " + ((int) theFile.length()) + "\r\n"
    + "\r\n"
    + "--mango\r\n"
    + "content-disposition: name=\"MAX_FILE_SIZE\"\r\n"
    + "\r\n"
    + "\r\n--mango\r\n"
    + "content-disposition: attachment; name=\"datafile\"" ;
    String filename="test.doc\"\r\n"
    + "Content-Type: text/doc\r\n"
    + "Content-Transfer-Encoding: binary\r\n"
    + "\r\n";
    wr.write(command);
    wr.flush();
    raw.write(theData);
    raw.flush( );
    wr.write("\r\n--mango--\r\n");
    wr.flush( );
    BufferedReader rd = new BufferedReader(new
    InputStreamReader(socket.getInputStream()));
    String line;
    while ((line = rd.readLine()) != null) {
    System.out.println("out"+line);
    wr.close();
    raw.close();
    socket.close();
    } catch (Exception e) {System.out.println(e.toString());}
    2)
    public void postMethod(String strURL, String filefrom){
    try {
    String fname = filefrom.substring(filefrom.lastIndexOf("/")+1, filefrom.length());
    File input=new File(filefrom);
    // Prepare HTTP post
    PostMethod post = new PostMethod(strURL);
    // Request content will be retrieved directly
    // from the input stream
    // Per default, the request content needs to be buffered
    // in order to determine its length.
    // Request body buffering can be avoided when
    // content length is explicitly specified
    post.setRequestEntity(new InputStreamRequestEntity(new FileInputStream(input), input.length()));
    // Specify content type and encoding
    // If content encoding is not explicitly specified
    // ISO-8859-1 is assumed
    //post.setRequestHeader("Content-type", "text/xml; charset=ISO-8859-1");
    post.setRequestHeader("Content-Type","multipart/form-data");
    post.setRequestHeader("Content-Disposition", "form-data; name="+fname);
    // Get HTTP client
    HttpClient httpclient = new HttpClient();
    // Execute request
    try {
    int result=httpclient.executeMethod(post);
    // Display status code
    System.out.println("Response status code: " +result);
    // Display response
    System.out.println("Response body: ");
    // System.out.println(post.getResponseBodyAsString());
    BufferedReader console = new BufferedReader(new InputStreamReader(post.getResponseBodyAsStream()));
    String name = null;
    String line = null;
    try {
    while ((line = console.readLine()) != null) {
    System.out.println("output"+line);
    //name = console.readLine();
    catch (IOException e) { name = "<" + e + ">"; }
    // System.out.println("Hello " + name);
    } finally {
    // Release current connection to the connection pool
    // once you are done
    post.releaseConnection();
    catch(IOException e){
    but am getting else condition response from php code
    but if i post with html code it is working fine.
    can anybody help me please where i have to change the code
    please suggest me. am in a big trouble and i have to complete this as soon as possible

    Jakarta Commons HttpClient
    ~

  • Writing to .txt file

    Hi
    Thanks for any help and advice i got with my last problem, an other small problem i have. I'm tring to use a gui to write information to a file, its compling with no errors, creates the file but won't write any thing to it. I have it inside the try and catch no luck i've tried it out side the try and catch also. The same problem
    Any help would be great i know its only something small just can't see it
    Cheers
    Ambrose
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import java.io.*;
    public class Create_Mail extends JPanel implements ActionListener
    private JButton b1;
    private JButton b4;
    private JButton b2;
    private JButton b3;
    private JLabel l4;
    private JLabel l5;
    private JTextArea ta6;
    private JComboBox comb7;
    private JTextField t8;
    private JTextField t9;
    private JButton b10;
    private FileOutputStream fos;
         private PrintWriter out;
    public Create_Mail() {
    //construct preComponents
    String[] jcomp7Items = {"Ireland", "IP 1", "IP 2", "IP 3", "IP 4", "IP 5", "America", "IP1", "IP2", "IP3"};
    //construct components
    b1 = new JButton ("Save E-Mail");
    b4 = new JButton ("a");
    b2 = new JButton ("Exit System");
    b3 = new JButton ("Main Menu");
    l4 = new JLabel (" To :");
    l5 = new JLabel (" Subject :");
    ta6 = new JTextArea (5, 5);
    comb7 = new JComboBox (jcomp7Items);
    t8 = new JTextField (5);
    t9 = new JTextField (5);
    b10 = new JButton ("Calculate Size of E-Mail");
    //adjust size and set layout
    setPreferredSize (new Dimension (482, 488));
    setLayout (null);
    //add components
    add (b4);
    add (b1);
    add (b2);
    add (b3);
    add (l4);
    add (l5);
    add (ta6);
    add (comb7);
    add (t8);
    add (t9);
    add (b10);
    //set component bounds
    b1.setBounds (35, 360, 100, 20);
    b2.setBounds (160, 395, 105, 20);
    b3.setBounds (160, 360, 100, 20);
    b4.setBounds (100, 460, 95, 20);
    b10.setBounds (285, 360, 180, 20);
    l4.setBounds (25, 30, 100, 25);
    l5.setBounds (25, 80, 100, 25);
    ta6.setBounds (30, 150, 435, 165);
    comb7.setBounds (365, 35, 95, 20);
    t8.setBounds (135, 85, 210, 20);
    t9.setBounds (135, 35, 210, 20);
              b1.addActionListener(this);
              b2.addActionListener(this);
              b3.addActionListener(this);
              b4.addActionListener(this);
              b10.addActionListener(this);
    public void actionPerformed( ActionEvent e )
    //When the user hits the below button a comparsion is made
    //If it's true then its executes
    //The process is continued depending on the button the user hits
    System.out.println("button => "+ e.getActionCommand());
    if(( new String("a")).compareTo(e.getActionCommand()) == 0 )
    System.exit(0);
    if(( new String("Save E-Mail")).compareTo(e.getActionCommand()) == 0 )
    try
              fos = new FileOutputStream("E-mail.txt", true );
    out = new PrintWriter(new OutputStreamWriter(fos));
         String s1 = ta6.getText();
                   String s2 = t8.getText();
                   String s3 = t9.getText();
                   s1.trim();
                   s2.trim();
                   s3.trim();
                   System.out.println("Test in dos prompt");
                   out.println(s1 +"," s2 "," +s3);
                   ta6.setText("");
                   t8.setText("");
                   t9.setText("");     
              catch (Exception ex){}
    public static void main (String[] args)
    JFrame frame = new JFrame ("Create_Mail");
    frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
    System.out.println("fgfd");
    frame.getContentPane().add (new Create_Mail());
    frame.pack();
    frame.setVisible (true);
    }

    Hello Ambrose,
    for writing text into a file use a Writer, e.g.
    BufferedWriter outfile = new BufferedWriter(new FileWriter("E-mail.txt"));
    String s= s1 +"," +s2 +"," +s3;
    outfile.write(s,0,s.length());
    outfile.newLine();hth
    J�rg

  • I need a timer function to ping the server every 5 secs??using threads.

    I need a timer function to ping the server every 5 secs??
    using threads...i have to use a thread coz i cant use Timer and Timer Task coz clients r on the JDK1.2 version.I have created a thread which keeps checking th ping msg & any server msg is pings 4 the1st time properly but then it just waits to read the response from server but it doesnt but the server shows that it has send the msgs to client???PLEASE HELP URGENT

    Few things are not clear from your post, like, are you using sockets and if you are, how are u reading writing to them (ur sample code would help)...
    Anyways if you are, are you doing accept on your socket in a while(true) loop or just once... If you do it only once you will get the first ping message but none afterwards if the other side closes and opens new sockets for every send... What I am suggesting is something like the following:
    ss = new ServerSocket(port);
    while(true)
         s = ss.accept();
         is = s.getInputStream();
         os = s.getOutputStream();
         reader = new BufferedReader(new InputStreamReader(is));
         writer = new BufferedWriter(new OutputStreamWriter(os));
         String in = reader.readLine();
            // do something with this string
            s.close();
            // put some check here to break out of this infinite loop
    }// end of While

  • Java Mapping expert advice

    Hi all
    I am using Java mapping to replace a string with another string in my outputed xml file. the code i am using is
    package xi_test_package;
    import java.io.BufferedReader;
    import java.io.BufferedWriter;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.io.OutputStream;
    import java.io.OutputStreamWriter;
    import java.util.HashMap;
    import java.util.Map;
    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
    import com.sap.aii.mapping.api.StreamTransformation;
    import com.sap.aii.mapping.api.StreamTransformationException;
    public class Xi_test_class implements StreamTransformation {
          private Map param = null;
                public void setParameter (Map param) {
                      this.param = param;
                      if (param == null) {
                            this.param = new HashMap();
                public void execute(InputStream inStream, OutputStream outStream) throws StreamTransformationException{
                      try{
                            BufferedReader in = new BufferedReader(new InputStreamReader(inStream));
                            BufferedWriter out = new BufferedWriter(new OutputStreamWriter(outStream));
                            // The pattern matches control characters
                            Pattern p = Pattern.compile("ns0:");
                            Matcher m = p.matcher("");
                            String aLine = null;
                            while((aLine = in.readLine()) != null) {
                                 m.reset(aLine);
                                 //Replaces control characters with an empty string.
                                 String result = m.replaceAll("");
                                 out.write(result);
                                 out.newLine();
                            in.close();
                            out.close();                           
                      }catch(Exception e){
                            e.printStackTrace();
    I picked this code from a different blog,This code is basically replacing "ns0" with "" .  I am now required to tweak it so that the logic is like this .
    replace all "ns0:" with "" and replace all "ns1:" with "" and replace all "ns2:" with "com:" and replace all occurenaces except the first one of "ns4" with "" and all occureance except the first one of "ns5" with "main"
    How can i tweak the code to do all of these replacements in a single go
    your expert java advice is well appricited.
    Thank you

    Try this.. I have just removed few lines related to pattern and used another piece of code here..
    let me know if any issues..
    >
    >                         BufferedWriter out = new BufferedWriter(new OutputStreamWriter(outStream));
    >
    > >                      
    >                         String aLine = null;
    >                         int count = 0;
    >                         while((aLine = in.readLine()) != null) {
    >                            
    >                              
                                    if ( count > 0 )
    >                              out.write( aLine.replaceAll( "ns0:","" ).replaceAll("ns1:","").replaceAll("ns2:","com:").replaceAll("ns4","") );
                                   else
                                    out.write( aLine.replaceAll( "ns0:","" ).replaceAll("ns1:","").replaceAll("ns2:","com:") );
    >                              
    >                              out.newLine();
    >                              if ( aLine.indexOf( "ns4") > 0 ) count++;
    >                         }
    >

  • How to, login into the yahoo groups/clubs,....

    Hi,
    I would like to write a offline browser utility to follow up my yahoo groups and clubs.
    I took several attempts before I wrote this mail and I discoverd that it are the redirections and cookies that cause the problems.
    Does anyone know a class capable to download a URL dispite of cookies and redirections?
    I tried with the swing-brower that comes as example with the JDK but he has also problems with the cookies and redirections.
    Greetings
    Frank

    Hi,
    I found the sollution to my problem with the help of the sniplet of madhu77 "Dealing with cookies" from nov 8, 2000 10:05 AM
    I worte a class to login to the yahoo clubs, I just added the hidden parameters from HTML form, and two methods, one to retrieve the login page and a second to get a HashSet of String(URLs) to the clubs your a member of. The constructor accepts login name and password as parameters.
    import java.net.*;
    import java.io.*;
    import java.util.*;
    public class YahooClubsLogin
    private String loginName="";
    private String password="";
    private String loginPage="";
    public YahooClubsLogin(String pLoginName,String pPassword)
    try
    loginName=pLoginName;
    password=pPassword;
    String firstcookie="";
    URL u = new URL("http://clubs.yahoo.com/clubs.html");
    URLConnection uc = u.openConnection();
    HttpURLConnection huc = (HttpURLConnection)uc;
    huc.setFollowRedirects(false);
    String cookie1 = huc.getHeaderField("set-cookie");
    if(cookie1!=null)
    { int index = cookie1.indexOf(";");
    if(index > 0)
    firstcookie = cookie1.substring(0, index);
    URL loginurl = new URL("http://login.yahoo.com/config/login");
    URLConnection con = loginurl.openConnection();
    HttpURLConnection httpcon = (HttpURLConnection)con;
    httpcon.setDoInput(true);
    httpcon.setDoOutput(true);
    httpcon.setUseCaches(false);
    httpcon.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
    httpcon.setRequestProperty("Cookie", firstcookie);
    httpcon.setFollowRedirects(false);
    OutputStream raw = httpcon.getOutputStream();
    OutputStream buffered = new BufferedOutputStream(raw);
    OutputStreamWriter out = new OutputStreamWriter(buffered);
    String query = ".tries"+"="+URLEncoder.encode("1")+"&"+
    ".done"+"="+URLEncoder.encode("http://clubs.yahoo.com/clubs/")+"&"+
    ".src"+"="+URLEncoder.encode("grp")+"&"+
    ".intl"+"="+URLEncoder.encode("us")+"&"+
    "login"+"="+URLEncoder.encode(loginName)+"&"+
    "passwd"+"="+URLEncoder.encode(password)+"&"+
    ".persistent"+"="+URLEncoder.encode("Y")+"&"+
    ".chkP"+"="+URLEncoder.encode("Y")+"&"+
    "Submit"+"="+URLEncoder.encode("Login");
    out.write(query);
    out.write("\r\n");
    out.flush();
    out.close();
    for(int p=0; p<15 ; p++)
    String header2 = httpcon.getHeaderField(p);
    String key2 =httpcon.getHeaderFieldKey(p);
    String location = httpcon.getHeaderField("location");
    int j=1;
    int count = 0;
    String[] cookies = new String[4];
    while(httpcon.getHeaderFieldKey(j)!= null)
    String key =
    httpcon.getHeaderFieldKey(j).toLowerCase();
    if(key.indexOf("set-cookie")!=-1)
    String header = httpcon.getHeaderField(j);
    int ind = header.indexOf(";");
    if(ind > 0)
    String cookie = header.substring(0, ind);
    cookies[count] = cookie;
    count++;
    j++;
    String cookiestring = new String();
    for(int k=0; k<count; k++)
    cookiestring = cookiestring.concat(cookies[k]+";");
    URL verifyurl = new URL(location);
    URLConnection loccon = verifyurl.openConnection();
    HttpURLConnection lcon = (HttpURLConnection)loccon;
    lcon.setFollowRedirects(false);
    lcon.setRequestProperty("Cookie", cookiestring);
    for(int r=0; r<15 ; r++)
    String header3 = lcon.getHeaderField(r);
    String key3 = lcon.getHeaderFieldKey(r);
    int code = lcon.getResponseCode();
    String response =lcon.getResponseMessage();
    String location2 = lcon.getHeaderField("location");
    String secondcookie = new String();
    String cookie2 = lcon.getHeaderField("set-cookie");
    if(cookie2!=null)
    int index2 = cookie2.indexOf(";");
    if(index2 > 0)
    secondcookie = cookie2.substring(0, index2);
    secondcookie = cookiestring+";"+secondcookie;
    URL myurl = new URL(location2);
    URLConnection mycon = myurl.openConnection();
    HttpURLConnection hmycon = (HttpURLConnection)mycon;
    hmycon.setFollowRedirects(false);
    hmycon.setRequestProperty("Cookie", secondcookie);
    for(int s=0; s<15 ; s++)
    String header4 = hmycon.getHeaderField(s);
    String key4 = hmycon.getHeaderFieldKey(s);
    InputStream data = hmycon.getInputStream();
    InputStream in = new BufferedInputStream(data);
    Reader r = new InputStreamReader(in);
    StringBuffer tmpPage=new StringBuffer(20000);
    int c;
    while ((c = r.read())!= -1)
    tmpPage.append((char)c);
    loginPage = tmpPage.toString();
    catch(Exception e)
    String getLoginPage()
    return loginPage;
    HashSet getClubURLs()
    HashSet urls = new HashSet();
    int loginNamePos = loginPage.indexOf(loginName);
    int endOfClubsTable = loginPage.indexOf("/table>",loginNamePos);
    int positionOfClub = loginPage.indexOf("http://clubs.yahoo.com/clubs/",loginNamePos);
    while (positionOfClub > loginNamePos && positionOfClub < endOfClubsTable )
    int positionEndClub = loginPage.indexOf("\">",positionOfClub);
    urls.add(loginPage.substring(positionOfClub,positionEndClub));
    positionOfClub = loginPage.indexOf("http://clubs.yahoo.com/clubs/",positionEndClub);
    return urls;

  • Thai Language Encoding with TIS-620

    Hi All,
    I have a file which has few Thai language words.I need to decode with TIS-620 charset.
    I have tried with a standalone program.When I run the program and try to print the local lang program..it simply prints ??? in Eclipse console......When I try to print the Byte Array with the charset Name=TIS-620, it gives me..[B@7d772e  and when I try to print it after decode the array of bytes with given char set as ISO8859_1..it prints some garbage characters....��������
    I am attaching the java code I have been trying and also the file which I am trying to read.
    {code}import java.io.BufferedReader;
    import java.io.DataOutputStream;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.InputStreamReader;
    public class te {     
         private static final String ISO = "ISO8859_1";
         private static String charsetTobeChanged="TIS-620";
         public static void main(String args[]) throws Exception{
         BufferedReader brFile;
         String inFileName=null ;
         String inLine,inLine_BENE_NAME,decode_LL_BENE_NAME ;
         inLine_BENE_NAME="test";
         FileOutputStream fos2=new FileOutputStream("C:\\Documents and Settings\\Desktop\\asPerBaseFile.dat");
         DataOutputStream output = new DataOutputStream (fos2);
         final String NEXT_LINE = "\n";
         inFileName= "C:\\Documents and Settings\\D150911\\Desktop\\latestBaseFile.dat" ;
         String newStrLine,newDecodedBeneName;
         try{
              brFile = new BufferedReader(new InputStreamReader(new FileInputStream(inFileName), "UTF-8"));
              while ((inLine = brFile.readLine()) != null) {
                   try{
                        inLine_BENE_NAME = getField(inLine, inLine.length(), 78, 128).trim();
                        if (inLine_BENE_NAME!=null && inLine_BENE_NAME.length()>0)
                                       decode_LL_BENE_NAME = decode(inLine_BENE_NAME.getBytes(charsetTobeChanged),ISO);
                                       newDecodedBeneName= fillSpace(decode_LL_BENE_NAME,50);
                                       newStrLine=inLine.substring(0, 78).concat(newDecodedBeneName).concat(inLine.substring(128));
                                       output.writeBytes(newStrLine);
                                       output.writeBytes(NEXT_LINE);
                        else
                             output.writeBytes(inLine);
                   }//end try
                   catch (Exception encodeE)
                                  System.out.println(" exception in Encoding=="+encodeE);
              }//end while
         }//end of try
         catch(Exception e)
                   System.out.println("File not found= or any other exception ==="+e);
         //getField
         public static String getField(String lineString, int lineLength, int startPos, int endPos) throws Exception {
              String outString;
              try {
                   if (lineLength >= endPos) {
                        outString = lineString.substring(startPos, endPos);
                   } else
                        if (lineLength >= startPos) {
                             outString = lineString.substring(startPos, lineLength);
                        } else {
                             outString = "";
                   return(outString);
              catch (Exception ex) {
                   throw ex;
         public static String decode(byte[] pvBytes, String pvTargetCodePage) throws Exception
         if(pvBytes == null)
         return "";
         return new String(pvBytes, pvTargetCodePage);
         public static String fillSpace(String field_value, int number_of_digit)
         String add_space = "";
         if (field_value.length() < number_of_digit) {
         for (int j=0; j<(number_of_digit - field_value.length()); j++) {
         add_space = add_space + " ";
         field_value = field_value + add_space;
         return field_value;
    } // fillSpace
    }//end class
    And the file which I am trying to read is following..please copy and paste as a file...
    000001 7441 7454797 2721001477 000000050030932 080429 0190014754              &#3612;&#3641;&#3657;&#3592;&#3633;&#3604;&#3585;&#3634;&#3619;&#3650;&#3619;&#3591;&#3648;&#3619;&#3637;&#3618;&#3609;&#3617;&#3633;&#3608;&#3618;&#3617;&#3623;&#3636;&#3592;&#3633;&#3618;&#3619;&#3632;&#3648;&#3610;&#3637;&#3618;&#3610;&#3648;&#3585;&#3603;&#3601;&#3660;&#3604;&#3657;&#3634;&#3609;&#3604;&#3639;&#3657;&#3629;&#3604;&#3639;&#3593;                            
    000002 7441 7454797 1681016631 000000057153890 080429 0190014757              &#3624;&#3638;&#3585;&#3625;&#3634;&#3604;&#3639;&#3657;&#3629;&#3604;&#3639;&#3657;&#3629;&#3604;&#3639;&#3657;&#3629;&#3604;&#3639;&#3657;&#3629;&#3604;&#3639;&#3657;&#3629;&#3604;&#3639;&#3657;&#3629;&#3604;&#3639;&#3657;&#3629;&#3604;&#3639;&#3657;&#3629;&#3594;&#3656;&#3629;&#3591;&#3623;&#3636;&#3607;&#3618;&#3634;&#3594;&#3609;&#3593;&#3633;                                
    000003 7441 7454797 4162503389 000000090107942 080429 0190014762              &#3612;&#3641;&#3657;&#3592;&#3633;&#3604;&#3585;&#3634;&#3619;&#3650;&#3619;&#3591;&#3648;&#3619;&#3637;&#3618;&#3609;&#3617;&#3633;&#3608;&#3618;&#3617;&#3623;&#3636;&#3592;&#3633;&#3618;&#3619;&#3632;&#3648;&#3610;&#3637;&#3618;&#3610;&#3648;&#3585;&#3603;&#3601;&#3660;&#3604;&#3657;&#3634;&#3609;&#3604;&#3639;&#3657;&#3629;&#3604;&#3639;&#3593;                           
    000004 9100 7454797 0000000000 000000197292764 000000                                                                          
    ==============================================
    The above line is just a seperator...It can be noticed in the given file above the 3rd last line after LL has a Thai word which needs to be encoded....
    I mean ,I want to decode it with Char set TIS-620 so that when I open it in IE..Thai language can be viewed by Thai encoding.
    Please help.
    Edited by: InfoRequired on Jul 11, 2008 1:11 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    Thank you for the help!.
    True, I read the article you provided but it was a bit confusing if I read for the first time.
    anyways, you summarised well.I tried with following,read the file,did string manipulation then simplay wrote to a file with require character encoding.
    Preview:
    import java.io.BufferedReader;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.InputStreamReader;
    import java.io.OutputStreamWriter;
    public class forumHelp {     
         private static String  charsetTobeChanged="TIS-620";
         public static void main(String args[]) throws Exception{
         BufferedReader brFile;
         //OutputStreamWriter f1;
         String inFileName=null ;
         //String outFileName=null;
         String inLine,inLine_BENE_NAME;
         inLine_BENE_NAME="test";
         //ouput stream writer
         FileOutputStream fileOut = new FileOutputStream ("C:\\Documents and Settings\\Desktop\\forumHelp2.dat",true);
         OutputStreamWriter out1;
         out1 = new OutputStreamWriter (fileOut, charsetTobeChanged);
         out1.flush();
         final String NEXT_LINE = "\n";
         inFileName= "C:\\Documents and Settings\\Desktop\\latestBaseFile.dat" ;
         String newStrLine,newDecodedBeneName;
         try{
              brFile         = new BufferedReader(new InputStreamReader(new FileInputStream(inFileName), "UTF-8"));
              //f1         =new OutputStreamWriter(new FileOutputStream(outFileName), charsetTobeChanged);
              while ((inLine = brFile.readLine()) != null) {
                   try{
                        inLine_BENE_NAME      = getField(inLine, inLine.length(),  78, 128).trim();
                        if (inLine_BENE_NAME!=null && inLine_BENE_NAME.length()>0)
                                       newDecodedBeneName= fillSpace(inLine_BENE_NAME,50);
                                       newStrLine=inLine.substring(0, 78).concat(newDecodedBeneName).concat(inLine.substring(128));
                                       out1.write(newStrLine);
                                       out1.write(NEXT_LINE);
                        else
                             out1.write(inLine);
                   }//end try
                   catch (Exception encodeE)
                                  System.out.println(" exception in Encoding=="+encodeE);
              }//end while
         }//end of try
         catch(Exception e)
                   System.out.println("File not found= or any other exception ==="+e);
         out1.close();     
         //getField
         public static String getField(String lineString, int lineLength, int startPos, int endPos) throws Exception {
              String outString;
              try {
                   if (lineLength >= endPos) {
                        outString = lineString.substring(startPos, endPos);
                   } else
                        if (lineLength >= startPos) {
                             outString = lineString.substring(startPos, lineLength);
                        } else {
                             outString = "";
                   return(outString);
              catch (Exception ex) {
                   throw ex;
         public static String fillSpace(String field_value, int number_of_digit)
                        String add_space = "";
                      if (field_value.length() < number_of_digit) {
                              for (int j=0; j<(number_of_digit - field_value.length()); j++) {
                                      add_space = add_space + " ";
                      field_value = field_value + add_space;
                      return field_value;
         }  // fillSpace
    }//end classThank you all again!

  • Running an Interactive External Process

    I am trying to run an Interactive external process.
    This process is an exe program.
    When I run this program it prompts for a password.
    Here the reader.read() is never gets to a ready state.
    Following is a snippet of the program
    public class StreamGobler extends Thread{
    private InputStream is;
    private OutputStream os;
    private String pwd;
    private int waitState = 1;
    public StreamGobler(InputStream _is, OutputStream _os, String _pwd)   {
            this.is = _is;
            this.os = _os;
            this.pwd = _pwd;
         public void run() {
            BufferedReader reader = null;
            BufferedWriter writer = null;
            try {
                reader = new BufferedReader(new InputStreamReader(is));
                writer = new BufferedWriter(new OutputStreamWriter(os));
                String msg = "";
                int c=0;
                //This is where my program get blocked it never enters the while block and eventually timesout               
                while ((c = reader.read()) != -1) {            
         msg += (char) c;
         if (waitState == 1) {                 
            if(msg != null && msg.toLowerCase().indexOf("password") != -1){
         writer.write(pwd+ "\n");                    writer.flush();                         waitState++;                    msg = "";
                       }else{
           buffer.append((char) c);              
            catch (Exception ee) {}       
            finally {
                try {
         if (reader != null)
             reader.close();
         if (writer != null)
             writer.close();
               } catch (Exception ee) {}
    Message was edited by:
            ff1012                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    You need to check with the vendor of this unspecified application to see if they have an api for remote control. Perhaps they have an ActiveX interface? If not, I've had very good luck with an application called AutoIT - https://www.autoitscript.com/site/autoit/
    There are LabVIEW examples on the forum.

  • Winsock Error 10053

    Hi,
    I'm having trouble connecting to my local server to send/receive queries. More specifically I can connect fine, writing is OK, using the outputStreamWriter.write(String) method, but when the query has been processed by the server, it fails when attempting to send the results back.
    The code is roughly like this (can't post technical details for intellectual property reasons :( )
    Socket sock = new Socket(ipAddress, portNo)
    BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(sock.getOutputStream()))
    BufferedReader reader = new BufferedReader(new InputStreamReader(sock.getInputStream()))
    writer.write(xmlQuery)
    writer.close()
    String output = reader.read()
    //handle outputAs i said, I get the error after writing, ie upon closing the writer, the server will attempt to process the query and return an answer of some description. But i get the error message
    Error 10053:A connection abort was caused internal to your host machine. The software caused a connection abort because there is no space on the socket's queue and the socket cannot receive further connections.
    Any ideas what might be causing the issues? This happens every time i run, rather than the other examples i've found where it's been sporadic and people cannot connect at all.
    If any more information is required, i'll try to provide ASAP!
    Many thanks,
    Chris

    Have you experienced the same problem on any other computer on your network...If not it may be the firmware issue...Flash/Upgrade the router's firmware...You can download the firmware from here , Follow these steps to upgrade the firmware on the device: -
    Open an Internet Explorer browser page.In the address bar type - 192.168.1.1
    Leave the username blank & in password use admin in lower case...
    Click on the 'Administration' tab- Then click on the 'Firmware Upgrade' sub tab- Here click on 'Browse' and browse the .bin firmware file and click on "Upgrade"...
    Wait for few seconds until it shows that "Upgrade is successful"  After the firmware upgrade, click on "Reboot" and you will be returned back to the same page OR it will say "Page cannot be displayed".
    Press and hold the reset button for 30 seconds...
    Then, unplug the power cable while holding down the reset button for another 30 Seconds...
    Plug the power cable back in, and keep holding down the reset button for another 30 Seconds...
    Release the reset button...Now re-configure your router...

  • Runtime.exec output lost when executing ftp.

    I'm writing application, which can execute command line scripts.
    I'm executing Runtime.exec("cmd") and then writing commands into output stream. I'm continously reading from input and error stream, so that's not the case.
    Everything goes fine while I'm executing simple commands, like: dir, cd.
    The problem begins when I try to execute more sophisticated commands, like ftp.
    Here is the scenario:
    ftp server_nameFtp asks for user name
    userAfter providing user name, the output is lost. There are no more characters in InputStream ever. The application doesn't hangs, because ftp actually performs next commands (password, cd, get file). It is just output that isn't shown.
    Is it known problem or am I doing something wrong?
    Please, help.

    I post some code:
    import java.util.*;
    import java.io.*;
    class StreamGobbler extends Thread
        InputStream is;
        String type;
        char[] buf = new char[1000];
        StreamGobbler(InputStream is, String type)
            this.is = is;
            this.type = type;
        public void run()
            try
                InputStreamReader isr = new InputStreamReader(is);
                BufferedReader br = new BufferedReader(isr);
                String line=null;
                boolean write = false;
                while (true) {
                     StringBuffer buffer = new StringBuffer();
                     while (br.ready()) {
                          int chars = br.read(buf, 0, 1000);
                          buffer.append(buf, 0 ,chars);
                          write = true;
                     if (write) {
                          System.out.print(type + ">" + buffer.toString());
                          System.out.flush();
                          write = false;
                    try {
                             Thread.sleep(1000);
                        } catch (InterruptedException e) {
                             // TODO Auto-generated catch block
                             e.printStackTrace();
                } catch (IOException ioe)
                    ioe.printStackTrace(); 
    class StreamForward extends Thread
        InputStream is;
        OutputStream os;
        StreamForward(InputStream is, OutputStream os)
            this.is = is;
            this.os = os;
        public void run()
            try
                InputStreamReader isr = new InputStreamReader(is);
                BufferedReader br = new BufferedReader(isr);
                OutputStreamWriter wr = new OutputStreamWriter(os);
                String line=null;
                while ( (line = br.readLine()) != null) {
                    wr.write(line+"\n");
                    wr.flush();
                } catch (IOException ioe)
                    ioe.printStackTrace(); 
    public class GoodWindowsExec
        public static void main(String args[])
            try
                String osName = System.getProperty("os.name" );
                String cmd = new String();
                System.out.println("OS: "+osName);
                if( osName.equals( "Windows NT" ) || osName.equals("Windows XP"))
                    cmd = "cmd.exe" ;
                else if( osName.equals( "Windows 95" ) )
                    cmd = "command.com" ;
                Runtime rt = Runtime.getRuntime();
                System.out.println("Execing " + cmd);
                Process proc = rt.exec(cmd);
                // any error message?
                StreamGobbler errorGobbler = new
                    StreamGobbler(proc.getErrorStream(), "ERROR");           
                // any output?
                StreamGobbler outputGobbler = new
                    StreamGobbler(proc.getInputStream(), "OUTPUT");
                StreamForward forward = new
                     StreamForward(System.in, proc.getOutputStream());
                // kick them off
                errorGobbler.start();
                outputGobbler.start();
                forward.start();
                // any error???
                int exitVal = proc.waitFor();
                System.out.println("ExitValue: " + exitVal);       
            } catch (Throwable t)
                t.printStackTrace();
    }This is example code, which demonstrate this problem.
    It creates new cmd process and forwards to it standard input. Process output and error streams are displayed on standard output.
    Basically you can execute dos commands by entering them from keyboard.
    Try:
    dir
    cd something
    etc.
    Now, to show a problem try:
    ftp your_favorite_server
    The program should ask for username. Enter username. Nothing is displayed. Notice that ftp is still running and executing commands, but doesn't display any output.
    Any clue, why this is happening?

  • Simple Soap Request

    Hi All,
    if some one helps me out in this regard i am very thankful.
    there is a webservice Halloworld implemented in .Net.
    for that we have implemented a sample java program to invoke the webservice. while executing i am getting error
    java.net.ConnectException: Connection timed out: connect
    import javax.net.ssl.*;
    import java.io.*;
    import java.net.*;
    import java.security.*;
    import java.security.cert.Certificate;
    public class HelloWorld
    public final static String WEB_SERVER_URI = "https://secure.transunion.co.za/TUBureau/Service.asmx?wsdl";
    public final static String SOAP_ACTION ="https://secure.transunion.co.za/TUBureau/HelloWorld";
    //public final static String WEB_SERVER_URI = "http://dms03/ethikwinidms";
    //public final static String SOAP_ACTION ="http://tempuri.org/DocumentImport";
    //?wsdl
    public void responceProcessRequestTrans01()
    public void requestProcessRequestTrans01()
    String reqEnquirerContactName ="RaaZ";
                   String server = WEB_SERVER_URI;
         String reqDestination = "Test";
    System.setProperty("java.protocol.handler.pkgs","com.sun.net.ssl.internal.www.protocol");
    Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
    try
    URL url = new URL(server);
    URLConnection uc = url.openConnection();
    HttpURLConnection connection = (HttpURLConnection) uc;
    connection.setDoInput(true);
    connection.setDoOutput(true);
    connection.setRequestMethod("POST");
    connection.setRequestProperty("SOAPAction",SOAP_ACTION);
    connection.setRequestProperty("Content-Type","text/xml");
    OutputStream out = connection.getOutputStream();
    Writer wout = new OutputStreamWriter(out);
    String xmlEnvelop = null;
    xmlEnvelop = "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">" ;
    xmlEnvelop = xmlEnvelop + "<soap:Body>" ;
    xmlEnvelop = xmlEnvelop + "<HelloWorld xmlns=\"https://secure.transunion.co.za/TUBureau\">" ;
    wout.write(xmlEnvelop);
         wout.write("<Name>" + reqEnquirerContactName + "</Name>\n");
    wout.write("</HelloWorld>\n");
    wout.write("</soap:Body>\n");
    wout.write("</soap:Envelope>");
    wout.flush();
    wout.close();
    InputStream in = connection.getInputStream();
    int c;
    while ((c = in.read()) != -1)
    System.out.println("Raa");
    System.out.write(+ c);
    in.close();
    catch(IOException e)
    System.err.println(e);
    //System.err.println(e.getStackTrace());
    public static void main (String args[])
    HelloWorld nss = new HelloWorld();
    nss.requestProcessRequestTrans01();
    }

    Hello, I tried your code and it worked fine, however when i put this in servlet this error happens
    java.io.IOException: Server returned HTTP response code: 503 for URL: http://ssmgt539:7373/WebService/WS_Gateway.asmx
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1174)
    at ImageInfoSender.getSoapDataSet(ImageInfoSender.java:184)
    at ImageInfoSender.processRequest(ImageInfoSender.java:84)
    at ImageInfoSender.doPost(ImageInfoSender.java:348)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
    at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:368)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
    Hoping you can help me this one.
    Thank you

  • SSL simple chat

    Hallo,
    I did SSL simple chat, but something is wrong. This program is cennect to another same program(on localhost has diferent ports number). When send thread is weak up, NetBeans write this error: SEVERE: null
    java.net.UnknownHostException: java.
    I work with SSL fist time, I don´t know where I is error. I was inspire on this web side stilius.net/java/java_ssl.php and I use same keytool command. But I don´t know taht, I right use parametrs becouse I have server part and client part i one program.
    Could you check my code.
    import java.io.BufferedReader;
    import java.io.BufferedWriter;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.io.OutputStream;
    import java.io.OutputStreamWriter;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import javax.net.ssl.SSLServerSocket;
    import javax.net.ssl.SSLServerSocketFactory;
    import javax.net.ssl.SSLSocket;
    import javax.net.ssl.SSLSocketFactory;
    * SslReverseEchoer.java
    * Copyright (c) 2005 by Dr. Herong Yang
    public class Main {
       public static void main(String[] args) {
           String addressIP;
           if(args.length==0)
                addressIP="127.0.0.1";
           else
               addressIP=args[0];
          ReciveThread recive = new ReciveThread();
          SendThread send = new SendThread(addressIP);
          recive.recive.start();
          send.send.start();
    class ReciveThread implements Runnable
    {   Thread recive;
        public ReciveThread()
            recive = new Thread(this,"Recive thread");
        public void run()
            try {
                SSLServerSocketFactory sslFactory = (SSLServerSocketFactory) SSLServerSocketFactory.getDefault();
                SSLServerSocket sslServer = (SSLServerSocket) sslFactory.createServerSocket(5000);
                SSLSocket ssl = (SSLSocket) sslServer.accept();
                System.out.println("Adresa hostitele:"+ssl.getInetAddress().getHostName());
                while(true){
                    BufferedReader buffRead = new BufferedReader(new InputStreamReader(ssl.getInputStream()));
                    String line = null;
                    while((line = buffRead.readLine())!=null)
                        System.out.println("Recive data:"+line);
                        System.out.flush();
            } catch (IOException ex) {
    class SendThread implements Runnable
    {   Thread send;
        private String addressIP;
        public SendThread(String ip)
            this.addressIP=ip;
            send = new Thread(this,"Send thread");
        public void run()
            try {
                Thread.sleep(10000);
                SSLSocketFactory sslFactory = (SSLSocketFactory) SSLSocketFactory.getDefault();
                SSLSocket ssl = (SSLSocket) sslFactory.createSocket(this.addressIP,4000);
                BufferedReader buffKeyboard = new BufferedReader(new InputStreamReader(System.in));
                OutputStream outputStream = ssl.getOutputStream();
                BufferedWriter Buffwriter = new BufferedWriter(new OutputStreamWriter(outputStream));
                String radek = null;
                while((radek = buffKeyboard.readLine())!=null)
                    Buffwriter.write(radek+'\n');
                    Buffwriter.newLine();
                    Buffwriter.flush();
                    System.out.println("Posilana data:"+radek);
            } catch (InterruptedException ex) {
                Logger.getLogger(SendThread.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IOException ex) {
                Logger.getLogger(SendThread.class.getName()).log(Level.SEVERE, null, ex);
    }  

    OK i cut while(true){. This error write on this line: SSLSocket ssl = (SSLSocket) sslFactory.createSocket(this.addressIP,4000); . I think problem is somewhere in creating listen socket or wrong using parametrs for running programs. How can i put this:
    First copy certificate file that you created before into working directory and run server with these parameters (notice that you have to change keyStore name and/or trustStrorePassword if you specified different options creating certificate:
    java -Djavax.net.ssl.keyStore=mySrvKeystore -Djavax.net.ssl.keyStorePassword=123456 EchoServer
    And now again copy certificate file that you created before into working directory and run client with these parameters (notice that you have to change keyStore name and/or trustStrorePassword if you specified different options creating certificate:
    java -Djavax.net.ssl.trustStore=mySrvKeystore -Djavax.net.ssl.trustStorePassword=123456 EchoClient
    If i use server and client together in one program?

Maybe you are looking for

  • Monitoring in an Enterprise SOA envrionment

    Hi, we're implementing enterprise soa like applications in a increasingly higher rate at our company. Using many different SAP products and non-SAP products we're offering end users relatively simple applications based upon a rather complex environme

  • Our apologies for today's outage

    Hi Community Users, We experienced an outage for about 4-5 hours ago at 3:30pm (GMT-7 Pacific time) . Unfortunately, due to data corruption, we had to roll back to the forum as it was Sunday, 8/4/13.  Messages posted after that time were lost. Please

  • How to add the ToolTip to the liitle widgets in the JSplitpane

    Hi, I have a JSplitPane.I have set the setOneTouchExpandable() to true due to which I will get a little widget provided to quickly expand/collapse the split pane i.e i have two widgets to expand and collapse.Now i want to give tooltip to these widget

  • Calling Transactional IVIEW

    Hi , Created a Transactional Iview for Custom Tcode.In portal as well i was able to look into the preview of the transaction code. I used the follwing code to navigate this Transactional IView in the ABAP WEBDYNP which is been linked to an action but

  • Trouble updating iMovie

    I get the following error each time I try to update to iMovie 10.0.2. There was an error in the App Store.  Please try again later. (20) I am running 10.9.1 on a Core I7 mini.  Any ideas?? Thanks in advance