package com.weblyzard.api.client.integration;

import com.weblyzard.api.client.BasicClient;
import java.io.IOException;
import java.net.Socket;
import java.util.logging.Logger;

public class TestClientBase {

    protected Logger logger = Logger.getLogger(getClass().getName());

    /**
     * checks if a network service is running
     *
     * @param host host the server is running on
     * @param port port the server is listening on
     * @return
     */
    public boolean weblyzardServiceAvailable(BasicClient basicClient) {

        Socket s = null;

        String host = basicClient.getBaseTarget().getUri().getHost();
        int port = basicClient.getBaseTarget().getUri().getPort();

        try {
            s = new Socket(host, port);
            return true;
        } catch (IOException e) {
            logger.info("service is not available :" + host + ":" + port);
            return false;
        } finally {
            if (s != null)
                try {
                    s.close();
                } catch (Exception e) {
                }
        }
    }
}

@@ -534,34 +534,8 @@
  %7B%0A%0A
-        Socket s = null;%0A%0A
     
@@ -596,24 +596,24 @@
 .getHost();%0A
+
         int 
@@ -680,29 +680,23 @@
     try 
-%7B%0A           
+(Socket
  s = new
@@ -710,25 +710,26 @@
 (host, port)
-;
+)%7B
 %0A           
@@ -851,16 +851,16 @@
  port);%0A
+
         
@@ -881,166 +881,8 @@
 se;%0A
-        %7D finally %7B%0A            if (s != null)%0A                try %7B%0A                    s.close();%0A                %7D catch (Exception e) %7B%0A                %7D%0A
     

use closable resource management