1 package org.objectweb.celtix.systest.ws.rm; 2 3 import javax.xml.namespace.QName ; 4 5 import org.objectweb.celtix.bus.busimpl.BusConfigurationBuilder; 6 import org.objectweb.celtix.bus.jaxws.EndpointImpl; 7 import org.objectweb.celtix.bus.jaxws.ServiceImpl; 8 import org.objectweb.celtix.bus.jaxws.configuration.types.HandlerChainType; 9 import org.objectweb.celtix.bus.jaxws.configuration.types.HandlerType; 10 import org.objectweb.celtix.bus.jaxws.configuration.types.SystemHandlerChainType; 11 import org.objectweb.celtix.bus.ws.addressing.MAPAggregator; 12 import org.objectweb.celtix.bus.ws.addressing.soap.MAPCodec; 13 import org.objectweb.celtix.bus.ws.rm.RMHandler; 14 import org.objectweb.celtix.bus.ws.rm.RMPersistenceHandler; 15 import org.objectweb.celtix.bus.ws.rm.soap.RMSoapHandler; 16 import org.objectweb.celtix.configuration.Configuration; 17 import org.objectweb.celtix.configuration.ConfigurationBuilder; 18 import org.objectweb.celtix.configuration.ConfigurationBuilderFactory; 19 20 public class TestConfigurator { 21 22 private static final String DEFAULT_BUS_ID = "celtix"; 23 24 private ConfigurationBuilder builder; 25 26 public TestConfigurator() { 27 builder = ConfigurationBuilderFactory.getBuilder(); 28 29 } 30 31 public void configureClient(QName serviceName, String portName) { 32 configureClient(DEFAULT_BUS_ID, serviceName, portName); 33 } 34 35 public void configureClient(String busId, QName serviceName, String portName) { 36 Configuration portCfg = createPortConfiguration(busId, serviceName, portName); 37 configureHandlers(portCfg, false); 38 } 39 40 public void configureServer(QName serviceName) { 41 configureServer(DEFAULT_BUS_ID, serviceName); 42 } 43 44 public void configureServer(String busId, QName serviceName) { 45 Configuration endpointCfg = createEndpointConfiguration(busId, serviceName); 46 configureHandlers(endpointCfg, true); 47 } 48 49 private Configuration createEndpointConfiguration(String busId, QName serviceName) { 50 Configuration busCfg = getBusConfiguration(busId); 51 return builder.buildConfiguration(EndpointImpl.ENDPOINT_CONFIGURATION_URI, 52 serviceName.toString(), busCfg); 53 } 54 55 private Configuration createPortConfiguration(String busId, QName serviceName, String portName) { 56 Configuration busCfg = getBusConfiguration(busId); 57 String id = serviceName.toString() + "/" + portName; 58 return builder.buildConfiguration(ServiceImpl.PORT_CONFIGURATION_URI, id, busCfg); 59 } 60 61 private Configuration getBusConfiguration(String busId) { 62 Configuration busCfg = builder.getConfiguration(BusConfigurationBuilder.BUS_CONFIGURATION_URI, busId); 63 if (null == busCfg) { 64 busCfg = builder.buildConfiguration(BusConfigurationBuilder.BUS_CONFIGURATION_URI, busId); 65 } 66 return busCfg; 67 } 68 69 private void configureHandlers(Configuration config, boolean isServer) { 70 SystemHandlerChainType systemHandlers = config.getObject(SystemHandlerChainType.class, 71 "systemHandlerChain"); 72 73 org.objectweb.celtix.bus.jaxws.configuration.types.ObjectFactory factory 74 = new org.objectweb.celtix.bus.jaxws.configuration.types.ObjectFactory(); 75 76 HandlerChainType handlerChain = null; 77 HandlerType handler = null; 78 79 if (null == systemHandlers) { 80 systemHandlers = factory.createSystemHandlerChainType(); 81 82 boolean withRM = true; 83 84 86 handlerChain = factory.createHandlerChainType(); 87 handler = factory.createHandlerType(); 88 handler.setHandlerClass(MAPAggregator.class.getName()); 89 handler.setHandlerName("logical addressing handler"); 90 handlerChain.getHandler().add(handler); 91 if (withRM) { 92 handler = factory.createHandlerType(); 93 handler.setHandlerClass(RMHandler.class.getName()); 94 handler.setHandlerName("logical rm handler"); 95 handlerChain.getHandler().add(handler); 96 } 97 if (!isServer) { 98 handler = factory.createHandlerType(); 99 handler.setHandlerClass(LogicalMessageContextRecorder.class.getName()); 100 handler.setHandlerName("logical message context recorder"); 101 handlerChain.getHandler().add(handler); 102 } 103 104 systemHandlers.setPreLogical(handlerChain); 105 106 108 handlerChain = factory.createHandlerChainType(); 109 if (withRM) { 110 handler = factory.createHandlerType(); 111 handler.setHandlerClass(RMSoapHandler.class.getName()); 112 handler.setHandlerName("protocol rm handler"); 113 handlerChain.getHandler().add(handler); 114 } 115 116 handler = factory.createHandlerType(); 117 handler.setHandlerClass(MAPCodec.class.getName()); 118 handler.setHandlerName("protocol addressing handler"); 119 handlerChain.getHandler().add(handler); 120 121 boolean persist = true; 122 if (persist) { 123 handler = factory.createHandlerType(); 124 handler.setHandlerClass(RMPersistenceHandler.class.getName()); 125 handler.setHandlerName("protocol rm persistence handler"); 126 handlerChain.getHandler().add(handler); 127 } 128 129 systemHandlers.setPostProtocol(handlerChain); 130 131 config.setObject("systemHandlerChain", systemHandlers); 132 } 133 134 handlerChain = config.getObject(HandlerChainType.class, "handlerChain"); 135 if (null == handlerChain && !isServer) { 136 handlerChain = factory.createHandlerChainType(); 137 handler = factory.createHandlerType(); 138 handler.setHandlerClass(SOAPMessageRecorder.class.getName()); 139 handler.setHandlerName("soap message recorder stream handler"); 140 handlerChain.getHandler().add(handler); 141 142 config.setObject("handlerChain", handlerChain); 143 } 144 145 147 builder.buildConfiguration(RMHandler.RM_CONFIGURATION_URI, 148 RMHandler.RM_CONFIGURATION_ID, 149 config); 150 } 151 } 152 | Popular Tags |