1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
33
34
35
36
37
38 public class Hessian extends AbstractInetSocketAddressWebProtocol {
39
40
41
42
43 protected Map<String, Object> m_serviceProperties;
44
45
46
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
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
88
89 public Class getProxyObjectType() {
90 return HessianProxyFactoryBean.class;
91 }
92
93
94
95
96 public Class getExporterObjectType() {
97 return HessianServiceExporter.class;
98 }
99
100
101
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
119
120 public Map<String, Object> getServiceProperties() {
121 return m_serviceProperties;
122 }
123
124
125
126
127 public void setServiceProperties(Map<String, Object> serviceProperties) {
128 m_serviceProperties = serviceProperties;
129 }
130 }