protected void execute(JUnitEETest test) throws BuildException { StringBuffer arguments = new StringBuffer(); boolean done; String sessionCookie; URL requestUrl; URLConnection con; arguments.append(url).append("?output=xml"); if (threaded) { log("Threaded mode", Project.MSG_DEBUG); arguments.append("&thread=true"); } if (test.getResource() != null) { arguments.append("&resource=").append(test.getResource()); } if (test.getRunall()) { arguments.append("&all=true"); } else if (test.getName() != null) { arguments.append("&suite=").append(URLEncoder.encode(test.getName())); } else { throw new BuildException("You must specify the test name or runall attribute", location); } if (!test.getFiltertrace()) { arguments.append("&filterTrace=false"); } InputStream in = null; try { // if user and password are set, then use the authenticator if (user != null && password != null) { java.net.Authenticator.setDefault(new AuthImpl(user, password)); } requestUrl = new URL(arguments.toString()); con = requestUrl.openConnection(); sessionCookie = con.getHeaderField("Set-Cookie"); log("Session cookie : " + sessionCookie, Project.MSG_DEBUG); if (sessionCookie != null) { int index = sessionCookie.indexOf(';'); if (index != -1) { sessionCookie = sessionCookie.substring(0, index); } } in = con.getInputStream(); done = parseResult(in, test); } catch (BuildException e) { throw e; } catch (Exception e) { log("Failed to execute test: " + e, Project.MSG_ERR); throw new BuildException(e); } finally { if (in != null) { try { in.close(); } catch (IOException e) { } ; } } try { while (!done) { try { log("Sleeping ... ", Project.MSG_DEBUG); Thread.sleep(1000); } catch (InterruptedException e) { // continue work } log("Get xml again using URL " + requestUrl, Project.MSG_DEBUG); con = requestUrl.openConnection(); if (sessionCookie != null) { con.setRequestProperty("Cookie", sessionCookie); } in = con.getInputStream(); try { done = parseResult(in, test); } finally { try { in.close(); } catch (IOException e) { } ; } } } catch (BuildException e) { throw e; } catch (Exception e) { log("Failed to execute test: " + e, Project.MSG_ERR); throw new BuildException(e); } }