Reputation: 1
I tried to call rest service using http adapter, but got unsupported media type exception.
My adapter and server side code is as follows
var invocationData = { adapter : 'MyHttpAdapter', procedure : 'myAdapterProcedure', parameters : [myJSONObject] };
WL.Client.invokeProcedure(invocationData, {
onSuccess : success,
onFailure : failure
});
function myAdapterProcedure(prarams) {
var input = {
method : 'put',
returnedContentType : 'json',
path : 'mobile/rest/notes/getMyWebData',
parameters : prarams
};
return WL.Server.invokeHttp(input);
}
server side:
@PUT
@Path("addNotes")
@Consumes("application/json")
@Produces("application/json")
public String addNotes(MyNotes pVo) throws Exception
{
System.out.println("1231231" + pVo);
return pVo;
}
Detailed exception: Failed to parse JSON string Apache Tomcat/6.0.35 - Error report
type Status report
message Unsupported Media Type
description The server refused this request because the request entity is in a format not supported by the requested resource for the requested method (Unsupported Media Type).
Tried with Put, Post method invocations and got the same exception. tried with '@Consumes({ MediaType.APPLICATION_JSON }) on server method still get the same error. Can anyone let me know what am I missing here...
Found the same issue here, without the solution. ref: How to send the JSON data in rest web services?
Upvotes: 0
Views: 969
Reputation: 143
Have you tried to check your REST service with a REST client (i'm using firefox add-on "RESTClient" to test my REST services outside of worklight) ?
If it's OK on the REST service side, then you need to check the headers in your http adapter "input" object.
you have to set the content-type params to "application/json" in the http request. To do so, add the "headers" attribute as below:
var input = {
method : 'put',
returnedContentType : 'json',
path : 'mobile/rest/notes/getMyWebData',
parameters : params,
headers : 'Content-Type: application/json'
};
Regards.
Upvotes: 0