0

I have created a web application, and hosted in on the server. Now I want to create a java program which will access (or "hit") the URL of my application in a loop, so that I can check how much load can my web application can handle. Also, the program should be able to tell me when the URL was successfully accessed, and when it wasn't.

I tried executing it without using a loop:

try {
        URL url = new URL("https://example.com/");
        BufferedReader in = new BufferedReader(
                new InputStreamReader(url.openStream()));

        String inputLine;
        while ((inputLine = in.readLine()) != null) {
            System.out.println(inputLine);
        }
        in.close();
    } catch (Exception e) {
        System.out.println("e: " + e.toString());
    }

But, I got this error:

e: javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateException: No  subject alternative DNS name matching example.com found.
3
  • There is no secure http for this url. Commented Aug 12, 2013 at 6:15
  • 1
    You need to import the certificates in your client keystore before you can hit the https url. Commented Aug 12, 2013 at 6:18
  • If it doesn't have to be https, you can use a command in a CMD window like so: ping -n 50 -l 1024 example.com Commented Aug 12, 2013 at 6:29

2 Answers 2

2

Use,

javax.net.ssl.HttpsURLConnection

to connect to https://

something like (note, handle resource closing, exceptions etc left on you)

final URL url = new URL("https://example.com");
final HttpsURLConnection con = (HttpsURLConnection)url.openConnection();
final BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream()));
String input;

while ((input = br.readLine()) != null){
    System.out.println(input);
}

However there are lots of tool available to load test it

Sign up to request clarification or add additional context in comments.

Comments

0

you are just getting a stream from url, but obviously this url is using HTTPS, so you need a "Public Key" imported to your client application. otherwise the client and server won't be able to communicate with each other.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.