Reputation: 1097
My worklight app has a page to post some values to a remote server. This is done using an adapter which calls the url to post. The client javascript is:
var invocationData = {
adapter : 'StoryAdaptor',
procedure : 'postStoryDetails',
parameters : [ storyParameters ]
};
WL.Client.invokeProcedure(invocationData, {
onSuccess : function(data) {
alert("return message: "+JSON.stringify(data))
},
onFailure : function(data) {
alert("Couldn't save Story");
}
});
The adapter method is
function postStoryDetails(storyParameters){
var input = {
method : 'post',
returnedContentType : 'json',
path : "/postStory.json",
parameters : storyParameters
};
var authResult = WL.Server.invokeHttp(input);
}
The remote application is a java Spring application which takes the parameters and on successful save, returns just a string "success".
@RequestMapping(value = { "/postStory" }, method = RequestMethod.POST)
public String postStory(HttpServletRequest request,HttpServletResponse response){
Story story = new Story();
story.setTitle(request.getParameter("title"));
.
.
.
boolean status = storyService.saveStory(story);
if(status ){
return "success";
}
return "failed";
}
I am not getting the "success" message in worklght. Instead, each time, the alert is printing
return message: {"status":200,"invocationContext":null,"invocationResult":{"isSuccessful":true}}
Why I am not getting my returned message?
Upvotes: 0
Views: 112
Reputation: 44516
Try returning like the following:
return {
result: "success";
}
For Worklight 6.2, see Using Java in Adapters, slide #11
For MobileFirst Platform 3.2, see Using Java in Adapters, section "Invoking custom Java classes from the adapter"
Upvotes: 1