001: package org.objectweb.celtix.systest.ws.rm;
002:
003: import javax.xml.namespace.QName;
004:
005: import org.objectweb.celtix.bus.busimpl.BusConfigurationBuilder;
006: import org.objectweb.celtix.bus.jaxws.EndpointImpl;
007: import org.objectweb.celtix.bus.jaxws.ServiceImpl;
008: import org.objectweb.celtix.bus.jaxws.configuration.types.HandlerChainType;
009: import org.objectweb.celtix.bus.jaxws.configuration.types.HandlerType;
010: import org.objectweb.celtix.bus.jaxws.configuration.types.SystemHandlerChainType;
011: import org.objectweb.celtix.bus.ws.addressing.MAPAggregator;
012: import org.objectweb.celtix.bus.ws.addressing.soap.MAPCodec;
013: import org.objectweb.celtix.bus.ws.rm.RMHandler;
014: import org.objectweb.celtix.bus.ws.rm.RMPersistenceHandler;
015: import org.objectweb.celtix.bus.ws.rm.soap.RMSoapHandler;
016: import org.objectweb.celtix.configuration.Configuration;
017: import org.objectweb.celtix.configuration.ConfigurationBuilder;
018: import org.objectweb.celtix.configuration.ConfigurationBuilderFactory;
019:
020: public class TestConfigurator {
021:
022: private static final String DEFAULT_BUS_ID = "celtix";
023:
024: private ConfigurationBuilder builder;
025:
026: public TestConfigurator() {
027: builder = ConfigurationBuilderFactory.getBuilder();
028:
029: }
030:
031: public void configureClient(QName serviceName, String portName) {
032: configureClient(DEFAULT_BUS_ID, serviceName, portName);
033: }
034:
035: public void configureClient(String busId, QName serviceName,
036: String portName) {
037: Configuration portCfg = createPortConfiguration(busId,
038: serviceName, portName);
039: configureHandlers(portCfg, false);
040: }
041:
042: public void configureServer(QName serviceName) {
043: configureServer(DEFAULT_BUS_ID, serviceName);
044: }
045:
046: public void configureServer(String busId, QName serviceName) {
047: Configuration endpointCfg = createEndpointConfiguration(busId,
048: serviceName);
049: configureHandlers(endpointCfg, true);
050: }
051:
052: private Configuration createEndpointConfiguration(String busId,
053: QName serviceName) {
054: Configuration busCfg = getBusConfiguration(busId);
055: return builder.buildConfiguration(
056: EndpointImpl.ENDPOINT_CONFIGURATION_URI, serviceName
057: .toString(), busCfg);
058: }
059:
060: private Configuration createPortConfiguration(String busId,
061: QName serviceName, String portName) {
062: Configuration busCfg = getBusConfiguration(busId);
063: String id = serviceName.toString() + "/" + portName;
064: return builder.buildConfiguration(
065: ServiceImpl.PORT_CONFIGURATION_URI, id, busCfg);
066: }
067:
068: private Configuration getBusConfiguration(String busId) {
069: Configuration busCfg = builder.getConfiguration(
070: BusConfigurationBuilder.BUS_CONFIGURATION_URI, busId);
071: if (null == busCfg) {
072: busCfg = builder.buildConfiguration(
073: BusConfigurationBuilder.BUS_CONFIGURATION_URI,
074: busId);
075: }
076: return busCfg;
077: }
078:
079: private void configureHandlers(Configuration config,
080: boolean isServer) {
081: SystemHandlerChainType systemHandlers = config.getObject(
082: SystemHandlerChainType.class, "systemHandlerChain");
083:
084: org.objectweb.celtix.bus.jaxws.configuration.types.ObjectFactory factory = new org.objectweb.celtix.bus.jaxws.configuration.types.ObjectFactory();
085:
086: HandlerChainType handlerChain = null;
087: HandlerType handler = null;
088:
089: if (null == systemHandlers) {
090: systemHandlers = factory.createSystemHandlerChainType();
091:
092: boolean withRM = true;
093:
094: // pre-logical
095:
096: handlerChain = factory.createHandlerChainType();
097: handler = factory.createHandlerType();
098: handler.setHandlerClass(MAPAggregator.class.getName());
099: handler.setHandlerName("logical addressing handler");
100: handlerChain.getHandler().add(handler);
101: if (withRM) {
102: handler = factory.createHandlerType();
103: handler.setHandlerClass(RMHandler.class.getName());
104: handler.setHandlerName("logical rm handler");
105: handlerChain.getHandler().add(handler);
106: }
107: if (!isServer) {
108: handler = factory.createHandlerType();
109: handler
110: .setHandlerClass(LogicalMessageContextRecorder.class
111: .getName());
112: handler
113: .setHandlerName("logical message context recorder");
114: handlerChain.getHandler().add(handler);
115: }
116:
117: systemHandlers.setPreLogical(handlerChain);
118:
119: // post-protocol
120:
121: handlerChain = factory.createHandlerChainType();
122: if (withRM) {
123: handler = factory.createHandlerType();
124: handler.setHandlerClass(RMSoapHandler.class.getName());
125: handler.setHandlerName("protocol rm handler");
126: handlerChain.getHandler().add(handler);
127: }
128:
129: handler = factory.createHandlerType();
130: handler.setHandlerClass(MAPCodec.class.getName());
131: handler.setHandlerName("protocol addressing handler");
132: handlerChain.getHandler().add(handler);
133:
134: boolean persist = true;
135: if (persist) {
136: handler = factory.createHandlerType();
137: handler.setHandlerClass(RMPersistenceHandler.class
138: .getName());
139: handler
140: .setHandlerName("protocol rm persistence handler");
141: handlerChain.getHandler().add(handler);
142: }
143:
144: systemHandlers.setPostProtocol(handlerChain);
145:
146: config.setObject("systemHandlerChain", systemHandlers);
147: }
148:
149: handlerChain = config.getObject(HandlerChainType.class,
150: "handlerChain");
151: if (null == handlerChain && !isServer) {
152: handlerChain = factory.createHandlerChainType();
153: handler = factory.createHandlerType();
154: handler
155: .setHandlerClass(SOAPMessageRecorder.class
156: .getName());
157: handler
158: .setHandlerName("soap message recorder stream handler");
159: handlerChain.getHandler().add(handler);
160:
161: config.setObject("handlerChain", handlerChain);
162: }
163:
164: // create rm handler configuration
165:
166: builder.buildConfiguration(RMHandler.RM_CONFIGURATION_URI,
167: RMHandler.RM_CONFIGURATION_ID, config);
168: }
169: }
|