1

I'm trying to remotely deploy application to Tomcat. To do that, I need to do the following GET request:

http://localhost:8080/manager/text/deploy?path=/client-001&war=file:C:/.DS/tmp/client-001.war

I do it from my Java code:

String url = "http://localhost:8080/manager/text/deploy?path=/client-001&war=file:C:/.DS/tmp/client-001.war";
HttpClient client = HttpClientBuilder.create().build();
HttpGet request;
try {
      request = new HttpGet(url);
      request.addHeader(BasicScheme.authenticate(
      new UsernamePasswordCredentials("test", "test"),
                  "UTF-8", false));

      HttpResponse response = client.execute(request);
      BufferedReader rd = new BufferedReader(
                    new InputStreamReader(response.getEntity().getContent()));

      StringBuffer result = new StringBuffer();
      String line = "";
      while ((line = rd.readLine()) != null) {
            result.append(line);
      }

      System.err.println(result.toString());
} catch (Exception e){
      e.printStackTrace();
}

but I get 403, even though I've passed my credentials.

What am I doing wrong?

SMSk
  • 693
  • 8
  • 25
  • Does the web server provide any error message along with the 403 code? 403 would usually mean that the user was authenticated successfully, but that the user is not authorized to invoke the requested action. – Petter Mar 24 '15 at 16:15
  • http://tomcat.apache.org/tomcat-7.0-doc/manager-howto.html#Configuring_Manager_Application_Access – Konstantin V. Salikhov Mar 24 '15 at 18:20
  • I guess your mistake is parameter 'war' pointing local file instead of server file. I had similar problem and I found solution here: http://stackoverflow.com/a/13367460/2365727 – michaldo Mar 24 '15 at 20:40
  • No, it's not a mistake. The file is local and the server is local, it's a fat client. But I may be able to copy the file to Tomcat directory first, and then deploy it like a server file, so I'll have a look at your solution, thanks! – SMSk Mar 25 '15 at 09:17

1 Answers1

1

So I found out what the problem was.

1) I didn't need to pass credentials to the Header, I just needed to change url from localhost:8080 to test:test@localhost:8080

2) My user test had role manager-gui, and for GET to work it needed the role manager-script

SMSk
  • 693
  • 8
  • 25