सबसे पहले, मैं जानना चाहता था कि मैं क्या कर रहा हूं यह करने का सही तरीका है।जेसन के साथ पोस्ट को पुन: कार्यान्वित करना और प्रतिक्रिया
मेरे पास एक परिदृश्य है जहां मुझे एक जेसन अनुरोध प्राप्त होगा और मुझे डेटाबेस अपडेट करना होगा, एक बार डीबी अपडेट होने के बाद मुझे जेसन स्वीकृति के साथ जवाब देना होगा।
मैं अब तक क्या किया इस प्रकार वर्ग का विस्तार आवेदन पैदा करते हैं:
@Override
public Restlet createRoot() {
// Create a router Restlet that routes each call to a
// new instance of ScanRequestResource.
Router router = new Router(getContext());
// Defines only one route
router.attach("/request", RequestResource.class);
return router;
}
मेरे संसाधन वर्ग ServerResource प्रदान कर रहा है और मैं अपने संसाधन कक्षा में निम्न विधि है
@Post("json")
public Representation post() throws ResourceException {
try {
Representation entity = getRequestEntity();
JsonRepresentation represent = new JsonRepresentation(entity);
JSONObject jsonobject = represent.toJsonObject();
JSONObject json = jsonobject.getJSONObject("request");
getResponse().setStatus(Status.SUCCESS_ACCEPTED);
StringBuffer sb = new StringBuffer();
ScanRequestAck ack = new ScanRequestAck();
ack.statusURL = "http://localhost:8080/status/2713";
Representation rep = new JsonRepresentation(ack.asJSON());
return rep;
} catch (Exception e) {
getResponse().setStatus(Status.SERVER_ERROR_INTERNAL);
}
मेरी पहली चिंता यह है कि मैं इकाई में प्राप्त ऑब्जेक्ट इनपुट प्रस्तुति है इसलिए जब मैं jsonobjectation से jsonobject लाता हूं तो मुझे हमेशा खाली/शून्य वस्तु मिलती है।
मैं ग्राहक संलग्न
function submitjson(){
alert("Alert 1");
$.ajax({
type: "POST",
url: "http://localhost:8080/thoughtclicksWeb/request",
contentType: "application/json; charset=utf-8",
data: "{request{id:1, request-url:http://thoughtclicks.com/status}}",
dataType: "json",
success: function(msg){
//alert("testing alert");
alert(msg);
}
});
};
ग्राहक निम्नलिखित कोड के साथ json अनुरोध के साथ-साथ
ClientResource requestResource = new ClientResource("http://localhost:8080/thoughtclicksWeb/request");
Representation rep = new JsonRepresentation(new JSONObject(jsonstring));
rep.setMediaType(MediaType.APPLICATION_JSON);
Representation reply = requestResource.post(rep);
कोई मदद या इस पर सुराग कहा करते थे गुजर करने की कोशिश की hight की सराहना की है?
धन्यवाद, राहुल
आधिकारिक Restlet-पर चर्चा मंच पर इस सवाल पूछने पर विचार करें // restl et.tigris.org/ds/viewForumSummary.do?dsForumId=4447 –