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 org.springframework.beans.MutablePropertyValues;
21  import org.springframework.context.support.StaticApplicationContext;
22  import org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean;
23  import org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter;
24  
25  import ch.elca.el4j.services.remoting.AbstractRemotingBase;
26  import ch.elca.el4j.services.remoting.RemotingProxyFactoryBean;
27  import ch.elca.el4j.services.remoting.RemotingServiceExporter;
28  
29  /**
30   * This class implements all needed things for the httpinvoker protocol.
31   *
32   * @svnLink $Revision: 3875 $;$Date: 2009-08-04 14:35:53 +0200 (Di, 04. Aug 2009) $;$Author: swismer $;$URL: https://el4j.svn.sourceforge.net/svnroot/el4j/branches/el4j_3_1/el4j/framework/modules/remoting_core/src/main/java/ch/elca/el4j/services/remoting/protocol/HttpInvoker.java $
33   *
34   * @author Rashid Waraich (RWA)
35   */
36  public class HttpInvoker  extends AbstractInetSocketAddressWebProtocol {
37  
38  	/**
39  	 * {@inheritDoc}
40  	 */
41  	public Object createProxyBean(RemotingProxyFactoryBean proxyBean,
42  			Class serviceInterfaceWithContext) {
43  		StaticApplicationContext appContext = new StaticApplicationContext(
44  				m_parentApplicationContext);
45  		registerChildApplicationContext(appContext);
46  		MutablePropertyValues props = new MutablePropertyValues();
47  		props.addPropertyValue("serviceInterface", serviceInterfaceWithContext);
48  		props.addPropertyValue("serviceUrl", generateUrl(proxyBean));
49  		appContext.registerSingleton("httpInvokerProxyBeanGen",
50  			getProxyObjectType(), props);
51  		appContext.refresh();
52  		return appContext.getBean("httpInvokerProxyBeanGen");
53  	}
54  
55  	/**
56  	 * {@inheritDoc}
57  	 */
58  	public Object createExporterBean(RemotingServiceExporter exporterBean,
59  			Class serviceInterfaceWithContext, Object serviceProxy) {
60  		StaticApplicationContext appContext = new StaticApplicationContext(
61  				m_parentApplicationContext);
62  		registerChildApplicationContext(appContext);
63  		MutablePropertyValues props = new MutablePropertyValues();
64  		props.addPropertyValue("service", serviceProxy);
65  		props.addPropertyValue("serviceInterface", serviceInterfaceWithContext);
66  		appContext.registerSingleton("httpInvokerExporterBeanGen",
67  				getExporterObjectType(), props);
68  		appContext.refresh();
69  		return appContext.getBean("httpInvokerExporterBeanGen");
70  	}
71  
72  	/**
73  	 * {@inheritDoc}
74  	 */
75  	public Class getProxyObjectType() {
76  		return HttpInvokerProxyFactoryBean.class;
77  	}
78  
79  	/**
80  	 * {@inheritDoc}
81  	 */
82  	public Class getExporterObjectType() {
83  		return HttpInvokerServiceExporter.class;
84  	}
85  
86  	/**
87  	 * {@inheritDoc}
88  	 */
89  	public String generateUrl(AbstractRemotingBase remoteBase) {
90  		StringBuffer sb = new StringBuffer();
91  		sb.append("http://");
92  		sb.append(getServiceHost());
93  		sb.append(":");
94  		sb.append(getServicePort());
95  		sb.append("/");
96  		sb.append(getContextPath());
97  		sb.append("/");
98  		sb.append(remoteBase.getServiceName());
99  		return sb.toString();
100 	}
101 }