Reputation: 857
I am using the latest distribution of jersey
framework and I am encountering some issue with the post method. I have to pass the instance of ByteArrayInputStream
but it is not accepting it. I've gone through documentation but it doesn't explain it very well. And, how can I specify the MediaType?
Response tokenResponse = resourceGetToken.request()
.header( KeyConstants.REST_URI_APPENDERS, tokenSb )
.header( DocusignRESTContants.CONTENT_TYPE, DocusignRESTContants.APPLICATION_XML )
.header( DocusignRESTContants.X_DOCUSIGN_AUTHENTICATION, getDocusignAuthHeader( cu ) )
/*.accept( MediaType.APPLICATION_XML )*/
.post( Response.class, new ByteArrayInputStream( tokenStream.toString().getBytes() ) );
Thanks
Upvotes: 1
Views: 136
Reputation: 209102
You need to pass an Entity
, where you can also specify the media-type for the body
There are static convenience methods like xml
json
form
for application/xml
, application/json
and application/x-www-form-urlencoded
, respectively. But if you need a different type, then you can use the static entity
method, where the second argument is the media type
.post(Entity.json(yourBody));
.post(Entity.xml(yourBody));
.post(Entity.entity(yourBody, yourMediaType));
Also there is already the MediaType
class. Unless your constants are using non-standard media types, you're better of just using the MediaType
constants, like MediaType.APPLICAITON_XML
Upvotes: 1