1 45 package org.exolab.jms.net.http; 46 47 import java.io.IOException ; 48 import java.net.Socket ; 49 import java.security.Principal ; 50 51 import EDU.oswego.cs.dl.util.concurrent.PooledExecutor; 52 53 import org.exolab.jms.common.uuid.UUIDGenerator; 54 import org.exolab.jms.net.connector.Authenticator; 55 import org.exolab.jms.net.connector.ConnectException; 56 import org.exolab.jms.net.connector.ResourceException; 57 import org.exolab.jms.net.connector.SecurityException; 58 import org.exolab.jms.net.multiplexer.Endpoint; 59 import org.exolab.jms.net.multiplexer.MultiplexedManagedConnection; 60 import org.exolab.jms.net.multiplexer.Multiplexer; 61 import org.exolab.jms.net.socket.SocketEndpoint; 62 import org.exolab.jms.net.uri.InvalidURIException; 63 import org.exolab.jms.net.uri.URI; 64 import org.exolab.jms.net.uri.URIHelper; 65 66 67 74 abstract class AbstractHTTPManagedConnection 75 extends MultiplexedManagedConnection { 76 77 80 protected Endpoint _endpoint; 81 82 85 private URI _remoteURI; 86 87 90 private URI _localURI; 91 92 93 100 public AbstractHTTPManagedConnection(Principal principal, 101 HTTPRequestInfo info) 102 throws ResourceException { 103 super(principal); 104 if (info == null) { 105 throw new IllegalArgumentException ("Argument 'info' is null"); 106 } 107 final URI uri = info.getURI(); 108 try { 109 _endpoint = new HTTPEndpoint(info); 110 } catch (IOException exception) { 111 throw new ConnectException("Failed to connect to URI=" 112 + info.getURI(), exception); 113 } 114 _remoteURI = URIHelper.convertHostToAddress(uri); 115 116 try { 117 _localURI = URIHelper.create(uri.getScheme(), null, -1, 118 UUIDGenerator.create()); 119 } catch (InvalidURIException exception) { 120 throw new ResourceException("Failed to generate local URI", 121 exception); 122 } 123 124 } 125 126 136 public AbstractHTTPManagedConnection(URI uri, Socket socket, 137 Authenticator authenticator, 138 PooledExecutor pool) 139 throws ResourceException { 140 super(authenticator, pool); 141 if (uri == null) { 142 throw new IllegalArgumentException ("Argument 'uri' is null"); 143 } 144 if (socket == null) { 145 throw new IllegalArgumentException ("Argument 'socket' is null"); 146 } 147 if (authenticator == null) { 148 throw new IllegalArgumentException ( 149 "Argument 'authenticator' is null"); 150 } 151 String scheme = uri.getScheme(); 152 int localPort = socket.getLocalPort(); 153 154 try { 155 _localURI = URIHelper.create(scheme, uri.getHost(), localPort); 156 } catch (InvalidURIException exception) { 157 throw new ResourceException("Failed to generate local URI", 158 exception); 159 } 160 try { 161 _endpoint = new SocketEndpoint(scheme, socket); 162 } catch (IOException exception) { 163 throw new ResourceException("Failed to create endpoint", exception); 164 } 165 } 166 167 172 public URI getRemoteURI() { 173 return _remoteURI; 174 } 175 176 181 public URI getLocalURI() { 182 return _localURI; 183 } 184 185 191 protected Endpoint createEndpoint() throws IOException { 192 return _endpoint; 193 } 194 195 205 protected Multiplexer createMultiplexer(Endpoint endpoint, 206 Principal principal, 207 PooledExecutor pool) 208 throws IOException , SecurityException { 209 return new HTTPMultiplexer(this, endpoint, _localURI, principal, pool); 210 } 211 212 222 protected Multiplexer createMultiplexer(Endpoint endpoint, 223 Authenticator authenticator, 224 PooledExecutor pool) 225 throws IOException , ResourceException { 226 HTTPMultiplexer result = new HTTPMultiplexer(this, endpoint, 227 authenticator, pool); 228 _remoteURI = result.getClientURI(); 229 return result; 230 } 231 232 } 233 | Popular Tags |