1 package net.sf.crispy.impl; 2 3 import java.util.Properties; 4 5 import net.sf.crispy.InvocationException; 6 import net.sf.crispy.InvocationStrategy; 7 import net.sf.crispy.proxy.StaticProxy; 8 import net.sf.crispy.strategy.NameInvocationStrategy; 9 10 import com.caucho.hessian.client.HessianProxyFactory; 11 12 /** 13 * Remote-Call with Hessian Remote Invocation (Caucho). 14 * 15 * @author Linke 16 * 17 */ 18 public class StaticHessianProxy extends StaticProxy { 19 20 public final static String DEFAULT_URL_AND_PORT = "http://localhost:8091/crispy/hessian"; 21 22 /** 23 * Get default url and port. If no url and port is in properties. 24 * 25 * @return Default url and port. 26 */ 27 public String getDefaultUrlAndPort() { 28 return DEFAULT_URL_AND_PORT; 29 } 30 31 public InvocationStrategy getDefaultInvocationStrategy(Properties pvProperties) { 32 String lvInterfaceName = (String) pvProperties.get(PROPERTY_CURRENT_INTERFACE_CLASS); 33 return new NameInvocationStrategy(lvInterfaceName); 34 } 35 36 /** 37 * @see net.sf.crispy.proxy.Proxy#newInstance(java.lang.Class) 38 */ 39 public Object newInstance(Class pvProxyClass) { 40 String lvUrlAndPort = getUrlAndPort() + "/" + getInvocationStrategy(); 41 if (log.isDebugEnabled()) { log.debug("Hessian Url and Port: " + lvUrlAndPort); } 42 HessianProxyFactory factory = new HessianProxyFactory(); 43 factory.setOverloadEnabled(true); 44 try { 45 Object lvProxyObject = factory.create(pvProxyClass, lvUrlAndPort); 46 setProxyObject(lvProxyObject); 47 setProxyClass(lvProxyObject.getClass()); 48 } catch (Exception e) { 49 throw new InvocationException("Error in newInstance in StaticHessianProxy: " + e, e); 50 } 51 if (log.isDebugEnabled()) { log.debug("Hessian Object created: " + getProxyObject()); } 52 return getProxyObject(); 53 } 54 }