Reputation: 2517
I keep receiving null values while sending these two parameters thru a POST with ajax (tried with Poster as well):
@POST
@Path("/update")
@Produces(MediaType.APPLICATION_JSON)
public void update(String Path, String Content) {
updateURI(Path,Content);
}
Path: http://essam.ldm.io/stor...amblog/ChannelList/ch1/post2
Content: <http://essam.ldm.io/storage/essamblog/ChannelList/ch1/post2> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://crosscloud/mblog/Post>. <http://essam.ldm.io/storage/essamblog/ChannelList/ch1/post2> <http://crosscloud/mblog/owner> <https://essam.ldm.io></https:>. <http://essam.ldm.io/storage/essamblog/ChannelList/ch1/post2> <http://purl.org/dc/terms/created> <2013-03-06T16:41:18+0300^^http://www.w3.org/2001/XMLSchema#dateTime>. <http://essam.ldm.io/storage/essamblog/ChannelList/ch1/post2> <http://rdfs.org/sioc/ns#content>.
Obviously I cannot send them as @QueryParam
or @PathParam
due to the format.
It is irrilevant putting the jQuery code since it deosnt wotk with Poster neither, but here it is:
function doUpdate(path, rdf)
{
var obj1 = {"path": path, "rdf": rdf};
var sUrl = "http://localhost:8080/browsing/services/RDF/update";
$.ajax({
type: "POST",
url: sUrl,
contentType: "application/json; charset=utf-8",
data: obj1,
//dataType: "json",
async: false,
success: function (resp, status, xhr) {
$("#message").html("STATUS: " + xhr.status + " " + xhr.statusText + "\n" + resp);
$("#message").hide();
$("#login_message").html("<font color='green'><b>Record succesfully updated</b></font>d");
},
error: function(resp, status, xhr){
$("#message").html("ERROR: " + resp.status + " " + resp.statusText + "\n" + xhr);
$("#message").show();
}
});
}
Anything I am doing wrong?
Thanks,
Upvotes: 0
Views: 1177
Reputation: 1900
You can encode it (i.e. base64) before you send it and decode it on server or you can use JSON as request param.
Using JSON, for example;
@POST
@Path("/update")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public void update(PathContext ctx) {
updateURI(ctx.getPath(),ctx.getContent());
}
@XmlRootElement
public class PathContext {
private String path;
private String content;
public String getPath() {
return path;
}
public void setPath(String path) {
this.path = path;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
}
Your JSON will look like;
{"path": somePath, "content": someContent}
Hope it helps.
Upvotes: 1