0

I need to reference a JSON-RPC method by the URL and wondering how to do it or if you can do it.

I want to do it this way because I want to make the call inside of a $.post using jQuery.deferred(). Look at this example to see what I am trying to accomplish. I want to replace the "/echo/html/" with my RPC method. If I had to I could rewrite my RPC as an XAgent, but I would rather first see if anyone knew how to call it via URL.

My RPC method looks like this: openATMRPC.openATMFirst(); It works fine using traditional javascript, but as you can see I want it chained inside of the jQuery deferred function so that the .always runs.

var deferred = function(trueFalse) {
    // return value from response as `deferred.promise`
    // within `setTimeout` , after `1000` ms (one second)
    return new $.Deferred(function (dfd) {
    setTimeout(function () {
        $.post("/echo/html/", {
            html: trueFalse
        })
    // `deferred.always` utilized here ,
    // to catch either `success` or `fail` ,
    // not certain about `error` (`fail`) callbacks ?
        .always(function (data) {
            dfd.resolve(data)
        })
    }, 1000);
    // return `deferred.promise()` , 
    // e.g., "true" , or "false"
    return dfd.promise()
})
};

UPDATE


Sorry if this wasn't clear previously. This is the XSP code for the remote call. The pathInfo property is part of the answer, but I haven't figured out how to use it to reference the method via a URL, which is what I am seeking. If I reference the ".../rpc" I get a "Service Error" message which is progress. How do I call the method inside the RPC-JSON via the URL is my question?

<xe:jsonRpcService id="jsonRpcService2" serviceName="openATMRPC" pathInfo="rpc">
        <xe:this.methods>                               
            <xe:remoteMethod name="openATMFirst">
<xe:this.script>
<![CDATA[print("into First");
var firstTry:boolean = atmBean.openATM(atmBean.atmID, userBean.userID, userBean.userPassword);
if(firstTry == false){
    return firstTry.toString();
} else if(firstTry == true){
    //atmBean.infoMessage = atmBean.atmID + " has been successfully Opened.";
    return firstTry.toString();
}]]></xe:this.script></xe:remoteMethod>
Steve Zavocki
  • 1,840
  • 4
  • 21
  • 35
  • That's not an XPages question. That's a jquery question. Without the server side there isn't a xpages solution – stwissel Sep 30 '14 at 15:08
  • I only tagged XPages, because the issue was calling an Ext Lib component JSON-RPC using the URL. I didn't think that would mean much to non XPage developers. – Steve Zavocki Sep 30 '14 at 15:18
  • It also doesn't mean to an XPages developer. You show a fraction of a client side JS without context. Mock the server side with a static response to get the client side to work. Separate the two pieces – stwissel Sep 30 '14 at 15:22
  • Fair enough, I will update the question with the JSON-RPC XSP code. Since I asked the question, I discovered the pathInfo property, now I just need to know how to call the method. – Steve Zavocki Sep 30 '14 at 15:25
  • The pathInfo is not what I thought. I don't think what I am trying to do is possible, therefore I don't think this question can be answered. It is my conclusion that the JSON-RPC control is not intended on being called from the URL. I will close question later. – Steve Zavocki Sep 30 '14 at 15:58
  • Stephan, I am not sure what you mean by your last comment. It seems to me that I am at a dead end, if there is something I am missing, please let me know. – Steve Zavocki Sep 30 '14 at 16:34
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/62199/discussion-between-stwissel-and-steve-zavocki). – stwissel Sep 30 '14 at 16:37

1 Answers1

1

The most likely piece you are looking for is the exact address of a JSON REST control. They do live inside an XPage (the page doesn't need to do anything useful). Look at a sample service:

<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core"
    xmlns:xe="http://www.ibm.com/xsp/coreex">
        <xe:jsonRpcService id="jsonRpcService1" serviceName="helloService">
        <xe:this.methods>
            <xe:remoteMethod name="sayHello">

                <xe:this.arguments>
                    <xe:remoteMethodArg name="who" type="string"></xe:remoteMethodArg>
                </xe:this.arguments>
                <xe:this.script><![CDATA[return "Hello " + who;]]></xe:this.script>
            </xe:remoteMethod>
        </xe:this.methods>
    </xe:jsonRpcService>
        <xp:label value="Who" id="label1" for="inputText1"></xp:label>
        <xp:inputText id="inputText1" value="#{viewScope.who}"></xp:inputText>
        <xp:button value="Greet Me" id="button1">
            <xp:eventHandler event="onclick" submit="false">
                <xp:this.script><![CDATA[var deferred = helloService.sayHello(dojo.byId("#{id:inputText1}").value);
deferred.addCallback(function(result) {
    alert(result)
});]]></xp:this.script>
            </xp:eventHandler></xp:button>
</xp:view>

Of course that uses Dojo under the hood. But when you look at the service URL - what you probably are looking for, you find something like:

/yournsf.nsf/sample.xsp?$$viewid=!dwjn9ryrqh!&$$axtarget=view:_id1:jsonRpcService1

The first value is send down by the browser in a hidden field with the name (not the id) $$viewid, the second one is the #{id:jsonRpcService1}

So you can use a scriptblock to send that value down and get your end-point. Most likely a REST service would be easier there, but that's up to you.

stwissel
  • 20,110
  • 6
  • 54
  • 101