[Json-rpc-java] jsonrpc does not find objects on the bridge

Rijken, Pieter pieter.rijken at logicacmg.com
Tue Aug 1 14:05:50 SGT 2006


Hi Michael,

Thanks you for your reply.

It took me some time, but I now seem to have solved the problem.

I discovered that I had two instances of the bridge running: the
server side code registered the object with the bridge and this
was working well.
But the client was polling another instance of the bridge.

I am also new to j2ee......and had deployed the json bridge code
in a war (client side) while I had the jsp code and the jar file
with (another) json bridge (to get the jsp compiling) in another
war file.
Appanrently, these run in different scope or container.

regards, pieter 

> -----Original Message-----
> From: Michael Clark [mailto:michael at metaparadigm.com] 
> Sent: 26 July 2006 05:38
> To: Rijken, Pieter
> Cc: json-rpc-java at oss.metaparadigm.com
> Subject: Re: [Json-rpc-java] jsonrpc does not find objects on 
> the bridge
> 
> Rijken, Pieter wrote:
> > Hi,
> >
> > I am new to JSON-RPC-JAVA and am struggling for quite a while now.
> > I have searched the mailing list archives and found 
> something similar
> > but not quite
> > the same problem I am having.
> >
> > In a JSP file I have the following code:
> >
> > <jsp:useBean id="JSONRPCBridge" scope="session"
> > class="com.metaparadigm.jsonrpc.JSONRPCBridge"/>
> > <jsp:useBean id="WorkspaceController" scope="session"
> > class="WorkspaceControllerBean"/>
> >
> > <%
> >     JSONRPCBridge.getGlobalBridge().setDebug(true);
> >     JSONRPCBridge.getGlobalBridge().registerObject("Workspaces",
> > WorkspaceController);
> >
> >     WorkspaceControllerBean mybean = (WorkspaceControllerBean)
> > JSONRPCBridge.getGlobalBridge().lookup("Workspaces");
> > %>
> >
> > [<%= mybean.hello("qwerty") %>]
> >
> >
> > This code produces on the HTML page the text: "hello 
> qwerty!!!", so I
> > know that the object "Workspaces"
> > is registered with the bridge.
> >
> >
> > However, in my javascript code I have the code that is not working:
> >
> > <%@ include file="/jsp/workspaces/json-workspace-bean.jsp" %>
> > <script language="javascript" type="text/javascript">
> > function objectToString(anObject,objectName)
> > {
> >   var retVal = ""; // this will be our string to return eventually
> >   var value;
> >
> >   if(null != objectName)
> >   {
> >     retVal += "["+objectName +"] {";
> >   }
> >
> >   // loop through each item in the object
> >   for(memberObjKey in anObject)
> >   {
> >     retVal += "["+memberObjKey+"]";
> >     value = anObject[memberObjKey];
> >     
> >     if('object' == typeof value)
> >     {
> >       retVal += " {"+objectToString(value)+"}";
> >     }
> >     else
> >     {
> >       retVal += " '"+value+"' ";
> >     }
> >     retVal += " ";
> >   }
> >
> >   if(null != objectName)
> >   {
> >     retVal += " }";
> >   }
> >
> >   return retVal;
> > }
> >
> > function loadWorkspaces() {
> >     try {
> >         /* Fetch a handle to the JSON-RPC bridge */
> >         var jsonrpc = new JSONRpcClient("/jsonrpc-1.0/JSON-RPC");
> >         alert(toJSON(jsonrpc));
> >
> >         /* Show the workspaces */
> >         document.write("blahblah");
> >         document.write(jsonrpc.Workspaces.hello("qwerty"));
> >     }
> >     catch (e) {
> >         alert("caught json exception: " + e.message);
> >     }
> > }
> > loadWorkspaces();
> > </script>
> >
> > This code produces an alert dialog with the text:
> >
> > {"serverURL": "/jsonrpc-1.0/JSON-RPC", "user": null, "pass": null,
> > "objectID": null, "system": {}, "charset": "utf-8"}
> >
> > It seems that no objects are registered with the bridge...
> >
> >   
> I made a quick change to the hello example and registered the object
> against the global bridge and it appears to be working (see 
> patch at end).
> 
> I notice you are registering a session scoped object in the global
> bridge. You should have scope="application" in your usebean if you are
> registering it on the global bridge.
> 
> Also see FAQ item 9 http://oss.metaparadigm.com/jsonrpc/faq.html#q9 on
> enabling debugging. This will let you see what is happening on the
> JSON-RPC server side when the client makes the request. Send us the
> debug log.
> 
> --- webapps/jsonrpc/hello.jsp   9 Feb 2005 02:27:55 -0000       1.1
> +++ webapps/jsonrpc/hello.jsp   26 Jul 2006 03:30:48 -0000
> @@ -2,9 +2,9 @@
>   "http://www.w3.org/TR/html4/loose.dtd">
>  <jsp:useBean id="JSONRPCBridge" scope="session"
>       class="com.metaparadigm.jsonrpc.JSONRPCBridge" />
> -<jsp:useBean id="hello" scope="session"
> +<jsp:useBean id="hello" scope="application"
>       class="com.metaparadigm.jsonrpc.test.Hello" />
> -<% JSONRPCBridge.registerObject("hello", hello); %>
> +<% JSONRPCBridge.getGlobalBridge().registerObject("hello", hello); %>
>  <html>
>    <head>
>      <script type="text/javascript" src="jsonrpc.js"></script>
> 
> 
> 


This e-mail and any attachment is for authorised use by the intended recipient(s) only. It may contain proprietary material, confidential information and/or be subject to legal privilege. It should not be copied, disclosed to, retained or used by, any other party. If you are not an intended recipient then please promptly delete this e-mail and any attachment and all copies and inform the sender. Thank you.


More information about the Json-rpc-java mailing list