Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    A way to inject a param in the explicit RPC call

    Wondering if there is any way to ensure that the following RPC call to getSomething() contains a certain parameter which is not an arg. I am trying to avoid adding args to the method call. My hope is to force a parameter in each call from various places and handle that on the server side only. There are multiple places where this service is called from and changing a method signature would mean all the calls have to be updated at the same time.

    Perhaps alter request, or something like that.

    thanks!

    Code:
    // inject parameter in the following call
       ???
    
    // make the call
    SomeService.App.getInstance().getSomething(
                arg1, 
                new AsyncCallback<RPCMessage>() {
                    @Override
                    public void onFailure(Throwable throwable) {
                           //Uh-oh
                    }
    
                   @Override
                   public void onSuccess(RPCMessage rpcMessage) {
                           //Yey!
                   }
    );

    #2
    Aren't you in control of the getSomething() implementation? In there you can pass some hardcoded arguments to your liking.

    Here's a cheezy RPC operation template.
    You can add some hard parameters like "SESSION", "OPERATION", or pass another argument in that implementation before sending it to the server.

    Your server handler (your own class x which extends IDACall) can extract those and do whatever with it. In there, you can also force some parameter in the request if you don't need that parameter to be sent from the client.


    Code:
    public void getMilk(Integer numberOfCows, String barnName, RPCCallback callback) {
    
    	RPCRequest rpcRequest = new RPCRequest();
    //tune rpcRequest
    	
    	Map<String, String> paramTypes = new LinkedHashMap<String, String>();
    	Map<String, Object> values = new LinkedHashMap<String, Object>();
    	
    	paramTypes.put("arg" + paramTypes.size(), numberOfCows.getClass().getName());
    	values.put("arg" + values.size(), numberOfCows);
    	
    	paramTypes.put("arg" + paramTypes.size(), barnName.getClass().getName());
    	values.put("arg" + values.size(), barnName);
    //add some other arguments
    	
    	Map<String, Object> payLoad = new HashMap<String, Object>();
    	payLoad.put(BEAN, cowService.getInterfaceName());
    	payLoad.put(BEANOPERATION, cowService.getMilk.getName());
    	payLoad.put(PARAMTYPES, paramTypes);
    	payLoad.put(VALUES, values);
    //add some parameters
    	
    	rpcRequest.setData(payLoad);
    	RPCManager.sendRequest(rpcRequest, callback);
    }

    Comment


      #3
      Thanks for the suggestions. I decided to just go ahead and make changes to the getSomething() and include a new argument. The change is invasive but at least it seems like the right thing to do.

      Comment

      Working...
      X