-1

I have a code with a RestBuilder that needs to connect to another application, the target endPoint have an object in the signature with the attributes. The problem is the request return 404. How I solve this? I tried use x-www-form-urlencoded (doesn't work)

Request Method:

RestResponse restResponse;

String parameters = '{"qtdThreads":3,"channel":"http://localhost:8081/application2"}'

try {
    restResponse = new RestBuilder().post("http://localhost:8080/application/endPoint", {
        accept("application/json")
        contentType "application/json; utf-8"
        body(parameters.getBytes("UTF-8"))
        connectTimeout: 1000
    })
} catch (Exception e) {
    e.printStackTrace();
} finally {
    return restResponse;
}

Target endPoint:

Object endPoint(ObjectCommand command) {
    render(status: HttpStatus.OK)
}

Object used on signature

import grails.validation.Validateable

@Validateable
class ObjectCommand {

    URL channel
    Integer qtdThreads

    static constraints = {
        qtdThreads(validator: { Integer val ->
            if (!val || val <= 0) {
                return "message1"
            }
        })
        channel(validator: { URL val ->
            if (!val) {
                return "message2"
            }
        })
    }

}

1 Answers1

0

did you check if the target application is running and exposing that endpoint?

red
  • 606
  • 10
  • 17