use of com.unboundid.ldap.protocol.LDAPMessage in project ldapsdk by pingidentity.
the class LDAPListenerClientConnection method sendIntermediateResponse.
/**
* Sends an intermediate response message to the client with the provided
* information.
*
* @param messageID The message ID for the LDAP message to send to the
* client. It must match the message ID of the associated
* search request.
* @param protocolOp The intermediate response protocol op to include in the
* LDAP message to send to the client.
* @param controls The set of controls to include in the response message.
* It may be empty or {@code null} if no controls should
* be included.
*
* @throws LDAPException If a problem occurs while attempting to send the
* provided response message. If an exception is
* thrown, then the client connection will have been
* terminated.
*/
public void sendIntermediateResponse(final int messageID, @NotNull final IntermediateResponseProtocolOp protocolOp, @Nullable final Control... controls) throws LDAPException {
if (intermediateResponseTransformers.isEmpty()) {
sendMessage(new LDAPMessage(messageID, protocolOp, controls));
} else {
Control[] c;
IntermediateResponseProtocolOp op = protocolOp;
if (controls == null) {
c = EMPTY_CONTROL_ARRAY;
} else {
c = controls;
}
for (final IntermediateResponseTransformer t : intermediateResponseTransformers) {
try {
final ObjectPair<IntermediateResponseProtocolOp, Control[]> p = t.transformIntermediateResponse(messageID, op, c);
if (p == null) {
return;
}
op = p.getFirst();
c = p.getSecond();
} catch (final Exception e) {
Debug.debugException(e);
sendMessage(new LDAPMessage(messageID, protocolOp, c));
throw new LDAPException(ResultCode.LOCAL_ERROR, ERR_CONN_INTERMEDIATE_RESPONSE_TRANSFORMER_EXCEPTION.get(t.getClass().getName(), String.valueOf(op), StaticUtils.getExceptionMessage(e)), e);
}
}
sendMessage(new LDAPMessage(messageID, op, c));
}
}
use of com.unboundid.ldap.protocol.LDAPMessage in project ldapsdk by pingidentity.
the class ProxyRequestHandler method processExtendedRequest.
/**
* {@inheritDoc}
*/
@Override()
@NotNull()
public LDAPMessage processExtendedRequest(final int messageID, @NotNull final ExtendedRequestProtocolOp request, @NotNull final List<Control> controls) {
final ExtendedRequest extendedRequest;
if (controls.isEmpty()) {
extendedRequest = new ExtendedRequest(request.getOID(), request.getValue());
} else {
final Control[] controlArray = new Control[controls.size()];
controls.toArray(controlArray);
extendedRequest = new ExtendedRequest(request.getOID(), request.getValue(), controlArray);
}
extendedRequest.setIntermediateResponseListener(this);
try {
final ExtendedResult extendedResult = ldapConnection.processExtendedOperation(extendedRequest);
final ExtendedResponseProtocolOp extendedResponseProtocolOp = new ExtendedResponseProtocolOp(extendedResult.getResultCode().intValue(), extendedResult.getMatchedDN(), extendedResult.getDiagnosticMessage(), Arrays.asList(extendedResult.getReferralURLs()), extendedResult.getOID(), extendedResult.getValue());
return new LDAPMessage(messageID, extendedResponseProtocolOp, Arrays.asList(extendedResult.getResponseControls()));
} catch (final LDAPException le) {
Debug.debugException(le);
final ExtendedResponseProtocolOp extendedResponseProtocolOp = new ExtendedResponseProtocolOp(le.getResultCode().intValue(), le.getMatchedDN(), le.getMessage(), Arrays.asList(le.getReferralURLs()), null, null);
return new LDAPMessage(messageID, extendedResponseProtocolOp, Arrays.asList(le.getResponseControls()));
}
}
use of com.unboundid.ldap.protocol.LDAPMessage in project ldapsdk by pingidentity.
the class ProxyRequestHandler method processSearchRequest.
/**
* {@inheritDoc}
*/
@Override()
@NotNull()
public LDAPMessage processSearchRequest(final int messageID, @NotNull final SearchRequestProtocolOp request, @NotNull final List<Control> controls) {
final String[] attrs;
final List<String> attrList = request.getAttributes();
if (attrList.isEmpty()) {
attrs = StaticUtils.NO_STRINGS;
} else {
attrs = new String[attrList.size()];
attrList.toArray(attrs);
}
final ProxySearchResultListener searchListener = new ProxySearchResultListener(listenerConnection, messageID);
final SearchRequest searchRequest = new SearchRequest(searchListener, request.getBaseDN(), request.getScope(), request.getDerefPolicy(), request.getSizeLimit(), request.getTimeLimit(), request.typesOnly(), request.getFilter(), attrs);
if (!controls.isEmpty()) {
searchRequest.setControls(controls);
}
searchRequest.setIntermediateResponseListener(this);
LDAPResult searchResult;
try {
searchResult = ldapConnection.search(searchRequest);
} catch (final LDAPException le) {
Debug.debugException(le);
searchResult = le.toLDAPResult();
}
final SearchResultDoneProtocolOp searchResultDoneProtocolOp = new SearchResultDoneProtocolOp(searchResult.getResultCode().intValue(), searchResult.getMatchedDN(), searchResult.getDiagnosticMessage(), Arrays.asList(searchResult.getReferralURLs()));
return new LDAPMessage(messageID, searchResultDoneProtocolOp, Arrays.asList(searchResult.getResponseControls()));
}
use of com.unboundid.ldap.protocol.LDAPMessage in project ldapsdk by pingidentity.
the class ProxyRequestHandler method processModifyRequest.
/**
* {@inheritDoc}
*/
@Override()
@NotNull()
public LDAPMessage processModifyRequest(final int messageID, @NotNull final ModifyRequestProtocolOp request, @NotNull final List<Control> controls) {
final ModifyRequest modifyRequest = new ModifyRequest(request.getDN(), request.getModifications());
if (!controls.isEmpty()) {
modifyRequest.setControls(controls);
}
modifyRequest.setIntermediateResponseListener(this);
LDAPResult modifyResult;
try {
modifyResult = ldapConnection.modify(modifyRequest);
} catch (final LDAPException le) {
Debug.debugException(le);
modifyResult = le.toLDAPResult();
}
final ModifyResponseProtocolOp modifyResponseProtocolOp = new ModifyResponseProtocolOp(modifyResult.getResultCode().intValue(), modifyResult.getMatchedDN(), modifyResult.getDiagnosticMessage(), Arrays.asList(modifyResult.getReferralURLs()));
return new LDAPMessage(messageID, modifyResponseProtocolOp, Arrays.asList(modifyResult.getResponseControls()));
}
use of com.unboundid.ldap.protocol.LDAPMessage in project ldapsdk by pingidentity.
the class ProxyRequestHandler method processModifyDNRequest.
/**
* {@inheritDoc}
*/
@Override()
@NotNull()
public LDAPMessage processModifyDNRequest(final int messageID, @NotNull final ModifyDNRequestProtocolOp request, @NotNull final List<Control> controls) {
final ModifyDNRequest modifyDNRequest = new ModifyDNRequest(request.getDN(), request.getNewRDN(), request.deleteOldRDN(), request.getNewSuperiorDN());
if (!controls.isEmpty()) {
modifyDNRequest.setControls(controls);
}
modifyDNRequest.setIntermediateResponseListener(this);
LDAPResult modifyDNResult;
try {
modifyDNResult = ldapConnection.modifyDN(modifyDNRequest);
} catch (final LDAPException le) {
Debug.debugException(le);
modifyDNResult = le.toLDAPResult();
}
final ModifyDNResponseProtocolOp modifyDNResponseProtocolOp = new ModifyDNResponseProtocolOp(modifyDNResult.getResultCode().intValue(), modifyDNResult.getMatchedDN(), modifyDNResult.getDiagnosticMessage(), Arrays.asList(modifyDNResult.getReferralURLs()));
return new LDAPMessage(messageID, modifyDNResponseProtocolOp, Arrays.asList(modifyDNResult.getResponseControls()));
}
Aggregations