简体   繁体   中英

Consuming & exposing a REST service and passing JSON body

I am using Apache Camel with XML DSL to consume & expose a REST service. I have a request body {"name":"your name","phonenumber":"111-111"}

I am successfully able to directly send this json request body and get a successfull response from the consumed endpoint url. Whereas when I go through my exposed URL I am getting the following exception.

org.apache.camel.component.restlet.RestletOperationException: Restlet operation failed invoking 
<!--Consumed URL--> with statusCode: 400 /n responseBody:
{"timestamp":"2020-04-07T06:15:41.302+0000","status":400,"error":"Bad Request",
"message":"Required request body is missing: public boolean
com.agcs.cids.BookingRestController.createBooking(org.bson.Document...)","path":"-----"}

I am successfully even able to print the body just before I make a call to the URL. Please fine my code below:

<log loggingLevel="TRACE" message="Request from source: Body: ${body}" />      
<log loggingLevel="TRACE" message="Request from source: Header: ${headers}" />
<to uri="restlet:<--Consumed URL-->?restletMethod=POST" />

I guess your code is trying to either -

  1. Send in a POST request without the {"name":"your name","phonenumber":"111-111"} JSON body. In this case, you might wanna revisit your code and verify if you're setting the body correctly, like the <setBody> is properly used inside the <to> and <from> tags.
  2. Send in a POST request to a URL which doesn't accept a JSON body. Have you tried adding "Accept", "application/json" as a header?
  3. Verify if you don't have your <from> and <to> addresses mixed up (you mentioned "Consumed URL" which semantically should be "Consuming URL" in case of a <to> endpoint)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM