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.jaxws.JaxWsPortProxyFactoryBean;
23
24 import ch.elca.el4j.services.remoting.AbstractRemotingBase;
25 import ch.elca.el4j.services.remoting.ProtocolSpecificConfiguration;
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 JAX-WS protocol using Spring remoting.
31 * Creating service exporters is not supported because of some restrictions
32 * (see {@link #createExporterBean(RemotingServiceExporter, Class, Object)}.
33 *
34 * This protocol should be used for clients (no servers) that communicate with self-written servers (i.e. Code is
35 * available and should not be generated by wsimport). If the code of one side has to be generated, use {@link Jaxws}.
36 *
37 * @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_jaxws/src/main/java/ch/elca/el4j/services/remoting/protocol/JaxwsSpring.java $
38 *
39 * @author Stefan Wismer (SWI)
40 */
41 public class JaxwsSpring extends AbstractInetSocketAddressWebProtocol {
42
43 /**
44 * {@inheritDoc}
45 */
46 public Object createProxyBean(RemotingProxyFactoryBean proxyBean,
47 Class serviceInterfaceWithContext) {
48
49 StaticApplicationContext appContext = new StaticApplicationContext(m_parentApplicationContext);
50 registerChildApplicationContext(appContext);
51
52 MutablePropertyValues props = new MutablePropertyValues();
53 props.addPropertyValue("serviceInterface", serviceInterfaceWithContext);
54 props.addPropertyValue("wsdlDocumentUrl", generateUrl(proxyBean));
55
56 ProtocolSpecificConfiguration cfg = proxyBean.getProtocolSpecificConfiguration();
57 if (cfg != null && cfg instanceof JaxwsSpringProtocolConfiguration) {
58 JaxwsSpringProtocolConfiguration jaxWsConfig = (JaxwsSpringProtocolConfiguration) cfg;
59
60 props.addPropertyValue("namespaceUri", jaxWsConfig.getNamespaceUri());
61 props.addPropertyValue("serviceName", jaxWsConfig.getServiceName());
62 props.addPropertyValue("portName", jaxWsConfig.getPortName());
63 }
64
65 adaptProxyServiceProperties(props);
66
67 appContext.registerSingleton("jaxWsProxyBeanGen", getProxyObjectType(), props);
68 appContext.refresh();
69
70 return appContext.getBean("jaxWsProxyBeanGen");
71 }
72
73 /**
74 * Do not use exporter from {@link JaxwsSpring}, but {@link Jaxws}, because it requires JDK 6 and
75 * does not support implicit context passing.
76 * {@inheritDoc}
77 */
78 public Object createExporterBean(RemotingServiceExporter exporterBean,
79 Class serviceInterfaceWithContext, Object serviceProxy) {
80 /*StaticApplicationContext appContext = new StaticApplicationContext(m_parentApplicationContext);
81 registerChildApplicationContext(appContext);
82
83 StringBuffer sb = new StringBuffer();
84 sb.append("http://");
85 sb.append(getServiceHost());
86 sb.append(":");
87 sb.append(getServicePort());
88 sb.append("/");
89
90 MutablePropertyValues props = new MutablePropertyValues();
91 props.addPropertyValue("baseAddress", sb.toString());
92 appContext.registerSingleton("jaxWsExporterBeanGen", getExporterObjectType(), props);
93 appContext.refresh();
94
95 return appContext.getBean("jaxWsExporterBeanGen");*/
96 return new Object();
97 }
98
99 /**
100 * {@inheritDoc}
101 */
102 public Class getProxyObjectType() {
103 return JaxWsPortProxyFactoryBean.class;
104 }
105
106 /**
107 * {@inheritDoc}
108 */
109 public Class getExporterObjectType() {
110 //return SimpleJaxWsServiceExporter.class;
111 return Object.class;
112 }
113
114 /**
115 * {@inheritDoc}
116 */
117 public String generateUrl(AbstractRemotingBase remoteBase) {
118 StringBuffer sb = new StringBuffer();
119 sb.append(getServiceProtocol());
120 sb.append("://");
121 sb.append(getServiceHost());
122 sb.append(":");
123 sb.append(getServicePort());
124 sb.append("/");
125 sb.append(getContextPath());
126 sb.append("/");
127 sb.append(remoteBase.getServiceName());
128 sb.append("?wsdl");
129 return sb.toString();
130 }
131
132 /**
133 * Does this protocol handle context passing on its own? Yes.
134 * @return Whether this protocol handles the context (<code>true</code>)
135 */
136 public boolean getProtocolSpecificContextPassing() {
137 return true;
138 }
139
140 /**
141 * Method providing an extension point do adapt the proxy service.
142 * @param props The service properties
143 */
144 protected void adaptProxyServiceProperties(MutablePropertyValues props) {
145 }
146 }