1 Reply Latest reply on Dec 4, 2012 11:33 AM by Tao Lu

    trying to create a package with the REST api.

    Rocky Pulley Newbie

      so I'm trying to just call a PUT on http://localhost:8080/drools/rest/packages/mypackagename

       

      but I get a 500 internal server error.

       

      Do I need to send some sort of information with it when creating the package, I figured just a PUT would create an empty package.

       

      here's my code to do it:

       

      <script type="text/javascript">

         

          function make_base_auth(user, password) {

            var tok = user + ':' + password;

            var hash = btoa(tok);

            return "Basic " + hash;

          }

       

         

                $(document).ready(function() {

                              $.ajax({

                    url: 'http://localhost:8080/drools/rest/packages/test.pck.five',

                    type: 'PUT',

                    beforeSend: function (xhr){

                        try {

                          xhr.setRequestHeader('Authorization', make_base_auth('admin', 'admin'));

                      } catch(e) {

                          alert(e.message);

                      }

                    },

                    success: function(data) {

                      alert('Load was performed.');

                    },

                    error: function(request, type, errorThrown) {

                        var message = "There was an error with the AJAX request.\n";

                      switch (type) {

                          case 'timeout':

                              message += "The request timed out.";

                              break;

                          case 'notmodified':

                              message += "The request was not modified but was not retrieved from the cache.";

                              break;

                          case 'parsererror':

                              message += "XML/Json format is bad.";

                              break;

                          default:

                              message += "HTTP Error (" + request.status + " " + request.statusText + ").";

                      }

                      message += "\n";

                      alert(message);

                      console.log(errorThrown);

                    }

                  });

       

                });

          </script>