Mobile Hessian


Client for the New Service

Now that your new authentication service is up and running, it's time to write a client to use the provided methods. The code in Listing 9.5 shows how to access the methods using the same techniques found in the BasicAPI client.

Listing 9.5: CAService client code.

start example
 import com.caucho.hessian.client.HessianProxyFactory; import java.net.MalformedURLException; import java.util.Vector; import authentication.CAServiceAPI; public class CAClient {   static String url = "http://localhost:8080/hessian/authentication/CAService";   public static void main(String[] args) {     CAServiceAPI basic = null;     HessianProxyFactory factory = new HessianProxyFactory();     try {       basic = (CAServiceAPI) factory.create(CAServiceAPI.class, url);     } catch (MalformedURLException e) {         System.out.println("Bad URL");     }     if (basic != null) {       try {       System.out.println("newaccount creation status = "         + basic.createNewAccount("username", "password"));       System.out.println("check basic authentication with         username/password = " +         basic.baseAuthenticate("username", "password"));       System.out.println("check basic authentication with         usernamel/passwordl = "         + basic.baseAuthenticate("usernamel", "passwordl"));       Vector vec = (Vector)basic.provideCertificate("username",        "password");       System.out.println("First 10 values in vector");       for(int i=0;i<10;i++)         System.out.print(vec.elementAt(i) + " ");       System.out.println("");       System.out.println("check basic authentication with         username/password = "         + basic.secureAuthentication("username", "password",          vec));       } catch (Exception e) {         e.printStackTrace();       }     }   } } 
end example

As you look through the code in Listing 9.5, you will find that it looks like the BasicAPI client, except instead of using BasicAPI as the interface class, it uses

CAServiceAPI instead. The code in the client exercises all the methods of the authentication service. When you compile and execute the client, it is imperative that both the hessian-3.0.2.jar and the CAServiceAPI.jar files be found in the classpath. If the JAR files aren't in the classpath, the client will produce an error. Figure 9.2 shows the output from an execution of the client code.

click to expand
Figure 9.2: CACIient execution output.




Mastering Resin
Mastering Resin
ISBN: 0471431036
EAN: 2147483647
Year: 2002
Pages: 180

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net