List of usage examples for org.apache.commons.httpclient.methods MultipartPostMethod getResponseHeader
@Override
public Header getResponseHeader(String headerName)
From source file:edu.umd.cs.buildServer.BuildServerDaemon.java
@Override protected ProjectSubmission<?> getProjectSubmission() throws MissingConfigurationPropertyException, IOException { try {// w w w. j a v a2 s.c o m String url = getRequestSubmissionURL(); MultipartPostMethod method = new MultipartPostMethod(url); String supportedCoursePKList = getBuildServerConfiguration().getSupportedCourses(); String specificProjectNum = getConfig().getOptionalProperty(DEBUG_SPECIFIC_PROJECT); String specificCourse = getConfig().getOptionalProperty(DEBUG_SPECIFIC_COURSE); if (specificCourse != null) supportedCoursePKList = specificCourse; String specificSubmission = getConfig().getOptionalProperty(DEBUG_SPECIFIC_SUBMISSION); String specificTestSetup = getConfig().getOptionalProperty(DEBUG_SPECIFIC_TESTSETUP); if (specificSubmission != null) { method.addParameter("submissionPK", specificSubmission); if (!isQuiet()) System.out.printf("Requesting submissionPK %s%n", specificSubmission); } if (specificTestSetup != null) { method.addParameter("testSetupPK", specificTestSetup); if (!isQuiet()) System.out.printf("Requesting testSetupPK %s%n", specificTestSetup); } if (specificProjectNum != null) { method.addParameter("projectNumber", specificProjectNum); } addCommonParameters(method); BuildServer.printURI(getLog(), method); int responseCode = client.executeMethod(method); if (responseCode != HttpStatus.SC_OK) { if (responseCode == HttpStatus.SC_SERVICE_UNAVAILABLE) { getLog().trace("Server returned 503 (no work)"); } else { String msg = "HTTP server returned non-OK response: " + responseCode + ": " + method.getStatusText(); getLog().error(msg); getLog().error(" for URI: " + method.getURI()); getLog().error("Full error message: " + method.getResponseBodyAsString()); if (responseCode == HttpStatus.SC_BAD_REQUEST) { if (!isQuiet()) { System.err.println(msg); System.out.println(msg); } System.exit(1); } } return null; } getLog().debug("content-type: " + method.getResponseHeader("Content-type")); getLog().debug("content-length: " + method.getResponseHeader("content-length")); // Ensure we have a submission PK. String submissionPK = getRequiredHeaderValue(method, HttpHeaders.HTTP_SUBMISSION_PK_HEADER); if (submissionPK == null) { if (specificSubmission != null) getLog().error("Server did not return submission " + specificSubmission); return null; } // Ensure we have a project PK. String testSetupPK = specificTestSetup != null ? specificTestSetup : getTestSetupPK(method); if (testSetupPK == null) return null; // This is a boolean value specifying whether the project jar file // is NEW, meaning that it needs to be tested against the // canonical project solution. The build server doesn't need // to do anything with this value except pass it back to // the submit server when reporting test outcomes. String isNewTestSetup = getIsNewTestSetup(method); if (isNewTestSetup == null) return null; // Opaque boolean value representing whether this was a // "background retest". // The BuildServer doesn't need to do anything with this except pass it // back to the SubmitServer. String isBackgroundRetest = getRequiredHeaderValue(method, HttpHeaders.HTTP_BACKGROUND_RETEST); if (isBackgroundRetest == null) isBackgroundRetest = "no"; ServletAppender servletAppender = (ServletAppender) getLog().getAppender("servletAppender"); if (isBackgroundRetest.equals("yes")) servletAppender.setThreshold(Level.FATAL); else servletAppender.setThreshold(Level.INFO); String kind = method.getResponseHeader(HttpHeaders.HTTP_KIND_HEADER).getValue(); String logMsg = "Got submission " + submissionPK + ", testSetup " + testSetupPK + ", kind: " + kind; getLog().info(logMsg); ProjectSubmission<?> projectSubmission = new ProjectSubmission<TestProperties>( getBuildServerConfiguration(), getLog(), submissionPK, testSetupPK, isNewTestSetup, isBackgroundRetest, kind); projectSubmission.setMethod(method); getCurrentFile().delete(); writeToCurrentFile(submissionPK + "\n" + testSetupPK + "\n" + kind + "\n" + SystemInfo.getSystemLoad() + "\n" + logMsg); return projectSubmission; } catch (ConnectException e) { getLog().warn("Unable to connect to " + getBuildServerConfiguration().getSubmitServerURL()); return null; } }