[Hypercup-users] How to use HyperCuP in your web application
Status: Beta
Brought to you by:
s_kruk
From: Slawek G. <sla...@de...> - 2005-09-16 21:56:27
|
Hi, Using HyperCuP implementation in your web application requires 3 steps in your java code, and set up topology. The 3 java steps: 1) At the beginning of your work with HyperCuP you must initialize it. In FOAFRealm and JeromeDL projects we use an servlet, which has everything in method init. The web applications use the servlet and method init is automatically invoked, if web.xml is configured correctly. Simplified body of the method init: public void init(ServletConfig config) throws ServletException { //setting up the full address of the Web Service Configurator conf = HyperCuP.getInstance().registerServiceURL(props.getProperty("service_url"),"dfoaf"); //implementation of the local query must be given conf.registerLocalQuery(new LocalQueryImpl()); //file to contain configuration must be specified conf.registerConnectionPropertiesFile("/tmp/hypercup-connections.xml"); } 2) Implementation of the local query. LocalQuery interface contains only one method that has the following signature: Serializable performQuery(Serializable query); It defines the behavior of the peers in the HyperCuP network. A Serializable argument lets us to pass parameters like Strings and many others. The method is invoked on every peer in the HyperCuP network and every peer sends results. Simplified example of implementation public class LocalQueryImpl implements LocalQuery { public Serializable performQuery(Serializable query) { //get user name and password from query String userData=(String)query; //an example of processing the data return authenticate(userData); } 3) Performing the query in web application: In order to use the query your code should contain similar code: LocalQueryImpl lqi=new LocalQueryImpl(); lqi.performQuery("us...@fo...::mypassword"); I think it is enough for the early beginning. I mentioned above that yon need to set up the topology. Currently the topology is configured manually. I do not want to describe the steps of this process because Pawel is going to change the code. Next week it will be able to do it in much easier way. If you do not set up the topology, your application can work, but on only one machine. So, you can start your work asap. Don't hesitate to ask me if you need more info, or just check FOAFRealm, JeromeDL projects source codes (located at sf.net) Best, Slawek |