Also if you need to post data to a custom handler you can do so like this:
@Operation(httpMethods = "POST", bodyParam = "data")
public Future<?> create(SocialRequestItem request) throws
ProtocolException {
....
Map<String, String> values = request.getTypedParameter("data",
Map.class);
....
}
On Fri, Oct 23, 2009 at 9:36 AM, Louis Ryan <[email protected]> wrote:
> You dont actually need to write your own Javascript to do this. Because you
> are using the standard annotation based dispatching stuff you can just use
> osapi. The default implementation of Shindig will introspect the API
> endpoints to discover the set of available services and makes them
> available
> to osapi.
>
> Assuming that your class looks like
>
> @Service("names", ...)
> public classs MyNames {
> ...
> @Operation(httpMethods = "GET")
> public Future<?> processGetRequest(RequestItem request) throws
> ProtocolException {
> return processMessage(request);
> }
> ...
> }
>
> Then if you require the "osapi" feature you will be able to call
>
> osapi.names.processGetRequest({< params in JSON object
> >}).execute(function(result){ /* callback */ });
>
> to get a nicer method name in the JS just change the method name in Java or
> use the aliasing feature of the Operation annotation.
>
>
>
> On Fri, Oct 23, 2009 at 12:42 AM, <[email protected]> wrote:
>
> > Hi all,
> >
> > I was trying to create a sample Handler in Shindig. It has a list of
> > methods. Below is the signature of each of the method.
> >
> > @Operation(httpMethods = "PUT")
> > public Future<?> update(RequestItem request) throws
> > ProtocolException {
> > return processMessage(request);
> > }
> >
> > @Operation(httpMethods = "GET")
> > public Future<?> processGetRequest(RequestItem request) throws
> > ProtocolException {
> > return processMessage(request);
> > }
> >
> > @Operation(httpMethods = "POST")
> > public Future<?> processMessage(RequestItem request) throws
> > ProtocolException {
> > String title = request.getParameter("title");
> > String hostname = request.getParameter("hostName");
> > String eventType = request.getParameter("eventType");
> > // rest of the code
> > }
> >
> > Now I added a new feature which has a js file called event.js which has
> > a method Namespace.updateEvent for updating the event as follows
> >
> > Namespace.updateEvent = function(opts,opts_callback) {
> > Namespace.sendRequestToServer('update', 'POST',
> > opts,opts_callback,true);
> > }
> >
> > Namespace.sendPostRequestToServer = function(url, method,
> > opt_postParams, opt_callback, opt_excludeSecurityToken) {
> > var opt_postParams = opt_postParams || {};
> > var makeRequestParams = {
> > "CONTENT_TYPE" : "JSON",
> > "METHOD" : method,
> > "POST_DATA" : opt_postParams};
> >
> > if (opt_excludeSecurityToken) {
> > var secureToken =
> > escape(Namespace.generateSecureToken());
> > url = socialpath+ url + "?st=" + secureToken;
> > }
> >
> > gadgets.io.makeNonProxiedRequest(url,
> >
> > function(data) {
> > data =
> > data.data;
> > if
> > (opt_callback) {
> >
> > opt_callback(data);
> > }
> > },
> > makeRequestParams,
> > "application/json"
> > );
> > }
> >
> >
> > Now I call Names.updateEvent() from a gadget by passing the parameters
> > as follows
> >
> > Namespace.event.updateEvent(gadgets.io.encodeValues({"title":eventId,"ho
> > stname":name,...}),callbackmethod);
> >
> > I found that this call is reaching my handler class and the method
> > processMessage()is getting called.
> > But all the parameter values are coming as null. If I change the method
> > as GET instead of POST, it is working fine. I could not resolve this
> > issue.
> > It would be great if somebody can help me in resolving this issue.
> >
> > Thanks in Advance
> > Vinu
> >
> >
> > Please do not print this email unless it is absolutely necessary.
> >
> > The information contained in this electronic message and any attachments
> to
> > this message are intended for the exclusive use of the addressee(s) and
> may
> > contain proprietary, confidential or privileged information. If you are
> not
> > the intended recipient, you should not disseminate, distribute or copy
> this
> > e-mail. Please notify the sender immediately and destroy all copies of
> this
> > message and any attachments.
> >
> > WARNING: Computer viruses can be transmitted via email. The recipient
> > should check this email and any attachments for the presence of viruses.
> The
> > company accepts no liability for any damage caused by any virus
> transmitted
> > by this email.
> >
> > www.wipro.com
> >
>