View Javadoc

1   /*
2    * EL4J, the Extension Library for the J2EE, adds incremental enhancements to
3    * the spring framework, http://el4j.sf.net
4    * Copyright (C) 2005 by ELCA Informatique SA, Av. de la Harpe 22-24,
5    * 1000 Lausanne, Switzerland, http://www.elca.ch
6    *
7    * EL4J is published under the GNU Lesser General Public License (LGPL)
8    * Version 2.1. See http://www.gnu.org/licenses/
9    *
10   * This program is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13   * GNU Lesser General Public License for more details.
14   *
15   * For alternative licensing, please contact info@elca.ch
16   */
17  
18  package ch.elca.el4j.services.remoting.protocol;
19  
20  import java.util.Map;
21  
22  import org.springframework.beans.MutablePropertyValues;
23  import org.springframework.context.support.StaticApplicationContext;
24  import org.springframework.remoting.caucho.HessianProxyFactoryBean;
25  import org.springframework.remoting.caucho.HessianServiceExporter;
26  
27  import ch.elca.el4j.services.remoting.AbstractRemotingBase;
28  import ch.elca.el4j.services.remoting.RemotingProxyFactoryBean;
29  import ch.elca.el4j.services.remoting.RemotingServiceExporter;
30  
31  /**
32   * This class implements all needed things for the hessian protocol.
33   *
34   * @svnLink $Revision: 4204 $;$Date: 2010-11-02 11:44:37 +0100 (Di, 02. Nov 2010) $;$Author: swisswheel $;$URL: https://el4j.svn.sourceforge.net/svnroot/el4j/branches/el4j_3_1/el4j/framework/modules/remoting_caucho/src/main/java/ch/elca/el4j/services/remoting/protocol/Hessian.java $
35   *
36   * @author Martin Zeltner (MZE)
37   */
38  public class Hessian extends AbstractInetSocketAddressWebProtocol {
39  	
40  	/**
41  	 * Additional properties to set.
42  	 */
43  	protected Map<String, Object> m_serviceProperties;
44  	
45  	/**
46  	 * {@inheritDoc}
47  	 */
48  	public Object createProxyBean(RemotingProxyFactoryBean proxyBean,
49  			Class serviceInterfaceWithContext) {
50  		StaticApplicationContext appContext = new StaticApplicationContext(
51  				m_parentApplicationContext);
52  		registerChildApplicationContext(appContext);
53  		MutablePropertyValues proxyProps = new MutablePropertyValues();
54  		proxyProps.addPropertyValue("serviceInterface",
55  				serviceInterfaceWithContext);
56  		proxyProps.addPropertyValue("serviceUrl", generateUrl(proxyBean));
57  		if (m_serviceProperties != null) {
58  			for (String property : m_serviceProperties.keySet()) {
59  				proxyProps.addPropertyValue(property,
60  					m_serviceProperties.get(property));
61  			}
62  		}
63  		appContext.registerSingleton("hessianProxyBeanGen",
64  				getProxyObjectType(), proxyProps);
65  		appContext.refresh();
66  		return appContext.getBean("hessianProxyBeanGen");
67  	}
68  
69  	/**
70  	 * {@inheritDoc}
71  	 */
72  	public Object createExporterBean(RemotingServiceExporter exporterBean,
73  			Class serviceInterfaceWithContext, Object serviceProxy) {
74  		StaticApplicationContext appContext = new StaticApplicationContext(
75  				m_parentApplicationContext);
76  		registerChildApplicationContext(appContext);
77  		MutablePropertyValues props = new MutablePropertyValues();
78  		props.addPropertyValue("service", serviceProxy);
79  		props.addPropertyValue("serviceInterface", serviceInterfaceWithContext);
80  		appContext.registerSingleton("hessianExporterBeanGen",
81  				getExporterObjectType(), props);
82  		appContext.refresh();
83  		return appContext.getBean("hessianExporterBeanGen");
84  	}
85  
86  	/**
87  	 * {@inheritDoc}
88  	 */
89  	public Class getProxyObjectType() {
90  		return HessianProxyFactoryBean.class;
91  	}
92  
93  	/**
94  	 * {@inheritDoc}
95  	 */
96  	public Class getExporterObjectType() {
97  		return HessianServiceExporter.class;
98  	}
99  
100 	/**
101 	 * {@inheritDoc}
102 	 */
103 	public String generateUrl(AbstractRemotingBase remoteBase) {
104 		StringBuffer sb = new StringBuffer();
105 		sb.append(getServiceProtocol());
106 		sb.append("://");
107 		sb.append(getServiceHost());
108 		sb.append(":");
109 		sb.append(getServicePort());
110 		sb.append("/");
111 		sb.append(getContextPath());
112 		sb.append("/");
113 		sb.append(remoteBase.getServiceName());
114 		return sb.toString();
115 	}
116 
117 	/**
118 	 * @return    the additional service properties
119 	 */
120 	public Map<String, Object> getServiceProperties() {
121 		return m_serviceProperties;
122 	}
123 
124 	/**
125 	 * @param serviceProperties    the additional service properties to set
126 	 */
127 	public void setServiceProperties(Map<String, Object> serviceProperties) {
128 		m_serviceProperties = serviceProperties;
129 	}
130 }