mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

neil_a_wilson
09.41.2007 fc649ad091ca53cbb9798ab193f0e36695abe825
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
9 files modified
174 ■■■■■ changed files
opends/src/dsml/org/opends/dsml/protocol/DSMLAbandonOperation.java 14 ●●●● patch | view | raw | blame | history
opends/src/dsml/org/opends/dsml/protocol/DSMLAddOperation.java 16 ●●●● patch | view | raw | blame | history
opends/src/dsml/org/opends/dsml/protocol/DSMLCompareOperation.java 22 ●●●●● patch | view | raw | blame | history
opends/src/dsml/org/opends/dsml/protocol/DSMLDeleteOperation.java 16 ●●●● patch | view | raw | blame | history
opends/src/dsml/org/opends/dsml/protocol/DSMLExtendedOperation.java 16 ●●●● patch | view | raw | blame | history
opends/src/dsml/org/opends/dsml/protocol/DSMLModifyDNOperation.java 14 ●●●● patch | view | raw | blame | history
opends/src/dsml/org/opends/dsml/protocol/DSMLModifyOperation.java 14 ●●●● patch | view | raw | blame | history
opends/src/dsml/org/opends/dsml/protocol/DSMLSearchOperation.java 39 ●●●● patch | view | raw | blame | history
opends/src/dsml/org/opends/dsml/protocol/DSMLServlet.java 23 ●●●●● patch | view | raw | blame | history
opends/src/dsml/org/opends/dsml/protocol/DSMLAbandonOperation.java
@@ -70,18 +70,8 @@
  {
    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;
@@ -95,7 +85,7 @@
    // 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;
opends/src/dsml/org/opends/dsml/protocol/DSMLAddOperation.java
@@ -85,19 +85,7 @@
    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>();
@@ -117,7 +105,7 @@
    // 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.
opends/src/dsml/org/opends/dsml/protocol/DSMLCompareOperation.java
@@ -83,25 +83,7 @@
    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();
@@ -113,7 +95,7 @@
    // 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.
opends/src/dsml/org/opends/dsml/protocol/DSMLDeleteOperation.java
@@ -85,24 +85,12 @@
    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.
opends/src/dsml/org/opends/dsml/protocol/DSMLExtendedOperation.java
@@ -83,19 +83,7 @@
    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();
@@ -103,7 +91,7 @@
    // 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.
opends/src/dsml/org/opends/dsml/protocol/DSMLModifyDNOperation.java
@@ -84,17 +84,7 @@
    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());
@@ -114,7 +104,7 @@
    }
    // 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.
opends/src/dsml/org/opends/dsml/protocol/DSMLModifyOperation.java
@@ -89,17 +89,7 @@
        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> ();
@@ -138,7 +128,7 @@
    // 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.
opends/src/dsml/org/opends/dsml/protocol/DSMLSearchOperation.java
@@ -93,18 +93,7 @@
         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;
@@ -124,12 +113,27 @@
    {
      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;
    }
@@ -157,7 +161,8 @@
          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;
@@ -250,8 +255,6 @@
        ae.printStackTrace();
        throw new IOException(ae.getMessage());
      }
      reqID++;
    }
    return searchResponse;
  }
opends/src/dsml/org/opends/dsml/protocol/DSMLServlet.java
@@ -65,6 +65,7 @@
  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;
@@ -303,7 +304,7 @@
      }
    } finally {
      if (connection != null) {
        connection.close(new AtomicInteger(1));
        connection.close(nextMessageID);
      }
    }
  }
@@ -347,5 +348,25 @@
    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;
  }
}