Tuesday, April 15, 2014

Using Spring LDAP to page large search results

I have a need to publish xml representations of specific ldap accounts to a a REST API.  This post focuses on how I used features of Spring LDAP to page the large result (200,000)  using:

Also see the section of the Spring LDAP User Guide on this topic.

The Directory Server (sometimes called an LDAP in everyday conversation) limits search results to 1,000 entries.  For example Oracle OID has such a limit by default
04: LDAP_SIZELIMIT_EXCEEDED - More entries match the search query than the size limit specified. If you have not specified a size limit for the search, Oracle Internet Directory uses a default size limit of 1000.

   public List<StaffPerson> getAllPersonNamesPaged() {  
     final SearchControls searchControls = new SearchControls();  
     final PagedResultsDirContextProcessor processor = new PagedResultsDirContextProcessor(PAGE_SIZE);  
     return SingleContextSource.doWithSingleContext(  
         contextSource, new LdapOperationsCallback<List<StaffPerson>>() {  
       public List doWithLdapOperations(LdapOperations operations) {  
         List<StaffPerson> result = new LinkedList<StaffPerson>();  
         boolean isFinished = false;  
         while (!isFinished) {  
           List<StaffPerson> oneResult = operations.search(  
               new AttributesMapper<StaffPerson>() {  
                 public StaffPerson mapFromAttributes(Attributes attrs)  
                     throws NamingException {  
                   StaffPerson staffPerson = new StaffPerson();  
                   staffPerson.setCn(getAttributeValue("cn", attrs));  
                   staffPerson.setTeachID(Long.parseLong(getAttributeValue("staffID", attrs)));  
                   staffPerson.setMail(getAttributeValue("mail", attrs));  
                   return staffPerson;  
           if (processor.hasMore()) {  
             println "processor has more: Paging Result Size ${oneResult.size()} Total Size is ${result.size()}"  
           } else {  
             isFinished = true;  
         return result;  

Friday, April 11, 2014

Reading Notes from "SOA Patterns" by Arnon Rotem-Gal-Oz

Chapter 2 - Foundation Structural Patterns

  • Service Host:  Make your services adaptable to different configurations easily and save yourself the repetitive and mundane tasks of setting listeners, wiring components, and so on.  Examples - the application server itself and frameworks like Spring.  App Fabric from Microsoft.  How can you easily configure services and avoid duplicating mundane tasks, such as setting listeners and wiring components, for each service?  Create a common service host component or framework that acts as a container for services. This container should be configurable and will perform the wiring and setup of services.  Service Host is a container for a service, and it performs the wiring and configuration on the service’s behalf.
  • Active Service:  Increase service autonomy and handle temporal concerns.With the Active Service pattern, you add independent behavior to a service in its own thread of control. This pattern can be used to handle recurring events, such as timeouts and monitoring.  How can you increase service autonomy and handle temporal concerns?  Make the service an active service by implementing at least one active class, either on the edge, within the service, or both. Let the active class take care of temporal concerns and autonomy issues.
  • Transactional Service:  Handle messages reliably.  Apply the Transactional Service pattern to handle the entire message flow, so that everything from receiving a request message to sending out a response is contained in a single transaction.  The Transactional Service pattern creates a transaction envelope: it opens a transaction, reads the request, handles the message, sends the response, and closes the transaction.  How can a service handle requests reliably?  Apply the Transactional Service pattern to handle the entire message flow, so that everything from receiving a request message to sending out a response is contained in a single transaction.
  • Workflodize:  Increase the service’s adaptability to changing business processes.  How can you increase a service’s adaptability to changing business processes?  Introduce a workflow engine within the service to handle the volatile and changing processes and orchestrate the stable logic.  The business process is made of the small building blocks that are relatively easy to rearrange. The workflow drives the business logic. The advantage of using workflows is that they give you a tool that makes you think in terms of building blocks (called activities) and lets you arrange and rearrange these activities into processes in a very flexible way.  The natural technology mapping for the Workflodize pattern is the use of a workflow engine. There are many workflow engines on the market,
  • Edge Component:  Allow the service’s business aspects, technological concerns, and other cross-cutting concerns to evolve at their own pace, independently of one another.  How can you allow the service’s business aspects, technological concerns, and other cross-cutting concerns to evolve at their own pace, independently of one another?  Add an edge component to the service implementation to add flexibility and separate the business logic from other concerns (such as contacts, protocols, technology choices, and additional cross-cutting features).  In a sense, the Edge Component pattern provides a fa├žade, or proxy, to a service implementation.  An Edge Component pattern implementation that processes incoming messages in three steps—validation, transformation, and routing—before the messages are sent to the service implementation.  As a request is received, it goes through different steps like logging, validating parameters, and validating intent and the user before it gets to the business services on the right side of this figure—getting the last order or all the orders for a specific client.  As contracts evolve, the services should be able to support consumers using older versions of the contract.

  • Service Host—A common wrapper that hosts service instances and introduces a common infrastructure that can be reused across services
  • Active Service—Implements at least one independent thread in the service so it can safely call external services
  • Transactional Service—Handles messages inside a transaction to gracefully recover from error conditions
  • Workflodize—Adds a workflow inside the service for added flexibility
  • Edge Component—Separates the interface (contract) from the implementation to enable flexibility and maintainability

Friday, April 4, 2014

Reading Notes from "SOA Patterns" by Arnon Rotem-Gal-Oz

Chapter 1

  1. Service - Distinct business function, coarse-grained. Implements all functionality promised by the contracts it exposes.  Service autonomy - the service should be mainly self-sufficient.
  2. Contract - The collection of messages supported by the service is the contract.  Unilateral, bilateral.  Analogous to interface in OOOD.
  3. Endpoint - is a URI where the service can be found.
  4. Message - Unit of communication ( HTTP GET, SOAP, JMS, SMTP)
  5. Policy - Terms and conditions for making a service available.  Policy can be updated at runtime.  Specifies dynamic properties (encryption, authentication, authorization, auditing, SLAs).
  6. Service Consumer - A service is only meaningful if another piece of software uses it. Adhere to a SOA contract themselves.



Monday, February 20, 2012

Clean Code by Robert C. Martin

When people look under the hood, we want them to be impressed with the neatness, consistency, and attention to detail that they perceive.  We want them to be struck by the orderliness.  We want their eyebrows to rise as they scroll through the modules.   We want them to perceive that professionals have been at work.  If instead they see a scrambled mass of code that looks like it was written by a bevy of drunken sailors, then they are likely to conclude that the same inattention to detail pervades every other aspect of the project.

Tuesday, July 8, 2008

Becoming A Positive Deviant

How to do things differently in a way that lets you perform better, or more potently, no matter your job?
  1. Ask an unscripted question
  2. Don't Complain
  3. Count Something
  4. Write Something
  5. Change