1 25 package org.objectweb.joram.mom.proxies.soap; 26 27 import java.util.*; 28 29 import org.objectweb.joram.shared.client.*; 30 import org.objectweb.joram.shared.excepts.*; 31 import org.objectweb.joram.mom.proxies.*; 32 import org.objectweb.joram.mom.notifications.*; 33 34 import fr.dyade.aaa.agent.AgentId; 35 import fr.dyade.aaa.agent.AgentServer; 36 import fr.dyade.aaa.agent.Channel; 37 import fr.dyade.aaa.util.Queue; 38 39 import org.objectweb.util.monolog.api.BasicLevel; 40 import org.objectweb.joram.shared.JoramTracing; 41 42 48 public class SoapProxyService { 49 50 private Hashtable connections; 51 52 61 public void start(int serverId, String serverName) throws Exception { 62 String [] args = {"" + serverId, serverName}; 63 AgentServer.init(args); 64 AgentServer.start(); 65 66 connections = new Hashtable(); 67 68 if (JoramTracing.dbgProxy.isLoggable(BasicLevel.DEBUG)) 69 JoramTracing.dbgProxy.log(BasicLevel.DEBUG, "SoapProxyService started."); 70 } 71 72 82 public int setConnection(String userName, 83 String userPassword, 84 int heartBeat) throws Exception { 85 if (JoramTracing.dbgProxy.isLoggable(BasicLevel.DEBUG)) 86 JoramTracing.dbgProxy.log( 87 BasicLevel.DEBUG, "SoapProxyService.setConnection(" + 88 userName + ',' + 89 userPassword + ',' + 90 heartBeat + ')'); 91 92 GetProxyIdNot gpin = new GetProxyIdNot(userName, userPassword, null); 93 AgentId proxyId; 94 gpin.invoke(new AgentId(AgentServer.getServerId(), 95 AgentServer.getServerId(), 96 AgentId.JoramAdminStamp)); 97 proxyId = gpin.getProxyId(); 98 99 OpenConnectionNot ocn = new OpenConnectionNot(false, heartBeat); 100 ocn.invoke(proxyId); 101 102 StandardConnectionContext cc = 103 (StandardConnectionContext) ocn.getConnectionContext(); 104 ProxyConnectionContext pcc = 105 new ProxyConnectionContext(proxyId, (Queue)cc.getQueue()); 106 connections.put(new ConnectionKey(userName, cc.getKey()), pcc); 107 108 return cc.getKey(); 109 } 110 111 121 public void send(String name, int cnxId, java.util.Hashtable h) throws Exception { 122 if (JoramTracing.dbgProxy.isLoggable(BasicLevel.DEBUG)) 123 JoramTracing.dbgProxy.log( 124 BasicLevel.DEBUG, "SoapProxyService.send(" + 125 name + ',' + cnxId + ',' + h + ')'); 126 127 AbstractJmsRequest request = (AbstractJmsRequest) AbstractJmsMessage.soapDecode(h); 128 129 if (JoramTracing.dbgProxy.isLoggable(BasicLevel.DEBUG)) 130 JoramTracing.dbgProxy.log(BasicLevel.DEBUG, "--- " + this 131 + " passes request " + request + " with id " 132 + request.getRequestId() + " to proxy's cnx " 133 + cnxId); 134 135 ProxyConnectionContext ctx = 136 (ProxyConnectionContext) connections.get(new ConnectionKey(name, cnxId)); 137 if (ctx == null) { 138 throw new StateException("Connection " + name + ':' + cnxId + " closed."); 139 } else { 140 ConnectionManager.sendToProxy(ctx.proxyId, cnxId, request, request); 141 } 142 } 143 144 153 public java.util.Hashtable getReply(String name, int cnxId) throws Exception  154 { 155 ConnectionKey ckey = new ConnectionKey(name, cnxId); 156 ProxyConnectionContext ctx = 157 (ProxyConnectionContext) connections.get(ckey); 158 if (ctx == null) { 159 throw new StateException("Connection " + name + ':' + cnxId + " closed."); 160 } else { 161 Object obj = ctx.replyQueue.get(); 162 if (obj instanceof Exception ) { 163 connections.remove(ckey); 164 throw (Exception )obj; 165 } else { 166 AbstractJmsReply reply = (AbstractJmsReply) obj; 167 ctx.replyQueue.pop(); 168 if (reply instanceof CnxCloseReply) { 169 connections.remove(ckey); 170 } 171 return reply.soapCode(); 172 } 173 } 174 } 175 176 static class ConnectionKey { 177 private String userName; 178 private int key; 179 180 public ConnectionKey(String userName, int key) { 181 this.userName = userName; 182 this.key = key; 183 } 184 185 public int hashCode() { 186 return userName.hashCode() + key; 187 } 188 189 public boolean equals(Object obj) { 190 if (obj instanceof ConnectionKey) { 191 ConnectionKey ck = (ConnectionKey)obj; 192 return (ck.userName.equals(userName) && 193 ck.key == key); 194 } 195 return false; 196 } 197 } 198 199 static class ProxyConnectionContext { 200 AgentId proxyId; 201 Queue replyQueue; 202 203 ProxyConnectionContext(AgentId proxyId, 204 Queue replyQueue) { 205 this.proxyId = proxyId; 206 this.replyQueue = replyQueue; 207 } 208 } 209 } 210 | Popular Tags |