[Dojo-interest] How to do WEB SERVICE program ???
Shake Sajan
shakesajan at gmail.com
Mon Jul 20 01:30:43 EDT 2009
Well Dustin, let me explain my question;
I am writing program to get data from a servlet using SMD (like invoking a
web service).
Here I have written;
an html file with js functions, Store class inheriting
ServiceStore class, SMD that contains my service description and servlet.
When I request for a service, say button click, I could able to connect to
servlet using SMD and got the response back. Now I have that response in
store._processResults method that is invoked immediately after getting
response.
Now the question is, how can I get that response value into my js function?
My example is to get the difference of 2 no.s given from the client UI.
Request data is;
var request = {
id: "diff_request",
method: "getDifference",
params: [dojo.byId("first").value, dojo.byId("second").value],
onBegin: function(arg)
{
outNode.innerHTML += "<br/>About to begin the service to get the
difference. arg: " + arg;
},
onComplete: function(arg)
{
outNode.innerHTML += "<br/>Service completed. arg: " + arg;
},
onItem: function(item)
{
outNode.innerHTML += "<br/>Item: " + item + ".";
}
};
Here onItem is not invoked. onBegin invoked, but arg is some int value (did
not sure what it is). onComplete invoked, but arg is null.
SMD is;
services: {
getDifference: {
transport: "POST",
target: "CalcSimulatorDiffServlet",
envelope: "JSON-RPC-2.0",
additionalParameters: false,
parameters: [
{type: "integer", default: 0},
{type: "integer", default: 0}
]
}
}
The other details like target, etc. are given properly.
Store _processResults function ;
_processResults: function(results, def)
{
console.log('[_processResults, ln: 43]\n\t results: ' + results +
'\t def: ' + def);
return this.inherited(arguments);
}
for test case, I pass 19 & 5 as inputs to the method. Got 14 as the output
from servlet. And it is printed from _processResults function. Now I want
this 14 value in my js function. probably in onComplete callback function of
request or in the Store object.
I hope now you are clear with my doubt. Expecting a response at the
earliest.
Meanwhile I will try to catch some info from given links.
Thank for the response.
regards.
Sajan.
+91 9980666232
--------------------------------------------------------
It is the thought that always matters...
--------------------------------------------------------
On Fri, Jul 17, 2009 at 6:35 PM, Dustin Machi <dmachi at dojotoolkit.org>wrote:
> I'm not sure I understand your question. Once the backend is setup,
> from the client's perspective it should be easy to use...
>
> // create teh service
> var svc = new dojox.rpc.Service(mySMD);
>
> // make a call to a service method, returns a Deferred object
> var def = svc._processResults(params)
>
> def.addCallback(function(results){
> /* do something with results */
> console.log("Results: ", results);
> });
>
> Dustin
>
> On Jul 17, 2009, at 8:47 AM, Shake Sajan wrote:
>
> > In my SMD based web service experiment, I used "JSON-RPC-2.0" as the
> > envelope. I got the output from the server. Now how to get the
> > values in my ultimate html/js file where I need to process on the
> > value.
> >
> > Means, I have the ouput value in my store._processResults function.
> > Now how to get this value into my js function which is outside the
> > store?
> >
> > Please help.
> >
> >
> > regards.
> > Sajan.
> > +91 9980666232
> > --------------------------------------------------------
> > It is the thought that always matters...
> > --------------------------------------------------------
> >
> >
> > On Fri, Jul 17, 2009 at 12:03 PM, Shake Sajan <shakesajan at gmail.com>
> > wrote:
> > Thank you very much for the valuable response..
> >
> > In fact, i thought to extract the values by reading the request body.
> >
> > Now, when I work with JSON-RPC, what kind of back-ends available?
> > Means, in the same example, How I can retrieve the data from the
> > request without reading and extracting the request body explicitly.
> > Is there any api already built? Or can I do so?
> >
> > Thanks in advance.
> >
> >
> >
> > regards.
> > Sajan.
> > +91 9980666232
> > --------------------------------------------------------
> > It is the thought that always matters...
> > --------------------------------------------------------
> >
> >
> > On Thu, Jul 16, 2009 at 7:04 PM, Dustin Machi
> > <dmachi at dojotoolkit.org> wrote:
> > For the JSON-RPC envelope, you need to
> > dojo.require("dojox.rpc.JsonRPC"); to make the json-rpc envelope
> > available. If you use json-rpc there are several backends available
> > in various languages. On the other hand, if you use envelope JSONn
> > and assuming transport POST from your example below, your servlet will
> > simply recieve a POST to the target url contain JSON encoded data in
> > the body of the request. Your servlet will need to take that POST
> > data deserialize the JSON data.
> >
> > Dustin
> >
> > On Jul 16, 2009, at 8:36 AM, Shake Sajan wrote:
> >
> > > Addition to the previous mail, I have one more doubt.
> > >
> > > ie, I could not work using the envelope as "JSON-RPC-2.0". So I
> > > changed the envelope to "JSON". Now its working. But how to retrieve
> > > the params values once I managed to reach the servlet thr SMD. SMD
> > > is given previous mail. if required I will send the detailed SMD.
> > >
> > > I hope my doubt is clear enough.
> > >
> > > Please reply. Thnx in advance...
> > >
> > >
> > > regards.
> > > Sajan.
> > > +91 9980666232
> > > --------------------------------------------------------
> > > It is the thought that always matters...
> > > --------------------------------------------------------
> > >
> > >
> > > On Wed, Jul 15, 2009 at 6:08 PM, Shake Sajan <shakesajan at gmail.com>
> > > wrote:
> > > yeah, I have worked on the first way you mentioned. ie, writing SMD
> > > for servlet.
> > > But it does not work when I try to connect to servlet residing in
> > > other machine. I provided the correct url for the servlet. I need to
> > > really dig the error.
> > >
> > > Next is, when I try to use "JSON-RPC-2.0" for connecting to servlet,
> > > how it would be?
> > >
> > > for eg: I have written like this;
> > > getDifference: {
> > > transport: "POST",
> > > target: "CalcSimulatorDiffServlet",
> > > envelope: "JSON-RPC-2.0",
> > > additionalParameters: false,
> > > parameters: [
> > > {type: "integer", default: 0},
> > > {type: "integer", default: 0}
> > > ]
> > > }
> > >
> > > target value is my servlet name. I have given the url in the outside
> > > target object. This getDifference object comes in the 'services' obj
> > > of the SMD. I have other method which is based on parameter name.
> > >
> > > What modification I need to make in the above object to connect to
> > > the servlet. Once I connect, How can I retrieve the positioned
> > > parameter values???
> > >
> > >
> > >
> > >
> > > regards.
> > > Sajan.
> > > +91 9980666232
> > > --------------------------------------------------------
> > > It is the thought that always matters...
> > > --------------------------------------------------------
> > >
> > >
> > > On Wed, Jul 15, 2009 at 5:14 PM, Kris Zyp <kris at sitepen.com> wrote:
> > > -----BEGIN PGP SIGNED MESSAGE-----
> > > Hash: SHA1
> > >
> > >
> > >
> > > Shake Sajan wrote:
> > > > Hi,
> > > >
> > > > I was trying to do a web service program. I went through the demos
> > > > provided by Dojo. I understand many things and the process flow.
> > > >
> > > > Now I was trying to do the pgm with my own web service.
> > > >
> > > > First, What all things we need to do to create a web service. Say
> > > > for eg: I have a servlet that will add two numbers. How I will
> > make
> > > > it understand the smd or how I can define a smd for the servlet.
> > [I
> > > > hope my requirement is technically correct].
> > > For RPC style communication, you probably want to use JSON-RPC
> > (there
> > > are plenty of resources on that). You can write an SMD to describe
> > > your servlets, so that Dojo can easily connect to your service.
> > > >
> > > > Once the smd is ready, how we can define the store?
> > > >
> > > > I went through some online references like :
> > > > http://www.sitepen.com/blog/2008/06/25/web-service-data-store/
> > > You can use the ServiceStore to connect to an RPC service. However,
> > > ServiceStore is read-only; stores are generally intended for storing
> > > data which can be a different concept than performing opaque
> > > computations (which is what RPC is targeted at). As an alternative
> > to
> > > RPC, the JsonRestStore works will if you want to preserve a
> > > web-service style architecture based on standard REST communication
> > > with read-write capabilities in your store. Or if you want to handle
> > > all the client-server comm, you could use an in-memory store like
> > the
> > > ItemFileWriteStore or jsonPathStore.
> > >
> > > - --
> > > Kris Zyp
> > > SitePen
> > > (503) 806-1841
> > > http://sitepen.com
> > > -----BEGIN PGP SIGNATURE-----
> > > Version: GnuPG v1.4.9 (MingW32)
> > > Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
> > >
> > > iEYEARECAAYFAkpdwR0ACgkQ9VpNnHc4zAxIHgCeO4l4HSbGoL5vODpE2TskMMqy
> > > lSgAoKfggO7L1Bc6cS16w8wKeDrwmJPV
> > > =KB8L
> > > -----END PGP SIGNATURE-----
> > >
> > > _______________________________________________
> > > FAQ: http://dojotoolkit.org/support/faq
> > > Book: http://dojotoolkit.org/docs/book
> > > Forums: http://dojotoolkit.org/forum
> > > Dojo-interest at mail.dojotoolkit.org
> > > http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
> > >
> > >
> > > _______________________________________________
> > > FAQ: http://dojotoolkit.org/support/faq
> > > Book: http://dojotoolkit.org/docs/book
> > > Forums: http://dojotoolkit.org/forum
> > > Dojo-interest at mail.dojotoolkit.org
> > > http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
> >
> > _______________________________________________
> > FAQ: http://dojotoolkit.org/support/faq
> > Book: http://dojotoolkit.org/docs/book
> > Forums: http://dojotoolkit.org/forum
> > Dojo-interest at mail.dojotoolkit.org
> > http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
> >
> >
> > _______________________________________________
> > FAQ: http://dojotoolkit.org/support/faq
> > Book: http://dojotoolkit.org/docs/book
> > Forums: http://dojotoolkit.org/forum
> > Dojo-interest at mail.dojotoolkit.org
> > http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
>
> _______________________________________________
> FAQ: http://dojotoolkit.org/support/faq
> Book: http://dojotoolkit.org/docs/book
> Forums: http://dojotoolkit.org/forum
> Dojo-interest at mail.dojotoolkit.org<http://dojotoolkit.org/forum%0ADojo-interest@mail.dojotoolkit.org>
> http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.dojotoolkit.org/pipermail/dojo-interest/attachments/20090720/543f831a/attachment.htm
More information about the Dojo-interest
mailing list