Hi all,

I want to use the tomcat supported manager command
<https://tomcat.apache.org/tomcat-7.0-doc/manager-howto.html#Supported_Manager_Commands>
 to deploy a war file. The Tomcat server is Tomcat v8.0.23.

The application is sure to be deployed and started successfully, I,
however, got the failed message of the response as below

*FAIL - Deployed application at context path /test but context failed to
start*

The way I used is the HttpURLConnection in Java to PUT a file by an HTTP
request as below code


public void execute(ResponseHandler handler) throws IOException {

    String deployURL =
"http://localhost/manager/text/deploy?update=true&path=/test";
    final HttpURLConnection hconn = (HttpURLConnection) (new
URL(deployURL)).openConnection();

    try (FileInputStream fsInput = new FileInputStream(deployedPackage)) {
        final long contentLength = fsInput.getChannel().size();

        hconn.setAllowUserInteraction(false);
        hconn.setDoInput(true);
        hconn.setUseCaches(false);
        hconn.setDoOutput(true);
        hconn.setRequestMethod("PUT");
        hconn.setRequestProperty("Content-Type", "application/octet-stream");
        hconn.setRequestProperty("Content-Length", "" + contentLength);
        hconn.setFixedLengthStreamingMode(contentLength);
        hconn.setRequestProperty("User-Agent", "Catalina-Ant-Task/1.0");

        // Set up an authorization header with our credentials
        final String input = this.username + ":" + this.password;
        final String output =
Base64.getEncoder().encodeToString(input.getBytes(StandardCharsets.ISO_8859_1));
        hconn.setRequestProperty("Authorization", "Basic " + output);

        // Establish the connection with the server
        hconn.connect();

        try (BufferedInputStream istream = new
BufferedInputStream(fsInput, 1024);
                BufferedOutputStream ostream = new
BufferedOutputStream(hconn.getOutputStream(), 1024)) {
            final byte buffer[] = new byte[1024];
            while (true) {
                int n = istream.read(buffer);
                if (n < 0) {
                    break;
                }
                ostream.write(buffer, 0, n);
            }
        }
    }

    String response = new String();

    // Process the response message
    try (InputStreamReader reader = new
InputStreamReader(hconn.getInputStream(), "utf-8")) {
        final StringBuilder buff = new StringBuilder();
        while (true) {
            int ch = reader.read();
            if (ch < 0) {
                break;
            } else {
                buff.append((char) ch);
            }
        }
        handler.handle(buff.toString());
    }

    hconn.disconnect();}


The target URL is *http://localhost/manager/text/deploy?update=true&path=/test
<http://localhost/manager/text/deploy?update=true&path=/test>* for
deploying a war file to a context path "test". And the *deployedPackage* is
a File with the size amount 130 MB.

Is there anything I miss to set up or do it in the wrong way?

Thanks

Reply via email to