1

I'm using AngularJS 1.4 and a Spring 4 RestController. When I make a GET request on my development machine, everything works fine. But when I deploy the exact same war file to our test server, exact same request from exact same browser returns HTTP 406 Not Acceptable.

Only difference between two environment is on my development machine I'm using embedded Tomcat 8, whereas on test server app is deployed on Tomcat 7.

My request consists of a single path variable which contains an email address.

Local request: enter image description here

Test server request: enter image description here

angularjs code which makes the request:

utilService.emailD = function(email) {
        return $http({
            method : 'GET',
            url : 'util/emailD/' + encodeURIComponent(email)
        }).then(
            function successCallback(response) {
                return response.data;
            },
            function errorCallback(response) {
                return {
                    error : true
                };
            });
    }

Spring controller which accepts request

@RequestMapping(value = "/emailD/{email:.+}",
        method = RequestMethod.GET,
        produces = MediaType.TEXT_PLAIN_VALUE)
public ResponseEntity<String> emailD(@Email @Valid @PathVariable(value = "email") String email) {       
    try {
        log.debug("request emailD, email: {}", email);

        //omitted irrelevant code

        return new ResponseEntity<String>(someString, HttpStatus.OK);
    } catch (IllegalArgumentException iae) {
        return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
    }
}

Is there any reason you can think of that may cause such behavior?

uylmz
  • 1,480
  • 2
  • 23
  • 44

1 Answers1

1

The problem itself (and multiple working solutions) are described here:

spring-json-request-getting-406-not-acceptable

In your case the situation is probably that your local Tomcat does have the required libs on classpath, while the remote Tomcat does not. Since your application needs these, the best solution would be to declare as a dependency via Maven. Alternative option would be to add the jackson libs to your Tomcat's lib folder.

Community
  • 1
  • 1
Gergely Bacso
  • 14,243
  • 2
  • 44
  • 64
  • In that question OP says hibernate query executes, but in my case path variable never makes into the function, nothing inside function is executed. Gonna check it out though, thanks. – uylmz Dec 17 '15 at 21:51