| 1 | | | |
| 2 | | | |
| 3 | | | |
| 4 | | | |
| 5 | | | |
| 6 | | | |
| 7 | | | |
| 8 | | | |
| 9 | | | |
| 10 | | | |
| 11 | | | |
| 12 | | | |
| 13 | | | |
| 14 | | | |
| 15 | | | |
| 16 | | | |
| 17 | | | |
| 18 | | | |
| 19 | | | |
| 20 | | | |
| 21 | | | |
| 22 | | | |
| 23 | | | |
| 24 | | | |
| 25 | | | |
| 26 | | | |
| 27 | | | |
| 28 | | | |
| 29 | | | |
| 30 | | | |
| 31 | | | |
| 32 | | | |
| 33 | | | package org.jcoderz.commons.connector.http; |
| 34 | | | |
| 35 | | | import java.io.ByteArrayInputStream; |
| 36 | | | import java.io.PrintWriter; |
| 37 | | | import java.security.KeyStore; |
| 38 | | | import java.util.HashSet; |
| 39 | | | import java.util.Iterator; |
| 40 | | | import java.util.Set; |
| 41 | | | import java.util.logging.Level; |
| 42 | | | import java.util.logging.Logger; |
| 43 | | | |
| 44 | | | import javax.resource.NotSupportedException; |
| 45 | | | import javax.resource.ResourceException; |
| 46 | | | import javax.resource.spi.ConnectionEvent; |
| 47 | | | import javax.resource.spi.ConnectionEventListener; |
| 48 | | | import javax.resource.spi.ConnectionRequestInfo; |
| 49 | | | import javax.resource.spi.LocalTransaction; |
| 50 | | | import javax.resource.spi.ManagedConnection; |
| 51 | | | import javax.resource.spi.ManagedConnectionMetaData; |
| 52 | | | import javax.security.auth.Subject; |
| 53 | | | import javax.transaction.xa.XAResource; |
| 54 | | | |
| 55 | | | import org.jcoderz.commons.connector.ConnectorConfiguration; |
| 56 | | | import org.jcoderz.commons.connector.http.transport.ConnectorContext; |
| 57 | | | import org.jcoderz.commons.connector.http.transport.HttpClientConnection; |
| 58 | | | import org.jcoderz.commons.connector.http.transport.HttpClientConnectionImpl; |
| 59 | | | import org.jcoderz.commons.connector.http.transport.HttpConnectionException; |
| 60 | | | import org.jcoderz.commons.connector.http.transport.HttpConnectorEventListener; |
| 61 | | | import org.jcoderz.commons.connector.http.transport.HttpRequestResponseHeader; |
| 62 | | | import org.jcoderz.commons.types.Url; |
| 63 | | | import org.jcoderz.commons.util.Constants; |
| 64 | | | |
| 65 | | | |
| 66 | | | |
| 67 | | | |
| 68 | | | |
| 69 | | | |
| 70 | | | |
| 71 | | | |
| 72 | | | |
| 73 | | (1) | public class HttpManagedConnectionImpl |
| 74 | | | implements ManagedConnection |
| 75 | | | { |
| 76 | | | |
| 77 | 0 | | private static final String CLASSNAME |
| 78 | | | = HttpManagedConnectionImpl.class.getName(); |
| 79 | | | |
| 80 | 0 | | private static final Logger logger |
| 81 | | | = Logger.getLogger(CLASSNAME); |
| 82 | | | |
| 83 | 0 | | private boolean mConnectionAssociated = false; |
| 84 | | | |
| 85 | 0 | | private boolean mConnectionOpened = false; |
| 86 | | | |
| 87 | | | |
| 88 | | | private PrintWriter mPrintWriter; |
| 89 | | | |
| 90 | | | |
| 91 | 0 | | private final Set mEventListeners = new HashSet(); |
| 92 | | | |
| 93 | | | private HttpConnectionImpl mConnectionHandle; |
| 94 | | | |
| 95 | | | private final HttpManagedConnectionFactoryImpl mManagedConnectionFactory; |
| 96 | | | |
| 97 | | | |
| 98 | | | private HttpConnectionRequestInfo mConnectionRequestInfo; |
| 99 | | | |
| 100 | | | private HttpClientConnection mConnection; |
| 101 | | | |
| 102 | 0 | | private boolean mPhysicalCloseRequired = false; |
| 103 | | | |
| 104 | | | private Url mUrl; |
| 105 | | | private final ConnectorConfiguration mConfig; |
| 106 | | | |
| 107 | | | private int mConnectTimeout; |
| 108 | | | private int mReadTimeout; |
| 109 | | | private String mKeyAlias; |
| 110 | | | private String mKeyAliasPassword; |
| 111 | 0 | (2) | private KeyStore mKeyStore = null; |
| 112 | 0 | (3) | private KeyStore mTrustStore = null; |
| 113 | | | |
| 114 | | | private HttpConnectorEventListener mHttpEventListener; |
| 115 | | | private ConnectorContext mConnectorContext; |
| 116 | | | private HttpRequestResponseHeader mRequestResponseHeader; |
| 117 | | | |
| 118 | | | |
| 119 | | | |
| 120 | | | |
| 121 | | | @param |
| 122 | | | @param |
| 123 | | | |
| 124 | | | public HttpManagedConnectionImpl ( |
| 125 | | | HttpManagedConnectionFactoryImpl mcf, |
| 126 | | | ConnectionRequestInfo cri) |
| 127 | 0 | | { |
| 128 | 0 | | final String methodName = "Constructor"; |
| 129 | 0 | | if (logger.isLoggable(Level.FINER)) |
| 130 | | | { |
| 131 | 0 | | logger.entering(CLASSNAME, methodName, cri); |
| 132 | | | } |
| 133 | 0 | | mConfig = ConfigurationFactory.getConfiguration(); |
| 134 | | | |
| 135 | 0 | | mManagedConnectionFactory = mcf; |
| 136 | | | |
| 137 | 0 | (4) | mConnectionRequestInfo = (HttpConnectionRequestInfo) cri; |
| 138 | 0 | | mConnectionAssociated = false; |
| 139 | 0 | | mConnectionOpened = false; |
| 140 | 0 | | mConnectionHandle = null; |
| 141 | 0 | | if (mConnectionRequestInfo != null) |
| 142 | | | { |
| 143 | 0 | | configure(mConnectionRequestInfo); |
| 144 | | | } |
| 145 | 0 | | if (logger.isLoggable(Level.FINER)) |
| 146 | | | { |
| 147 | 0 | | logger.exiting(CLASSNAME, methodName); |
| 148 | | | } |
| 149 | 0 | | } |
| 150 | | | |
| 151 | | | |
| 152 | | | |
| 153 | | | |
| 154 | | | |
| 155 | | | |
| 156 | | | |
| 157 | | | |
| 158 | | | |
| 159 | | | |
| 160 | | | |
| 161 | | | |
| 162 | | | |
| 163 | | | |
| 164 | | | |
| 165 | | | |
| 166 | | | |
| 167 | | | |
| 168 | | | |
| 169 | | | |
| 170 | | | |
| 171 | | | |
| 172 | | | {@inheritDoc} |
| 173 | | | public void addConnectionEventListener (ConnectionEventListener listener) |
| 174 | | | { |
| 175 | 0 | | mEventListeners.add(listener); |
| 176 | 0 | | } |
| 177 | | | |
| 178 | | | {@inheritDoc} |
| 179 | | | public void associateConnection (Object connection) |
| 180 | | | { |
| 181 | 0 | | final String methodName = "associateConnection"; |
| 182 | 0 | | if (logger.isLoggable(Level.FINER)) |
| 183 | | | { |
| 184 | 0 | | logger.entering(CLASSNAME, methodName); |
| 185 | | | } |
| 186 | | | |
| 187 | | | |
| 188 | | | |
| 189 | | | |
| 190 | | | |
| 191 | 0 | | if (mConnectionHandle != null) |
| 192 | | | { |
| 193 | 0 | | if (logger.isLoggable(Level.WARNING)) |
| 194 | | | { |
| 195 | 0 | | final String messageText = "connection still have a handle"; |
| 196 | 0 | | logger.warning(messageText); |
| 197 | | | } |
| 198 | 0 | | mConnectionHandle.disassociateManagedConnection(true); |
| 199 | | | } |
| 200 | 0 | | final HttpConnectionImpl usercon = (HttpConnectionImpl) connection; |
| 201 | 0 | | usercon.associateManagedConnection(this); |
| 202 | 0 | | mConnectionHandle = usercon; |
| 203 | 0 | | if (logger.isLoggable(Level.FINER)) |
| 204 | | | { |
| 205 | 0 | | logger.exiting(CLASSNAME, methodName); |
| 206 | | | } |
| 207 | 0 | | } |
| 208 | | | |
| 209 | | | {@inheritDoc} |
| 210 | | | public void cleanup () |
| 211 | | | { |
| 212 | 0 | | final String methodName = "cleanup"; |
| 213 | 0 | | if (logger.isLoggable(Level.FINER)) |
| 214 | | | { |
| 215 | 0 | | logger.entering(CLASSNAME, methodName); |
| 216 | | | } |
| 217 | | | |
| 218 | | | |
| 219 | | | |
| 220 | | | |
| 221 | | | |
| 222 | | | |
| 223 | | | |
| 224 | | | |
| 225 | 0 | | if (mConnectionAssociated) |
| 226 | | | { |
| 227 | 0 | | mConnectionHandle.disassociateManagedConnection(true); |
| 228 | 0 | | mConnectionAssociated = false; |
| 229 | 0 | | mConnectionHandle = null; |
| 230 | | | } |
| 231 | 0 | | if (logger.isLoggable(Level.FINER)) |
| 232 | | | { |
| 233 | 0 | | logger.exiting(CLASSNAME, methodName); |
| 234 | | | } |
| 235 | 0 | | } |
| 236 | | | |
| 237 | | | {@inheritDoc} |
| 238 | | | public void destroy () |
| 239 | | | { |
| 240 | 0 | | final String methodName = "destroy"; |
| 241 | 0 | | if (logger.isLoggable(Level.FINER)) |
| 242 | | | { |
| 243 | 0 | | logger.entering(CLASSNAME, methodName); |
| 244 | | | } |
| 245 | | | |
| 246 | | | |
| 247 | | | |
| 248 | | | |
| 249 | | | |
| 250 | | | |
| 251 | | | |
| 252 | | | |
| 253 | | | |
| 254 | 0 | | if (logger.isLoggable(Level.FINE)) |
| 255 | | | { |
| 256 | 0 | | final String messageText |
| 257 | | | = "destroy PHYSICAL CONNECTION (" + this + ") to " |
| 258 | | | + mConnectionRequestInfo; |
| 259 | 0 | | logger.log(Level.FINE, messageText); |
| 260 | | | } |
| 261 | | | |
| 262 | 0 | | disconnect(); |
| 263 | | | |
| 264 | 0 | | if (logger.isLoggable(Level.FINER)) |
| 265 | | | { |
| 266 | 0 | | logger.exiting(CLASSNAME, methodName); |
| 267 | | | } |
| 268 | 0 | | } |
| 269 | | | |
| 270 | | | {@inheritDoc} |
| 271 | | | public Object getConnection (Subject subject, ConnectionRequestInfo cri) |
| 272 | | | { |
| 273 | 0 | | final String methodName = "getConnection"; |
| 274 | 0 | | if (logger.isLoggable(Level.FINER)) |
| 275 | | | { |
| 276 | 0 | | logger.entering(CLASSNAME, methodName); |
| 277 | | | } |
| 278 | 0 | | mPhysicalCloseRequired = false; |
| 279 | 0 | (5) | mConnectionRequestInfo = (HttpConnectionRequestInfo) cri; |
| 280 | | | |
| 281 | | | |
| 282 | | | |
| 283 | 0 | | if (mConnectionAssociated) |
| 284 | | | { |
| 285 | 0 | | final String errorText |
| 286 | | | = "managed connection already associated to a connection handle"; |
| 287 | 0 | (6) | throw new IllegalStateException(errorText); |
| 288 | | | } |
| 289 | | | |
| 290 | | | |
| 291 | 0 | | if (!mConnectionOpened) |
| 292 | | | { |
| 293 | | | |
| 294 | 0 | | if (logger.isLoggable(Level.FINE)) |
| 295 | | | { |
| 296 | 0 | | final String messageText |
| 297 | | | = "establishing NEW PHYSICAL CONNECTION (" + this + ") to " |
| 298 | | | + mConnectionRequestInfo; |
| 299 | 0 | | logger.fine(messageText); |
| 300 | | | } |
| 301 | | | |
| 302 | 0 | | if (mConnectionRequestInfo != null) |
| 303 | | | { |
| 304 | 0 | | configure(mConnectionRequestInfo); |
| 305 | | | } |
| 306 | | | |
| 307 | | | } |
| 308 | | | else |
| 309 | | | { |
| 310 | | | |
| 311 | 0 | | if (logger.isLoggable(Level.FINE)) |
| 312 | | | { |
| 313 | 0 | | final String messageText |
| 314 | | | = "reusing PHYSICAL CONNECTION (" + this + ") to " |
| 315 | | | + mConnectionRequestInfo; |
| 316 | 0 | | logger.fine(messageText); |
| 317 | | | } |
| 318 | | | |
| 319 | | | } |
| 320 | 0 | | mConnectionAssociated = true; |
| 321 | 0 | | mConnectionHandle = new HttpConnectionImpl(this); |
| 322 | 0 | | return mConnectionHandle; |
| 323 | | | } |
| 324 | | | |
| 325 | | | {@inheritDoc} |
| 326 | | | public LocalTransaction getLocalTransaction () |
| 327 | | | throws ResourceException |
| 328 | | | { |
| 329 | 0 | | final String messageText = "Local transaction not supported"; |
| 330 | 0 | | throw new NotSupportedException(messageText); |
| 331 | | | } |
| 332 | | | |
| 333 | | | {@inheritDoc} |
| 334 | | | public PrintWriter getLogWriter () |
| 335 | | | { |
| 336 | 0 | | return mPrintWriter; |
| 337 | | | } |
| 338 | | | |
| 339 | | | {@inheritDoc} |
| 340 | | | public void setLogWriter (PrintWriter out) |
| 341 | | | { |
| 342 | 0 | | mPrintWriter = out; |
| 343 | 0 | | } |
| 344 | | | |
| 345 | | | {@inheritDoc} |
| 346 | | | public ManagedConnectionMetaData getMetaData () |
| 347 | | | { |
| 348 | | | |
| 349 | | | |
| 350 | 0 | | final HttpManagedConnectionMetaData managedConnectionMetaData |
| 351 | | | = new HttpManagedConnectionMetaData(this); |
| 352 | 0 | (7) | return managedConnectionMetaData; |
| 353 | | | } |
| 354 | | | |
| 355 | | | {@inheritDoc} |
| 356 | | | public XAResource getXAResource () |
| 357 | | | throws ResourceException |
| 358 | | | { |
| 359 | 0 | | final String messageText = "XA transaction not supported"; |
| 360 | 0 | | throw new NotSupportedException(messageText); |
| 361 | | | } |
| 362 | | | |
| 363 | | | {@inheritDoc} |
| 364 | | | public void removeConnectionEventListener (ConnectionEventListener listener) |
| 365 | | | { |
| 366 | 0 | | mEventListeners.remove(listener); |
| 367 | 0 | | } |
| 368 | | | |
| 369 | | | |
| 370 | | | |
| 371 | | | |
| 372 | | | |
| 373 | | | |
| 374 | | | |
| 375 | | | |
| 376 | | | |
| 377 | | | |
| 378 | | | |
| 379 | | | |
| 380 | | | |
| 381 | | | private void disconnect () |
| 382 | | | { |
| 383 | 0 | | final String methodName = "disconnect"; |
| 384 | 0 | | if (logger.isLoggable(Level.FINER)) |
| 385 | | | { |
| 386 | 0 | | logger.entering(CLASSNAME, methodName); |
| 387 | | | } |
| 388 | | | |
| 389 | | | |
| 390 | | | |
| 391 | | | |
| 392 | | | |
| 393 | 0 | | if (!mConnectionOpened && mPhysicalCloseRequired) |
| 394 | | | { |
| 395 | 0 | | if (logger.isLoggable(Level.FINE)) |
| 396 | | | { |
| 397 | 0 | | final String messageText = "already disconnected (" + this + ")" |
| 398 | | | + " due to \'Connection:Close\' in response"; |
| 399 | 0 | | logger.fine(messageText); |
| 400 | 0 | | } |
| 401 | | | } |
| 402 | | | else |
| 403 | | | { |
| 404 | | | |
| 405 | 0 | | mConnection.closeConnection(); |
| 406 | 0 | | mConnectionOpened = false; |
| 407 | | | } |
| 408 | | | |
| 409 | 0 | | if (logger.isLoggable(Level.FINER)) |
| 410 | | | { |
| 411 | 0 | | logger.exiting(CLASSNAME, methodName); |
| 412 | | | } |
| 413 | 0 | | } |
| 414 | | | |
| 415 | | | |
| 416 | | | |
| 417 | | | |
| 418 | | | {@link |
| 419 | | | } |
| 420 | | | |
| 421 | | | {@link |
| 422 | | | } |
| 423 | | | |
| 424 | | | {@link } |
| 425 | | | |
| 426 | | | |
| 427 | | | @param |
| 428 | | | |
| 429 | | | private final void configure (HttpConnectionRequestInfo cri) |
| 430 | | | { |
| 431 | 0 | | final String methodName = "configure"; |
| 432 | 0 | | if (logger.isLoggable(Level.FINER)) |
| 433 | | | { |
| 434 | 0 | | logger.entering(CLASSNAME, methodName); |
| 435 | | | } |
| 436 | | | |
| 437 | | | String messageText; |
| 438 | | | String errorText; |
| 439 | | | |
| 440 | 0 | | if (mConnectionOpened) |
| 441 | | | { |
| 442 | 0 | (8) | messageText = "Unable to configure an already opened connection"; |
| 443 | | | |
| 444 | 0 | | if (logger.isLoggable(Level.WARNING)) |
| 445 | | | { |
| 446 | 0 | | logger.warning(messageText); |
| 447 | | | } |
| 448 | | | |
| 449 | | | } |
| 450 | | | else |
| 451 | | | { |
| 452 | 0 | | if (cri.getConnectionSpec() != null) |
| 453 | | | { |
| 454 | | | |
| 455 | | | |
| 456 | 0 | | mUrl = cri.getConnectionSpec().getUrl(); |
| 457 | | | |
| 458 | 0 | | mConnectTimeout = mConfig.getConnectTimeoutInMilliSeconds(); |
| 459 | 0 | | mReadTimeout = mConfig.getReadTimeoutInMilliSeconds(); |
| 460 | | | |
| 461 | 0 | | mKeyAlias = mConfig.getSslKeyAlias(); |
| 462 | 0 | | mKeyAliasPassword = mConfig.getSslKeyAliasPassword(); |
| 463 | | (9) | |
| 464 | | (10) | |
| 465 | | | |
| 466 | 0 | | if (mConnection == null) |
| 467 | | | { |
| 468 | | | |
| 469 | 0 | | if (logger.isLoggable(Level.FINER)) |
| 470 | | | { |
| 471 | 0 | | messageText = "creating new HTTPConnection"; |
| 472 | 0 | | logger.log(Level.FINER, messageText); |
| 473 | | | } |
| 474 | | | |
| 475 | 0 | | mConnection = new HttpClientConnectionImpl(); |
| 476 | | | } |
| 477 | | | |
| 478 | 0 | | mConnection.initSsl( |
| 479 | | | mKeyStore, mTrustStore, mKeyAlias, mKeyAliasPassword); |
| 480 | 0 | | mConnection.establishConnection( |
| 481 | | | mUrl.toString(), mConnectTimeout, mReadTimeout); |
| 482 | | | } |
| 483 | | | else |
| 484 | | | { |
| 485 | 0 | | errorText = "connection specification is not set"; |
| 486 | 0 | (11) | throw new IllegalStateException(errorText); |
| 487 | | | } |
| 488 | | | } |
| 489 | 0 | | if (logger.isLoggable(Level.FINER)) |
| 490 | | | { |
| 491 | 0 | | logger.exiting(CLASSNAME, methodName); |
| 492 | | | } |
| 493 | 0 | | } |
| 494 | | | |
| 495 | | | |
| 496 | | | |
| 497 | | | {@link |
| 498 | | | } |
| 499 | | | |
| 500 | | | |
| 501 | | | @param |
| 502 | | | @return |
| 503 | | | @throws |
| 504 | | | |
| 505 | | | public byte[] sendAndReceive (byte[] message) |
| 506 | | | throws HttpConnectionException |
| 507 | | | { |
| 508 | 0 | | final String methodName = "sendAndReceive(byte[])"; |
| 509 | 0 | | if (logger.isLoggable(Level.FINER)) |
| 510 | | | { |
| 511 | 0 | | logger.entering(CLASSNAME, methodName); |
| 512 | | | } |
| 513 | | | |
| 514 | | | |
| 515 | 0 | | mConnection.setEventListener(mHttpEventListener, mConnectorContext); |
| 516 | | | |
| 517 | | | |
| 518 | | | |
| 519 | 0 | | getRequestResponseHeader().addRequestHeader("Content-Length", |
| 520 | | | String.valueOf(message.length)); |
| 521 | 0 | | getRequestResponseHeader().addRequestHeader("Connection", |
| 522 | | | "Keep-Alive"); |
| 523 | | | |
| 524 | | | |
| 525 | 0 | | mConnection.setRequestResponseHeader(getRequestResponseHeader()); |
| 526 | | | |
| 527 | | | |
| 528 | 0 | | mConnection.setRequestBody(new ByteArrayInputStream(message)); |
| 529 | | | |
| 530 | 0 | | mConnectionOpened = true; |
| 531 | | | |
| 532 | | | |
| 533 | 0 | | mConnection.execute(); |
| 534 | | | |
| 535 | | | |
| 536 | 0 | | final byte[] responseBytes = mConnection.getResponseBody(); |
| 537 | | | |
| 538 | 0 | | if (isCloseConnectionRequired()) |
| 539 | | | { |
| 540 | 0 | | mPhysicalCloseRequired = true; |
| 541 | | | } |
| 542 | | | |
| 543 | 0 | | mConnection.releaseConnection(); |
| 544 | 0 | | if (logger.isLoggable(Level.FINER)) |
| 545 | | | { |
| 546 | 0 | | logger.exiting(CLASSNAME, methodName); |
| 547 | | | } |
| 548 | 0 | | return responseBytes; |
| 549 | | | } |
| 550 | | | |
| 551 | | | |
| 552 | | | |
| 553 | | | |
| 554 | | | @param |
| 555 | | | |
| 556 | | | public void setRequestResponseHeader (HttpRequestResponseHeader header) |
| 557 | | | { |
| 558 | 0 | | mRequestResponseHeader = header; |
| 559 | 0 | | } |
| 560 | | | |
| 561 | | | |
| 562 | | | |
| 563 | | | |
| 564 | | | |
| 565 | | | @param |
| 566 | | | @param |
| 567 | | | |
| 568 | | | public void setEventListener (HttpConnectorEventListener listener, |
| 569 | | | ConnectorContext context) |
| 570 | | | { |
| 571 | 0 | | mHttpEventListener = listener; |
| 572 | 0 | | mConnectorContext = context; |
| 573 | 0 | | } |
| 574 | | | |
| 575 | | | |
| 576 | | | |
| 577 | | | {@link } |
| 578 | | | |
| 579 | | | |
| 580 | | | |
| 581 | | | @param |
| 582 | | | @throws |
| 583 | | | |
| 584 | | | |
| 585 | | | void disassociateConnection (HttpConnectionImpl conn) |
| 586 | | | throws IllegalStateException |
| 587 | | | { |
| 588 | 0 | | final String methodName = "disassociateConnection"; |
| 589 | 0 | | if (logger.isLoggable(Level.FINER)) |
| 590 | | | { |
| 591 | 0 | | logger.entering(CLASSNAME, methodName); |
| 592 | | | } |
| 593 | | | |
| 594 | 0 | | if (conn != mConnectionHandle) |
| 595 | | | { |
| 596 | 0 | | final String errorText = "Connection handle was not created by " |
| 597 | | | + "THIS HttpManagedConnection " + conn; |
| 598 | 0 | | final IllegalStateException ise = new IllegalStateException(errorText); |
| 599 | | | |
| 600 | 0 | | if (logger.isLoggable(Level.FINE)) |
| 601 | | | { |
| 602 | 0 | | logger.log(Level.FINE, errorText); |
| 603 | | | } |
| 604 | 0 | | if (logger.isLoggable(Level.FINER)) |
| 605 | | | { |
| 606 | 0 | | logger.throwing(CLASSNAME, methodName, ise); |
| 607 | | | } |
| 608 | | | |
| 609 | 0 | | throw ise; |
| 610 | | | } |
| 611 | 0 | | mConnectionAssociated = false; |
| 612 | 0 | | mConnectionHandle = null; |
| 613 | 0 | | if (mPhysicalCloseRequired) |
| 614 | | | { |
| 615 | 0 | | disconnect(); |
| 616 | | | } |
| 617 | | | else |
| 618 | | | { |
| 619 | 0 | | mConnection.releaseConnection(); |
| 620 | | | } |
| 621 | | | |
| 622 | 0 | | if (logger.isLoggable(Level.FINER)) |
| 623 | | | { |
| 624 | 0 | | logger.exiting(CLASSNAME, methodName); |
| 625 | | | } |
| 626 | 0 | | } |
| 627 | | | |
| 628 | | | |
| 629 | | | |
| 630 | | | |
| 631 | | | |
| 632 | | | @return |
| 633 | | | |
| 634 | | | |
| 635 | | | ConnectionRequestInfo getConnectionRequestInfo () |
| 636 | | | { |
| 637 | 0 | | return mConnectionRequestInfo; |
| 638 | | | } |
| 639 | | | |
| 640 | | | |
| 641 | | | |
| 642 | | | |
| 643 | | | |
| 644 | | | |
| 645 | | | |
| 646 | | | @param |
| 647 | | | |
| 648 | | | void notifyAboutConnectionClosed ( |
| 649 | | | HttpConnectionImpl connectionHandle) |
| 650 | | | { |
| 651 | 0 | | final String methodName = "notifyAboutConnectionClosed"; |
| 652 | 0 | | if (logger.isLoggable(Level.FINER)) |
| 653 | | | { |
| 654 | 0 | | logger.entering(CLASSNAME, methodName); |
| 655 | | | } |
| 656 | | | |
| 657 | 0 | | if (mConnectionAssociated) |
| 658 | | | { |
| 659 | 0 | | if (logger.isLoggable(Level.WARNING)) |
| 660 | | | { |
| 661 | 0 | | final String messageText |
| 662 | | | = "HttpManagedConnection SHOULD have disassociated before"; |
| 663 | 0 | | logger.warning(messageText); |
| 664 | | | } |
| 665 | | | |
| 666 | 0 | | mConnectionAssociated = false; |
| 667 | 0 | | mConnectionHandle = null; |
| 668 | | | } |
| 669 | 0 | | final ConnectionEvent ce = new ConnectionEvent( |
| 670 | | | this, ConnectionEvent.CONNECTION_CLOSED); |
| 671 | 0 | | ce.setConnectionHandle(connectionHandle); |
| 672 | 0 | | final Iterator it = mEventListeners.iterator(); |
| 673 | 0 | | while (it.hasNext()) |
| 674 | | | { |
| 675 | 0 | | final ConnectionEventListener listener |
| 676 | | | = (ConnectionEventListener) it.next(); |
| 677 | 0 | | listener.connectionClosed(ce); |
| 678 | 0 | | } |
| 679 | 0 | | if (logger.isLoggable(Level.FINER)) |
| 680 | | | { |
| 681 | 0 | | logger.exiting(CLASSNAME, methodName); |
| 682 | | | } |
| 683 | 0 | | } |
| 684 | | | |
| 685 | | | |
| 686 | | | |
| 687 | | | |
| 688 | | | |
| 689 | | | |
| 690 | | | |
| 691 | | | |
| 692 | | | |
| 693 | | | |
| 694 | | | |
| 695 | | | |
| 696 | | | |
| 697 | | | |
| 698 | | | @param |
| 699 | | | @param |
| 700 | | | |
| 701 | | | |
| 702 | | | void notifyAboutConnectionErrorOccurred ( |
| 703 | | | Exception e, |
| 704 | | | HttpConnectionImpl connectionHandle) |
| 705 | | | { |
| 706 | 0 | | final String methodName = "notifyAboutConnectionErrorOccurred"; |
| 707 | 0 | | if (logger.isLoggable(Level.FINER)) |
| 708 | | | { |
| 709 | 0 | | logger.entering(CLASSNAME, methodName); |
| 710 | | | } |
| 711 | | | |
| 712 | 0 | | if (mConnectionAssociated) |
| 713 | | | { |
| 714 | 0 | | if (logger.isLoggable(Level.WARNING)) |
| 715 | | | { |
| 716 | 0 | | final String messageText |
| 717 | | | = "HttpManagedConnection SHOULD have disassociated before"; |
| 718 | 0 | | logger.warning(messageText); |
| 719 | | | } |
| 720 | | | } |
| 721 | 0 | | final ConnectionEvent ce = new ConnectionEvent( |
| 722 | | | this, ConnectionEvent.CONNECTION_ERROR_OCCURRED, e); |
| 723 | 0 | | if (connectionHandle != null) |
| 724 | | | { |
| 725 | 0 | | ce.setConnectionHandle(connectionHandle); |
| 726 | | | } |
| 727 | | | |
| 728 | 0 | | final Iterator it = mEventListeners.iterator(); |
| 729 | 0 | | while (it.hasNext()) |
| 730 | | | { |
| 731 | 0 | | final ConnectionEventListener listener |
| 732 | | | = (ConnectionEventListener) it.next(); |
| 733 | 0 | | listener.connectionErrorOccurred(ce); |
| 734 | 0 | | } |
| 735 | 0 | | if (logger.isLoggable(Level.FINER)) |
| 736 | | | { |
| 737 | 0 | | logger.exiting(CLASSNAME, methodName); |
| 738 | | | } |
| 739 | 0 | | } |
| 740 | | | |
| 741 | | | |
| 742 | | | |
| 743 | | | |
| 744 | | | @return |
| 745 | | | |
| 746 | | | boolean isOpen () |
| 747 | | | { |
| 748 | 0 | | return mConnectionOpened; |
| 749 | | | } |
| 750 | | | |
| 751 | | | |
| 752 | | | |
| 753 | | | |
| 754 | | | private boolean isCloseConnectionRequired () |
| 755 | | | { |
| 756 | 0 | | boolean result = false; |
| 757 | 0 | | final String connectionValue |
| 758 | | | = mConnection.getResponseHeader("Connection"); |
| 759 | 0 | (12) | if (connectionValue != null |
| 760 | | | && connectionValue.toLowerCase( |
| 761 | | | Constants.SYSTEM_LOCALE).equals("close")) |
| 762 | | | { |
| 763 | 0 | | logger.fine("\'Connection\' attribute in response header is \'" |
| 764 | | | + connectionValue |
| 765 | | | + "\' physical connection will be closed"); |
| 766 | 0 | | result = true; |
| 767 | | | } |
| 768 | 0 | | return result; |
| 769 | | | } |
| 770 | | | |
| 771 | | | protected Url getUrl () |
| 772 | | | { |
| 773 | 0 | | return mUrl; |
| 774 | | | } |
| 775 | | | |
| 776 | | | |
| 777 | | | |
| 778 | | | |
| 779 | | | @return |
| 780 | | | |
| 781 | | | public HttpManagedConnectionFactoryImpl getManagedConnectionFactory () |
| 782 | | | { |
| 783 | 0 | | return mManagedConnectionFactory; |
| 784 | | | } |
| 785 | | | |
| 786 | | | private HttpRequestResponseHeader getRequestResponseHeader () |
| 787 | | | { |
| 788 | 0 | | if (mRequestResponseHeader == null) |
| 789 | | | { |
| 790 | 0 | | mRequestResponseHeader = new HttpRequestResponseHeader(); |
| 791 | | | } |
| 792 | 0 | | return mRequestResponseHeader; |
| 793 | | | } |
| 794 | | | |
| 795 | | | |
| 796 | | | |
| 797 | | | |
| 798 | | | @return |
| 799 | | | |
| 800 | | | public String toString () |
| 801 | | | { |
| 802 | 0 | | final String result |
| 803 | | | = "HttpManagedConnectionImpl hashCode()=" + hashCode(); |
| 804 | 0 | (13) | return result; |
| 805 | | | } |
| 806 | | | } |