1 17 18 package org.apache.sandesha.client; 19 20 21 import org.apache.axis.SimpleChain; 22 import org.apache.axis.configuration.SimpleProvider; 23 import org.apache.axis.description.JavaServiceDesc; 24 import org.apache.axis.handlers.soap.SOAPService; 25 import org.apache.axis.transport.http.SimpleAxisServer; 26 import org.apache.sandesha.Constants; 27 import org.apache.sandesha.util.PropertyLoader; 28 import org.apache.sandesha.ws.rm.providers.RMProvider; 29 30 import java.io.IOException ; 31 import java.net.ServerSocket ; 32 import java.util.ArrayList ; 33 34 35 45 46 public class ClientListener { 47 48 49 public static final int NULL_PORT = -1; 50 private SimpleAxisServer sas; 51 private int listenerPort = NULL_PORT; 52 private boolean started; 53 54 public ClientListener(int aPort) { 55 listenerPort = aPort; 56 } 57 58 59 public synchronized void start() throws IOException { 60 61 if (!isStarted()) { 62 initSimpleAxisServer(); 63 configureClientService(); 64 configureServerSocket(); 65 startSimpleAxisServer(); 66 } 67 } 68 69 70 public void stop() { 71 getSas().stop(); 72 } 73 74 75 protected void initSimpleAxisServer() { 76 setSas(new SimpleAxisServer()); 77 getSas().setMyConfig(new SimpleProvider()); 78 } 79 80 81 protected void configureClientService() { 82 SimpleChain reqHandlers = getListenerRequestChain(); 83 SimpleChain resHandlers = getListenerResponseChain(); 84 RMProvider rmp = new RMProvider(); 85 rmp.setClient(true); 86 SOAPService rmService = new SOAPService(reqHandlers, rmp, resHandlers); 87 JavaServiceDesc desc = new JavaServiceDesc(); 88 rmService.setOption(Constants.ClientProperties.CLASS_NAME, Constants.ClientProperties.RMSERVICE_CLASS); 89 rmService.setOption(Constants.ClientProperties.ALLOWED_METHODS, Constants.ASTERISK); 90 desc.setName(Constants.ClientProperties.RMSERVICE); 91 rmService.setServiceDescription(desc); 92 ((SimpleProvider) getSas().getMyConfig()).deployService(Constants.ClientProperties.RMSERVICE, rmService); 93 } 94 95 protected void configureServerSocket() throws IOException { 96 ServerSocket socket = new ServerSocket (getListenerPort()); 97 getSas().setServerSocket(socket); 98 } 99 100 protected void startSimpleAxisServer() { 101 Thread serverThread = new Thread (getSas()); 102 serverThread.start(); 103 } 104 105 protected SimpleChain getListenerRequestChain() { 106 ArrayList arr = PropertyLoader.getListenerRequestHandlerNames(); 107 return ClientHandlerUtil.getHandlerChain(arr); 108 } 109 110 protected SimpleChain getListenerResponseChain() { 111 ArrayList arr = PropertyLoader.getListenerResponseHandlerNames(); 112 return ClientHandlerUtil.getHandlerChain(arr); 113 } 114 115 protected SimpleAxisServer getSas() { 116 return sas; 117 } 118 119 protected void setSas(SimpleAxisServer aSas) { 120 sas = aSas; 121 } 122 123 protected int getListenerPort() { 124 if (listenerPort == NULL_PORT) { 125 listenerPort = PropertyLoader.getClientSideListenerPort(); 126 } 127 128 return listenerPort; 129 } 130 131 132 protected boolean isStarted() { 133 return started; 134 } 135 } 136 137 | Popular Tags |