Package com.caucho.hessian.client
Class HessianProxyFactory
- java.lang.Object
-
- com.caucho.hessian.client.HessianProxyFactory
-
- All Implemented Interfaces:
ServiceProxyFactory,ObjectFactory
public class HessianProxyFactory extends Object implements 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 tocreateIn 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.
-
-
Constructor Summary
Constructors Constructor Description HessianProxyFactory()Creates the new proxy factory.HessianProxyFactory(ClassLoader loader)Creates the new proxy factory.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Objectcreate(Class<?> api, String urlName, ClassLoader loader)Creates a new proxy with the specified URL.Objectcreate(Class<?> api, URL url, ClassLoader loader)Creates a new proxy with the specified URL.Objectcreate(Class api, String urlName)Creates a new proxy with the specified URL.Objectcreate(String url)Creates a new proxy with the specified URL.protected HessianConnectionFactorycreateHessianConnectionFactory()static charencode(long d)StringgetBasicAuth()HessianConnectionFactorygetConnectionFactory()Returns the connection factory to be used for the HTTP request.longgetConnectTimeout()The socket connection timeout in milliseconds.AbstractHessianInputgetHessian1Input(InputStream is)AbstractHessianInputgetHessian2Input(InputStream is)AbstractHessianInputgetHessianInput(InputStream is)AbstractHessianOutputgetHessianOutput(OutputStream os)ObjectgetObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?,?> environment)JNDI object factory so the proxy can be used as a resource.longgetReadTimeout()The socket timeout on requests in milliseconds.HessianRemoteResolvergetRemoteResolver()Returns the remote resolver.SerializerFactorygetSerializerFactory()Gets the serializer factory.booleanisChunkedPost()Set true if should use chunked encoding on the request.booleanisDebug()Gets the debugbooleanisOverloadEnabled()Returns true if overloaded methods are allowed (using mangling)voidsetChunkedPost(boolean isChunked)Set true if should use chunked encoding on the request.voidsetConnectionFactory(HessianConnectionFactory factory)Sets the connection factory to use when connecting to the Hessian service.voidsetConnectTimeout(long timeout)The socket connect timeout in milliseconds.voidsetDebug(boolean isDebug)Sets the debugvoidsetHessian2Reply(boolean isHessian2)True if the proxy can read Hessian 2 responses.voidsetHessian2Request(boolean isHessian2)True if the proxy should send Hessian 2 requests.voidsetOverloadEnabled(boolean isOverloadEnabled)set true if overloaded methods are allowed (using mangling)voidsetPassword(String password)Sets the password.voidsetReadTimeout(long timeout)The socket timeout on requests in milliseconds.voidsetSerializerFactory(SerializerFactory factory)Sets the serializer factory.voidsetUser(String user)Sets the user.
-
-
-
Field Detail
-
log
protected static Logger log
-
-
Constructor Detail
-
HessianProxyFactory
public HessianProxyFactory()
Creates the new proxy factory.
-
HessianProxyFactory
public HessianProxyFactory(ClassLoader loader)
Creates the new proxy factory.
-
-
Method Detail
-
setUser
public void setUser(String user)
Sets the user.
-
setPassword
public void setPassword(String password)
Sets the password.
-
getBasicAuth
public String getBasicAuth()
-
setConnectionFactory
public void setConnectionFactory(HessianConnectionFactory factory)
Sets the connection factory to use when connecting to the Hessian service.
-
getConnectionFactory
public HessianConnectionFactory getConnectionFactory()
Returns the connection factory to be used for the HTTP request.
-
setDebug
public void setDebug(boolean isDebug)
Sets the debug
-
isDebug
public boolean isDebug()
Gets the debug
-
isOverloadEnabled
public boolean isOverloadEnabled()
Returns true if overloaded methods are allowed (using mangling)
-
setOverloadEnabled
public void setOverloadEnabled(boolean isOverloadEnabled)
set true if overloaded methods are allowed (using mangling)
-
setChunkedPost
public void setChunkedPost(boolean isChunked)
Set true if should use chunked encoding on the request.
-
isChunkedPost
public boolean isChunkedPost()
Set true if should use chunked encoding on the request.
-
getReadTimeout
public long getReadTimeout()
The socket timeout on requests in milliseconds.
-
setReadTimeout
public void setReadTimeout(long timeout)
The socket timeout on requests in milliseconds.
-
getConnectTimeout
public long getConnectTimeout()
The socket connection timeout in milliseconds.
-
setConnectTimeout
public void setConnectTimeout(long timeout)
The socket connect timeout in milliseconds.
-
setHessian2Reply
public void setHessian2Reply(boolean isHessian2)
True if the proxy can read Hessian 2 responses.
-
setHessian2Request
public void setHessian2Request(boolean isHessian2)
True if the proxy should send Hessian 2 requests.
-
getRemoteResolver
public HessianRemoteResolver getRemoteResolver()
Returns the remote resolver.
-
setSerializerFactory
public void setSerializerFactory(SerializerFactory factory)
Sets the serializer factory.
-
getSerializerFactory
public SerializerFactory getSerializerFactory()
Gets the serializer factory.
-
createHessianConnectionFactory
protected HessianConnectionFactory createHessianConnectionFactory()
-
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.
- Throws:
MalformedURLExceptionClassNotFoundException
-
create
public Object create(Class api, String urlName) 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:
createin interfaceServiceProxyFactory- Parameters:
api- the interface the proxy class needs to implementurl- the URL where the client object is located.- Returns:
- a proxy to the object with the specified interface.
- Throws:
MalformedURLException
-
create
public Object create(Class<?> api, String urlName, ClassLoader loader) 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);
- Parameters:
api- the interface the proxy class needs to implementurl- the URL where the client object is located.- Returns:
- a proxy to the object with the specified interface.
- Throws:
MalformedURLException
-
create
public Object create(Class<?> api, URL url, ClassLoader loader)
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);
- Parameters:
api- the interface the proxy class needs to implementurl- the URL where the client object is located.- Returns:
- a proxy to the object with the specified interface.
-
getHessianInput
public AbstractHessianInput getHessianInput(InputStream is)
-
getHessian1Input
public AbstractHessianInput getHessian1Input(InputStream is)
-
getHessian2Input
public AbstractHessianInput getHessian2Input(InputStream is)
-
getHessianOutput
public AbstractHessianOutput 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.- Specified by:
getObjectInstancein interfaceObjectFactory- Throws:
Exception
-
encode
public static char encode(long d)
-
-