}
public TestResult runTest()
{
TestResult testResult=new TestResult();
int code=0;
String message=null;
HttpURLConnection connection;
FileReader fis=null;
BufferedReader in=null;
File file=null;
int i=0;
try
{
// getting connection to jsp //
connection=getConnection(null,null,null,"GET");
}
catch(Exception k)
{
testResult.setMessage("FAIL");
testResult.setStatus(false);
return testResult;
}
try
{
code = connection.getResponseCode();
}
catch(IOException io)
{
testResult.setMessage("FAIL");
testResult.setStatus(false);
return testResult;
}
try
{
message = connection.getResponseMessage();
}
catch(IOException j)
{
testResult.setMessage(message);
testResult.setStatus(false);
return testResult;
}
try
{
out.println("HTTP code" + code);
out.println("Message: " + message);
}
catch(IOException h)
{
testResult.setStatus(false);
testResult.setMessage(message);
}
if(code >= 400)
{
testResult.setStatus(false);
testResult.setMessage(message);
}
else
{
try
{
//Reading from the input stream //
in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
}
catch(IOException u)
{
testResult.setStatus(false);
testResult.setMessage("error at buffered reader");
}
StringBuffer result = new StringBuffer();
String line = null;
try
{
while ((line = in.readLine()) != null )
{
result.append(line);
out.println (line);
}
}
catch(IOException me)
{
testResult.setStatus(false);
testResult.setMessage("error in readline");
}
}
// In the jsp, data is written into the
// output stream after closing the stream
//Exception is thrown.In the catch block
//a file " positiveClose.err is
// created and message is written
String dir=System.getProperty("user.home");
String sss=dir+System.getProperty("file.separator")+"positiveClose.err";
//the file is opened and read
file=new File(sss);
try
{
fis =new FileReader(file);
}
catch(Exception ee)
{
testResult.setStatus(false);
testResult.setMessage("error in filereader");
return testResult;
}
char b[]=new char[15];
try
{
fis.read(b);
}
catch(IOException u)
{
testResult.setStatus(false);
testResult.setMessage("unable to read from file");
return testResult;
}
String str= new String(b);
str = str.trim();
// checking for the written message
if(str.equals("out is not null"))
{
testResult.setStatus(true);
testResult.setMessage("OK");
return testResult;
}
else
{
testResult.setStatus(false);
testResult.setMessage("error");
return testResult;
}
}