com.caucho.hessian.client

Class HessianProxyFactory

Implemented Interfaces:
ObjectFactory, com.caucho.services.client.ServiceProxyFactory

public class HessianProxyFactory
extends java.lang.Object
implements com.caucho.services.client.ServiceProxyFactory, ObjectFactory

Factory for creating Hessian client stubs. The returned stub will call the remote object for all methods.
 String url = "http://localhost:8080/ejb/hello";
 HelloHome hello = (HelloHome) factory.create(HelloHome.class, url);
 
After creation, the stub can be like a regular Java class. Because it makes remote calls, it can throw more exceptions than a Java class. In particular, it may throw protocol exceptions. The factory can also be configured as a JNDI resource. The factory expects to parameters: "type" and "url", corresponding to the two arguments to create In Resin 3.0, the above example would be configured as:
 <reference>
   <jndi-name>hessian/hello</jndi-name>
   <factory>com.caucho.hessian.client.HessianProxyFactory</factory>
   <init-param url="http://localhost:8080/ejb/hello"/>
   <init-param type="test.HelloHome"/>
 </reference>
 
To get the above resource, use JNDI as follows:
 Context ic = new InitialContext();
 HelloHome hello = (HelloHome) ic.lookup("java:comp/env/hessian/hello");

 System.out.println("Hello: " + hello.helloWorld());
 

Authentication

The proxy can use HTTP basic authentication if the user and the password are set.

Field Summary

private String
_basicAuth
private boolean
_isOverloadEnabled
private String
_password
private HessianRemoteResolver
_resolver
private String
_user

Constructor Summary

HessianProxyFactory()
Creates the new proxy factory.

Method Summary

private String
base64(String value)
Creates the Base64 value.
Object
create(Class api, String url)
Creates a new proxy with the specified URL.
Object
create(String url)
Creates a new proxy with the specified URL.
static char
encode(long d)
AbstractHessianInput
getHessianInput(InputStream is)
HessianOutput
getHessianOutput(OutputStream os)
Object
getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable environment)
JNDI object factory so the proxy can be used as a resource.
HessianRemoteResolver
getRemoteResolver()
Returns the remote resolver.
boolean
isOverloadEnabled()
Returns true if overloaded methods are allowed (using mangling)
protected URLConnection
openConnection(URL url)
Creates the URL connection.
void
setOverloadEnabled(boolean isOverloadEnabled)
set true if overloaded methods are allowed (using mangling)
void
setPassword(String password)
Sets the password.
void
setUser(String user)
Sets the user.

Field Details

_basicAuth

private String _basicAuth

_isOverloadEnabled

private boolean _isOverloadEnabled

_password

private String _password

_resolver

private HessianRemoteResolver _resolver

_user

private String _user

Constructor Details

HessianProxyFactory

public HessianProxyFactory()
Creates the new proxy factory.

Method Details

base64

private String base64(String value)
Creates the Base64 value.

create

public Object create(Class api,
                     String url)
            throws MalformedURLException
Creates a new proxy with the specified URL. The returned object is a proxy with the interface specified by api.
 String url = "http://localhost:8080/ejb/hello");
 HelloHome hello = (HelloHome) factory.create(HelloHome.class, url);
 
Specified by:
create in interface com.caucho.services.client.ServiceProxyFactory
Parameters:
api - the interface the proxy class needs to implement
url - the URL where the client object is located.
Returns:
a proxy to the object with the specified interface.

create

public Object create(String url)
            throws MalformedURLException,
                   ClassNotFoundException
Creates a new proxy with the specified URL. The API class uses the java.api.class value from _hessian_
Parameters:
url - the URL where the client object is located.
Returns:
a proxy to the object with the specified interface.

encode

public static char encode(long d)

getHessianInput

public AbstractHessianInput getHessianInput(InputStream is)

getHessianOutput

public HessianOutput getHessianOutput(OutputStream os)

getObjectInstance

public Object getObjectInstance(Object obj,
                                Name name,
                                Context nameCtx,
                                Hashtable environment)
            throws Exception
JNDI object factory so the proxy can be used as a resource.

getRemoteResolver

public HessianRemoteResolver getRemoteResolver()
Returns the remote resolver.

isOverloadEnabled

public boolean isOverloadEnabled()
Returns true if overloaded methods are allowed (using mangling)

openConnection

protected URLConnection openConnection(URL url)
            throws IOException
Creates the URL connection.

setOverloadEnabled

public void setOverloadEnabled(boolean isOverloadEnabled)
set true if overloaded methods are allowed (using mangling)

setPassword

public void setPassword(String password)
Sets the password.

setUser

public void setUser(String user)
Sets the user.