Class UrlInvocationHandler

  • All Implemented Interfaces:
    InvocationHandler

    public class UrlInvocationHandler
    extends Object
    implements InvocationHandler
    Useful utility for allowing Java code to make Ajax calls, yet the Java code can make these calls via Dynamic Proxies created from Java interfaces for the remote server(s). Example: Assume you have a tomcat instance running a JSON Command Servlet, like com.cedarsoftware's or Spring MVC. Assume you have a Java interface 'Explorer' that is mapped to a Java bean that you are allowing to be called through RESTful JSON calls (Ajax / XHR). Explorer has methods on it, like getFiles(userId), etc. You need to use a SessionAware (JSESSIONID only) or CookieAware UrlInvocationHandler to interact with the server so that the cookies will be placed on all requests. In Javascript within browsers, this is taken care of for you. Not so in the Java side.
     Map cookies = new HashMap();
     String url = "http://www.mycompany.com:80/json/"
    
     InvocationHandler handler = new UrlInvocationHandler(new UrlInvocationHandlerStrategyImplementation(url, ...));
     Explorer explorer = (Explorer) ProxyFactory.create(Explorer.class, handler);
    
     At this point, your Java code can do this:
    
     List files = explorer.getFiles(userId);
     
    Author:
    Ken Partlow ([email protected]), John DeRegnaucourt ([email protected])
    Copyright (c) Cedar Software LLC

    Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.