Update the DSML gateway so that it properly treats the request ID as an
optional element rather than required. Also, update the DSML search processing
code to be a little more forgiving when it comes to the search scope and
deref policy strings.
OpenDS Issue Number: 1584
| | |
| | | { |
| | | LDAPResult abandonResponse = objFactory.createLDAPResult(); |
| | | |
| | | String requestID = abandonRequest.getRequestID(); |
| | | int reqID = 0; |
| | | try |
| | | { |
| | | reqID = Integer.parseInt(requestID); |
| | | } catch (NumberFormatException nfe) |
| | | { |
| | | throw new IOException(nfe.getMessage()); |
| | | } |
| | | |
| | | // Set the id for the response. |
| | | abandonResponse.setRequestID(requestID); |
| | | abandonResponse.setRequestID(abandonRequest.getRequestID()); |
| | | |
| | | String abandonIdStr = abandonRequest.getAbandonID(); |
| | | int abandonId = 0; |
| | |
| | | |
| | | // Create and send an LDAP request to the server. |
| | | ProtocolOp op = new AbandonRequestProtocolOp(abandonId); |
| | | LDAPMessage msg = new LDAPMessage(reqID, op); |
| | | LDAPMessage msg = new LDAPMessage(DSMLServlet.nextMessageID(), op); |
| | | int numBytes = connection.getASN1Writer().writeElement(msg.encode()); |
| | | |
| | | return abandonResponse; |
| | |
| | | throws IOException, LDAPException, ASN1Exception |
| | | { |
| | | LDAPResult addResponse = objFactory.createLDAPResult(); |
| | | |
| | | String requestID = addRequest.getRequestID(); |
| | | int reqID = 1; |
| | | try |
| | | { |
| | | reqID = Integer.parseInt(requestID); |
| | | } catch (NumberFormatException nfe) |
| | | { |
| | | throw new IOException(nfe.getMessage()); |
| | | } |
| | | |
| | | // Set the response id. |
| | | addResponse.setRequestID(requestID); |
| | | addResponse.setRequestID(addRequest.getRequestID()); |
| | | |
| | | ASN1OctetString dnStr = new ASN1OctetString(addRequest.getDn()); |
| | | ArrayList<RawAttribute> attributes = new ArrayList<RawAttribute>(); |
| | |
| | | |
| | | // Create and send the LDAP request to the server. |
| | | ProtocolOp op = new AddRequestProtocolOp(dnStr, attributes); |
| | | LDAPMessage msg = new LDAPMessage(reqID, op); |
| | | LDAPMessage msg = new LDAPMessage(DSMLServlet.nextMessageID(), op); |
| | | int numBytes = connection.getASN1Writer().writeElement(msg.encode()); |
| | | |
| | | // Read and decode the LDAP response from the server. |
| | |
| | | throws IOException, LDAPException, ASN1Exception |
| | | { |
| | | LDAPResult compareResponse = objFactory.createLDAPResult(); |
| | | |
| | | String requestID = compareRequest.getRequestID(); |
| | | int reqID = 1; |
| | | try |
| | | { |
| | | if(requestID != null) |
| | | { |
| | | reqID = Integer.parseInt(requestID); |
| | | } |
| | | } catch (NumberFormatException nfe) |
| | | { |
| | | throw new IOException(nfe.getMessage()); |
| | | } |
| | | |
| | | // Set the response id. |
| | | if(requestID != null) |
| | | { |
| | | compareResponse.setRequestID(requestID); |
| | | } |
| | | compareResponse.setRequestID(compareRequest.getRequestID()); |
| | | |
| | | // Read the attribute name and value for the compare request. |
| | | AttributeValueAssertion attrValAssertion = compareRequest.getAssertion(); |
| | |
| | | |
| | | // Create and send the LDAP compare request to the server. |
| | | ProtocolOp op = new CompareRequestProtocolOp(dnStr, attrName, attrValue); |
| | | LDAPMessage msg = new LDAPMessage(reqID, op); |
| | | LDAPMessage msg = new LDAPMessage(DSMLServlet.nextMessageID(), op); |
| | | int numBytes = connection.getASN1Writer().writeElement(msg.encode()); |
| | | |
| | | // Read and decode the LDAP response from the server. |
| | |
| | | throws IOException, LDAPException, ASN1Exception |
| | | { |
| | | LDAPResult delResponse = objFactory.createLDAPResult(); |
| | | |
| | | String requestID = deleteRequest.getRequestID(); |
| | | int reqID = 1; |
| | | try |
| | | { |
| | | reqID = Integer.parseInt(requestID); |
| | | } catch (NumberFormatException nfe) |
| | | { |
| | | throw new IOException(nfe.getMessage()); |
| | | } |
| | | |
| | | // Set the response id. |
| | | delResponse.setRequestID(requestID); |
| | | delResponse.setRequestID(deleteRequest.getRequestID()); |
| | | |
| | | // Create and send the LDAP delete request to the server. |
| | | ASN1OctetString dnStr = new ASN1OctetString(deleteRequest.getDn()); |
| | | ProtocolOp op = new DeleteRequestProtocolOp(dnStr); |
| | | LDAPMessage msg = new LDAPMessage(reqID, op); |
| | | LDAPMessage msg = new LDAPMessage(DSMLServlet.nextMessageID(), op); |
| | | int numBytes = connection.getASN1Writer().writeElement(msg.encode()); |
| | | |
| | | // Read and decode the LDAP response from the server. |
| | |
| | | throws IOException, LDAPException, ASN1Exception |
| | | { |
| | | ExtendedResponse extendedResponse = objFactory.createExtendedResponse(); |
| | | |
| | | String requestID = extendedRequest.getRequestID(); |
| | | int reqID = 1; |
| | | try |
| | | { |
| | | reqID = Integer.parseInt(requestID); |
| | | } catch (NumberFormatException nfe) |
| | | { |
| | | throw new IOException(nfe.getMessage()); |
| | | } |
| | | |
| | | // Set the response id. |
| | | extendedResponse.setRequestID(requestID); |
| | | extendedResponse.setRequestID(extendedRequest.getRequestID()); |
| | | |
| | | String requestName = extendedRequest.getRequestName(); |
| | | Object value = extendedRequest.getRequestValue(); |
| | |
| | | |
| | | // Create and send the LDAP request to the server. |
| | | ProtocolOp op = new ExtendedRequestProtocolOp(requestName, asnValue); |
| | | LDAPMessage msg = new LDAPMessage(reqID, op); |
| | | LDAPMessage msg = new LDAPMessage(DSMLServlet.nextMessageID(), op); |
| | | int numBytes = connection.getASN1Writer().writeElement(msg.encode()); |
| | | |
| | | // Read and decode the LDAP response from the server. |
| | |
| | | throws IOException, LDAPException, ASN1Exception |
| | | { |
| | | LDAPResult modDNResponse = objFactory.createLDAPResult(); |
| | | |
| | | String requestID = modifyDNRequest.getRequestID(); |
| | | int reqID = 1; |
| | | try |
| | | { |
| | | reqID = Integer.parseInt(requestID); |
| | | } catch (NumberFormatException nfe) |
| | | { |
| | | throw new IOException(nfe.getMessage()); |
| | | } |
| | | modDNResponse.setRequestID(requestID); |
| | | modDNResponse.setRequestID(modifyDNRequest.getRequestID()); |
| | | |
| | | ASN1OctetString dnStr = new ASN1OctetString(modifyDNRequest.getDn()); |
| | | |
| | |
| | | } |
| | | |
| | | // Create and send the LDAP request to the server. |
| | | LDAPMessage msg = new LDAPMessage(reqID, op); |
| | | LDAPMessage msg = new LDAPMessage(DSMLServlet.nextMessageID(), op); |
| | | int numBytes = connection.getASN1Writer().writeElement(msg.encode()); |
| | | |
| | | // Read and decode the LDAP response from the server. |
| | |
| | | throws IOException, LDAPException, ASN1Exception |
| | | { |
| | | LDAPResult modResponse = objFactory.createLDAPResult(); |
| | | String requestID = modifyRequest.getRequestID(); |
| | | int reqID = 1; |
| | | try |
| | | { |
| | | reqID = Integer.parseInt(requestID); |
| | | } catch (NumberFormatException nfe) |
| | | { |
| | | throw new IOException(nfe.getMessage()); |
| | | } |
| | | |
| | | modResponse.setRequestID(requestID); |
| | | modResponse.setRequestID(modifyRequest.getRequestID()); |
| | | |
| | | ArrayList<RawModification> modifications = |
| | | new ArrayList<RawModification> (); |
| | |
| | | |
| | | // Create and send the LDAP request to the server. |
| | | ProtocolOp op = new ModifyRequestProtocolOp(dnStr, modifications); |
| | | LDAPMessage msg = new LDAPMessage(reqID, op); |
| | | LDAPMessage msg = new LDAPMessage(DSMLServlet.nextMessageID(), op); |
| | | int numBytes = connection.getASN1Writer().writeElement(msg.encode()); |
| | | |
| | | // Read and parse the LDAP response from the server. |
| | |
| | | throws IOException, LDAPException |
| | | { |
| | | SearchResponse searchResponse = objFactory.createSearchResponse(); |
| | | |
| | | String requestID = searchRequest.getRequestID(); |
| | | int reqID = 1; |
| | | try |
| | | { |
| | | reqID = Integer.parseInt(requestID); |
| | | } catch (NumberFormatException nfe) |
| | | { |
| | | throw new IOException(nfe.getMessage()); |
| | | } |
| | | |
| | | searchResponse.setRequestID(requestID); |
| | | searchResponse.setRequestID(searchRequest.getRequestID()); |
| | | |
| | | ArrayList<LDAPFilter> filters = new ArrayList<LDAPFilter> (); |
| | | LDAPFilter f = null; |
| | |
| | | { |
| | | filters.add(f); |
| | | } |
| | | DereferencePolicy derefPolicy = DereferencePolicy.DEREF_IN_SEARCHING; |
| | | DereferencePolicy derefPolicy = DereferencePolicy.NEVER_DEREF_ALIASES; |
| | | String derefStr = searchRequest.getDerefAliases().toLowerCase(); |
| | | if (derefStr.equals("derefinsearching")) |
| | | { |
| | | derefPolicy = DereferencePolicy.DEREF_IN_SEARCHING; |
| | | } |
| | | else if (derefStr.equals("dereffindingbaseobj")) |
| | | { |
| | | derefPolicy = DereferencePolicy.DEREF_FINDING_BASE_OBJECT; |
| | | } |
| | | else if (derefStr.equals("derefalways")) |
| | | { |
| | | derefPolicy = DereferencePolicy.DEREF_ALWAYS; |
| | | } |
| | | |
| | | SearchScope scope = SearchScope.WHOLE_SUBTREE; |
| | | if(searchRequest.getScope().equals("singleLevel")) |
| | | String scopeStr = searchRequest.getScope().toLowerCase(); |
| | | if(scopeStr.equals("singlelevel") || scopeStr.equals("one")) |
| | | { |
| | | scope = SearchScope.SINGLE_LEVEL; |
| | | } else if(searchRequest.getScope().equals("baseObject")) |
| | | } else if(scopeStr.equals("baseobject") || scopeStr.equals("base")) |
| | | { |
| | | scope = SearchScope.BASE_OBJECT; |
| | | } |
| | |
| | | false, filter, attributes); |
| | | try |
| | | { |
| | | LDAPMessage msg = new LDAPMessage(reqID, protocolOp); |
| | | LDAPMessage msg = new LDAPMessage(DSMLServlet.nextMessageID(), |
| | | protocolOp); |
| | | int numBytes = connection.getASN1Writer().writeElement(msg.encode()); |
| | | |
| | | byte opType; |
| | |
| | | ae.printStackTrace(); |
| | | throw new IOException(ae.getMessage()); |
| | | } |
| | | |
| | | reqID++; |
| | | } |
| | | return searchResponse; |
| | | } |
| | |
| | | private static final String PORT = "ldap.port"; |
| | | private static final String HOST = "ldap.host"; |
| | | private static final long serialVersionUID = -3748022009593442973L; |
| | | private static final AtomicInteger nextMessageID = new AtomicInteger(1); |
| | | |
| | | private Unmarshaller unmarshaller; |
| | | private Marshaller marshaller; |
| | |
| | | } |
| | | } finally { |
| | | if (connection != null) { |
| | | connection.close(new AtomicInteger(1)); |
| | | connection.close(nextMessageID); |
| | | } |
| | | } |
| | | } |
| | |
| | | reply.writeTo(os); |
| | | os.flush(); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Retrieves a message ID that may be used for the next LDAP message sent to |
| | | * the Directory Server. |
| | | * |
| | | * @return A message ID that may be used for the next LDAP message sent to |
| | | * the Directory Server. |
| | | */ |
| | | public static int nextMessageID() |
| | | { |
| | | int nextID = nextMessageID.getAndIncrement(); |
| | | if (nextID == Integer.MAX_VALUE) |
| | | { |
| | | nextMessageID.set(1); |
| | | } |
| | | |
| | | return nextID; |
| | | } |
| | | } |
| | | |