简体   繁体   中英

How to Pass the DTO to the Restful web services

This might be simple question. I tried googling but no luck. I have one DTO which is pass from client and consumed by the restful webservices. But getting this exception

 Mapping exception to XML
avax.ws.rs.NotSupportedException: HTTP 415 Unsupported Media Type

and this is my restful method.

    @PUT
    @Path("microservice/persist")
    @Consumes("application/json")
    public long update(AsyncJobDTO asyncJobDTO){
      //calling EJB and returing the value
      }

this is my restful call

http://localhost:9090/nexterp-war/rest/api/Jobupdate/microservice/persist?format=format.json

It was because there was no accept header sent with the request. You need to send a Accepts and Content-Type headers with the client code.

Since your application accepted json, It should be

<code>'Accept': 'application/json'</code>
<code>'Content-Type': 'application/json'</code>

Similar posting in SO Http 415 Unsupported Media type error with JSON , Error 415 Unsupported Media Type: POST not reaching REST if JSON, but it does if XML

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