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) 2006 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  package ch.elca.el4j.services.remoting.protocol;
18  
19  import java.util.ArrayList;
20  import java.util.List;
21  
22  import javax.xml.bind.JAXBContext;
23  import javax.xml.ws.Service;
24  import javax.xml.ws.handler.Handler;
25  import javax.xml.ws.handler.HandlerResolver;
26  import javax.xml.ws.handler.PortInfo;
27  
28  import org.jvnet.jax_ws_commons.spring.SpringService;
29  
30  import ch.elca.el4j.services.remoting.protocol.jaxws.JaxwsContextHandler;
31  
32  /**
33   * This class is an extension to the default JAX-WS SOAP class and provides the
34   * ability to transfer the implicit context inside the SOAP header using Jaxb
35   * to serialize the parameters and context.
36   *
37   * @svnLink $Revision: 3878 $;$Date: 2009-08-04 15:06:35 +0200 (Di, 04. Aug 2009) $;$Author: swismer $;$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/JaxwsSoapHeaderContextPassing.java $
38   *
39   * @author Stefan Wismer (SWI)
40   */
41  public class JaxwsSoapHeaderContextPassing extends Jaxws {
42  	/**
43  	 * The {@link JAXBContext} instance used to serialize the several
44  	 * Objects in the implicit context.
45  	 */
46  	private JAXBContext m_contextPassingContext = null;
47  	
48  	/** {@inheritDoc} */
49  	@SuppressWarnings("unchecked")
50  	@Override
51  	protected void adaptExporterService(SpringService service) {
52  		super.adaptExporterService(service);
53  		
54  		// If context passing is enabled, add a handler
55  		if (getImplicitContextPassingRegistry() != null) {
56  			// Enable implicit context passing
57  			List<Handler> handlers = new ArrayList<Handler>();
58  			handlers.add(new JaxwsContextHandler(
59  				getImplicitContextPassingRegistry(),
60  				m_contextPassingContext));
61  			service.setHandlers(handlers);
62  		}
63  		
64  	}
65  	
66  	/** {@inheritDoc} */
67  	@Override
68  	protected void adaptProxyService(Service service) {
69  		super.adaptProxyService(service);
70  		
71  		// If context passing is enabled, add a handler
72  		if (getImplicitContextPassingRegistry() != null) {
73  			// Enable implicit context passing
74  			service.setHandlerResolver(new HandlerResolver() {
75  				@SuppressWarnings("unchecked")
76  				public List<Handler> getHandlerChain(PortInfo portInfo) {
77  					List<Handler> list = new ArrayList<Handler>();
78  					list.add(new JaxwsContextHandler(
79  						getImplicitContextPassingRegistry(),
80  						m_contextPassingContext));
81  					return list;
82  				}
83  			});
84  		}
85  	}
86  	
87  	/**
88  	 * Get the {@link JAXBContext} used to serialize the implicit context.
89  	 * @return The used {@link JAXBContext}
90  	 */
91  	public JAXBContext getContextPassingContext() {
92  		return m_contextPassingContext;
93  	}
94  	
95  	/**
96  	 * Set the {@link JAXBContext} used to serialize the implicit context.
97  	 * @param context The {@link JAXBContext} to use
98  	 */
99  	public void setContextPassingContext(JAXBContext context) {
100 		m_contextPassingContext = context;
101 	}
102 }