Example usage for org.apache.commons.httpclient.methods MultipartPostMethod getURI

List of usage examples for org.apache.commons.httpclient.methods MultipartPostMethod getURI

Introduction

In this page you can find the example usage for org.apache.commons.httpclient.methods MultipartPostMethod getURI.

Prototype

@Override
public URI getURI() throws URIException 

Source Link

Document

Returns the URI of the HTTP method

Usage

From source file:edu.umd.cs.buildServer.BuildServerDaemon.java

@Override
protected void doWelcome() throws MissingConfigurationPropertyException, IOException {
    if (!isQuiet()) {
        System.out.println(//w ww .  j a v  a 2 s  .  co m
                "Connecting to submit server at " + getBuildServerConfiguration().getSubmitServerURL());
        String hostname = getBuildServerConfiguration().getHostname();
        System.out.println("Hostname: " + hostname);
        System.out.println("System load: " + SystemInfo.getSystemLoad());
        System.out.println("Java version: " + System.getProperty("java.version"));
        System.out.println("connection timeout: " + getConnectionTimeout());
        System.out.println();

    }
    String url = getWelcomeURL();
    MultipartPostMethod method = new MultipartPostMethod(url);

    addCommonParameters(method);

    BuildServer.printURI(getLog(), method);
    int responseCode;
    try {
        responseCode = client.executeMethod(method);
    } catch (IOException e) {
        throw new IOException("Buildserver unable to connect to submitserver at " + url, e);
    }
    if (!isQuiet())
        System.out.println(method.getResponseBodyAsString());

    if (responseCode != HttpStatus.SC_OK) {

        getLog().error("HTTP server returned non-OK response: " + responseCode + ": " + method.getStatusText());
        getLog().error(" for URI: " + method.getURI());
        getLog().error("Full error message: " + method.getStatusText());
        throw new IOException("Buildserver unable to connect to submitserver at " + url + ", Status "
                + responseCode + ": " + method.getStatusText());
    }

}

From source file:edu.umd.cs.buildServer.BuildServerDaemon.java

@Override
protected ProjectSubmission<?> getProjectSubmission()
        throws MissingConfigurationPropertyException, IOException {

    try {//ww w  .ja  v a2 s  .  co 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;
    }
}