| | |
| | | * CDDL HEADER END |
| | | * |
| | | * |
| | | * Portions Copyright 2013-2015 ForgeRock AS |
| | | * Copyright 2013-2015 ForgeRock AS |
| | | */ |
| | | package org.opends.server.protocols.http; |
| | | |
| | |
| | | * connection that will be accepted by an instance of the HTTP connection |
| | | * handler. |
| | | */ |
| | | final class HTTPClientConnection extends ClientConnection implements |
| | | HTTPRequestInfo |
| | | final class HTTPClientConnection extends ClientConnection implements HTTPRequestInfo |
| | | { |
| | | |
| | | // TODO JNR Confirm with Matt that persistent searches are inapplicable to |
| | | // Rest2LDAP. |
| | | // TODO JNR Confirm with Matt that persistent searches are inapplicable to Rest2LDAP. |
| | | // TODO JNR Should I override getIdleTime()? |
| | | |
| | | /** |
| | |
| | | |
| | | final SearchResultHandler entryHandler; |
| | | |
| | | public SearchOperationWithPromise(Operation operation, LdapPromiseImpl<Result> promise, |
| | | SearchResultHandler entryHandler) |
| | | public SearchOperationWithPromise( |
| | | Operation operation, LdapPromiseImpl<Result> promise, SearchResultHandler entryHandler) |
| | | { |
| | | super(operation, promise); |
| | | this.entryHandler = entryHandler; |
| | |
| | | * Official servlet property giving access to the SSF (Security Strength |
| | | * Factor) used to encrypt the current connection. |
| | | */ |
| | | private static final String SERVLET_SSF_CONSTANT = |
| | | "javax.servlet.request.key_size"; |
| | | private static final String SERVLET_SSF_CONSTANT = "javax.servlet.request.key_size"; |
| | | |
| | | /** |
| | | * Indicates whether the Directory Server believes this connection to be valid |
| | |
| | | * @param request |
| | | * represents this client connection. |
| | | */ |
| | | public HTTPClientConnection(HTTPConnectionHandler connectionHandler, |
| | | HttpServletRequest request) |
| | | public HTTPClientConnection(HTTPConnectionHandler connectionHandler, HttpServletRequest request) |
| | | { |
| | | this.connectionHandler = connectionHandler; |
| | | |
| | | // memoize all the fields we need from the request before Grizzly decides to |
| | | // recycle it |
| | | // Memorize all the fields we need from the request before Grizzly decides to recycle it |
| | | this.clientAddress = request.getRemoteAddr(); |
| | | this.clientPort = request.getRemotePort(); |
| | | this.serverAddress = request.getLocalAddr(); |
| | |
| | | this.remoteAddress = toInetAddress(request.getRemoteAddr()); |
| | | this.localAddress = toInetAddress(request.getLocalAddr()); |
| | | this.isSecure = request.isSecure(); |
| | | this.securityStrengthFactor = |
| | | calcSSF(request.getAttribute(SERVLET_SSF_CONSTANT)); |
| | | this.securityStrengthFactor = calcSSF(request.getAttribute(SERVLET_SSF_CONSTANT)); |
| | | this.method = request.getMethod(); |
| | | this.query = computeQuery(request); |
| | | this.protocol = request.getProtocol(); |
| | |
| | | return request.getRequestURI(); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public String getAuthUser() |
| | | { |
| | | return this.authUser; |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public long getConnectionID() |
| | | { |
| | | return connectionID; |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public HTTPConnectionHandler getConnectionHandler() |
| | | { |
| | | return connectionHandler; |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public long getTotalProcessingTime() |
| | | { |
| | | return totalProcessingTime.get(); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public String getProtocol() |
| | | { |
| | | return protocol; |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public String getClientAddress() |
| | | { |
| | | return clientAddress; |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public String getClientHost() |
| | | { |
| | | return clientHost; |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public int getClientPort() |
| | | { |
| | | return clientPort; |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public String getServerAddress() |
| | | { |
| | | return serverAddress; |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public String getServerHost() |
| | | { |
| | | return serverHost; |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public int getServerPort() |
| | | { |
| | | return serverPort; |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public InetAddress getRemoteAddress() |
| | | { |
| | | return remoteAddress; |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public InetAddress getLocalAddress() |
| | | { |
| | | return localAddress; |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public boolean isSecure() |
| | | { |
| | | return isSecure; |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public void sendResponse(Operation operation) |
| | | { |
| | |
| | | if (keepStats) |
| | | { |
| | | this.statTracker.updateRequestMonitoringData(getMethod(), time); |
| | | this.statTracker.updateOperationMonitoringData(operation |
| | | .getOperationType(), time); |
| | | this.statTracker.updateOperationMonitoringData(operation.getOperationType(), time); |
| | | } |
| | | |
| | | OperationWithPromise op = this.operationsInProgress.get(operation.getMessageID()); |
| | |
| | | |
| | | if (keepStats) |
| | | { |
| | | this.statTracker.updateMessageWritten(new LDAPMessage(operation |
| | | .getMessageID(), toResponseProtocolOp(operation))); |
| | | this.statTracker.updateMessageWritten( |
| | | new LDAPMessage(operation.getMessageID(), toResponseProtocolOp(operation))); |
| | | } |
| | | } |
| | | catch (LdapException e) |
| | |
| | | throw new RuntimeException("Not implemented for operation " + operation); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public void sendSearchEntry(SearchOperation operation, |
| | | SearchResultEntry searchEntry) throws DirectoryException |
| | | public void sendSearchEntry(SearchOperation operation, SearchResultEntry searchEntry) throws DirectoryException |
| | | { |
| | | SearchOperationWithPromise op = |
| | | (SearchOperationWithPromise) this.operationsInProgress.get(operation.getMessageID()); |
| | |
| | | op.entryHandler.handleEntry(from(searchEntry)); |
| | | if (keepStats) |
| | | { |
| | | this.statTracker.updateMessageWritten(new LDAPMessage(operation |
| | | .getMessageID(), new SearchResultEntryProtocolOp(searchEntry))); |
| | | this.statTracker.updateMessageWritten( |
| | | new LDAPMessage(operation.getMessageID(), new SearchResultEntryProtocolOp(searchEntry))); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public boolean sendSearchReference(SearchOperation operation, |
| | | SearchResultReference searchReference) throws DirectoryException |
| | | public boolean sendSearchReference(SearchOperation operation, SearchResultReference searchReference) |
| | | throws DirectoryException |
| | | { |
| | | SearchOperationWithPromise op = |
| | | (SearchOperationWithPromise) this.operationsInProgress.get(operation.getMessageID()); |
| | |
| | | op.entryHandler.handleReference(from(searchReference)); |
| | | if (keepStats) |
| | | { |
| | | this.statTracker.updateMessageWritten(new LDAPMessage(operation.getMessageID(), |
| | | new SearchResultReferenceProtocolOp(searchReference))); |
| | | this.statTracker.updateMessageWritten( |
| | | new LDAPMessage(operation.getMessageID(), new SearchResultReferenceProtocolOp(searchReference))); |
| | | } |
| | | } |
| | | |
| | | return connectionValid; |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | protected boolean sendIntermediateResponseMessage( |
| | | IntermediateResponse intermediateResponse) |
| | | protected boolean sendIntermediateResponseMessage(IntermediateResponse intermediateResponse) |
| | | { |
| | | // if (keepStats) |
| | | // { |
| | |
| | | throw new RuntimeException("Not implemented"); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public void setAuthUser(String authUser) |
| | | { |
| | |
| | | * not used with HTTP. |
| | | */ |
| | | @Override |
| | | public void disconnect(DisconnectReason disconnectReason, |
| | | boolean sendNotification, LocalizableMessage message) |
| | | public void disconnect(DisconnectReason disconnectReason, boolean sendNotification, LocalizableMessage message) |
| | | { |
| | | // Set a flag indicating that the connection is being terminated so |
| | | // that no new requests will be accepted. Also cancel all operations |
| | | // in progress. |
| | | // that no new requests will be accepted. |
| | | // Also cancel all operations in progress. |
| | | synchronized (opsInProgressLock) |
| | | { |
| | | // If we are already in the middle of a disconnect, then don't |
| | | // do anything. |
| | | // If we are already in the middle of a disconnect, then don't do anything. |
| | | if (disconnectRequested) |
| | | { |
| | | return; |
| | |
| | | } |
| | | else |
| | | { |
| | | cancelAllOperations(new CancelRequest(true, disconnectReason |
| | | .getClosureMessage())); |
| | | cancelAllOperations(new CancelRequest(true, disconnectReason.getClosureMessage())); |
| | | } |
| | | finalizeConnectionInternal(); |
| | | |
| | |
| | | logDisconnect(this, disconnectReason, message); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public String getMethod() |
| | | { |
| | | return this.method; |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public String getQuery() |
| | | { |
| | | return this.query; |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public int getStatusCode() |
| | | { |
| | | return this.statusCode.get(); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public String getUserAgent() |
| | | { |
| | | return this.userAgent; |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public Collection<Operation> getOperationsInProgress() |
| | | { |
| | |
| | | return results; |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public Operation getOperationInProgress(int messageID) |
| | | { |
| | |
| | | } |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public boolean removeOperationInProgress(int messageID) |
| | | { |
| | |
| | | return previousValue != null; |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public CancelResult cancelOperation(int messageID, CancelRequest cancelRequest) |
| | | { |
| | |
| | | return 0; |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public void cancelAllOperations(CancelRequest cancelRequest) |
| | | { |
| | |
| | | } |
| | | } |
| | | catch (Exception e) |
| | | { // make sure all operations are cancelled, no matter what |
| | | { // Make sure all operations are cancelled, no matter what |
| | | logger.traceException(e); |
| | | } |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public void cancelAllOperationsExcept(CancelRequest cancelRequest, |
| | | int messageID) |
| | |
| | | } |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public long getNumberOfOperations() |
| | | { |
| | | return this.operationsPerformed.get(); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public String getMonitorSummary() |
| | | { |
| | |
| | | } |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public void toString(StringBuilder buffer) |
| | | { |
| | |
| | | return statTracker; |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public int getSSF() |
| | | { |
| | | return securityStrengthFactor; |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public boolean isConnectionValid() |
| | | { |
| | | return connectionValid; |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public boolean isInnerConnection() |
| | | { |
| | | return true; |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public void log(int statusCode) |
| | | { |
| | | if (this.statusCode.compareAndSet(0, statusCode)) |
| | | { // this request was not logged before |
| | | { // This request was not logged before |
| | | HTTPAccessLogger.logRequestInfo(this); |
| | | } |
| | | } |