@Override
    public void process(Exchange exchange) throws Exception {
        @SuppressWarnings("unchecked")
        Map<String, Object> body = exchange.getIn().getBody(Map.class);

        LdapOperation operation = endpoint.getOperation();
        if (null == operation) {
            throw new UnsupportedOperationException("LDAP operation must not be empty, but you provided an empty operation");
        }

        LdapTemplate ldapTemplate = endpoint.getLdapTemplate();

        String dn = (String) body.get(DN);
        boolean dnSetOnLdapTemplate = false;
        ContextSource contextSource = ldapTemplate.getContextSource();
        if (contextSource instanceof BaseLdapPathContextSource) {
            if (ObjectHelper.isNotEmpty(((BaseLdapPathContextSource) contextSource).getBaseLdapPathAsString())) {
                dn = ""; // DN already set on the ldapTemplate
                dnSetOnLdapTemplate = true;
            }
        }
        if (operation != LdapOperation.FUNCTION_DRIVEN && ObjectHelper.isEmpty(dn) && !dnSetOnLdapTemplate) {
            throw new UnsupportedOperationException("DN must not be empty, but you provided an empty DN");
        }

        switch (operation) {
            case SEARCH:
                String filter = (String) body.get(FILTER);
                exchange.getIn().setBody(ldapTemplate.search(dn, filter, endpoint.scopeValue(), mapper));
                break;
            case BIND:
                Attributes attributes = (Attributes) body.get(ATTRIBUTES);
                ldapTemplate.bind(dn, null, attributes);
                break;
            case UNBIND:
                ldapTemplate.unbind(dn);
                break;
            case AUTHENTICATE:
                ldapTemplate.authenticate(LdapQueryBuilder.query().base(dn).filter((String) body.get(FILTER)),
                        (String) body.get(PASSWORD));
                break;
            case MODIFY_ATTRIBUTES:
                ModificationItem[] modificationItems = (ModificationItem[]) body.get(MODIFICATION_ITEMS);
                ldapTemplate.modifyAttributes(dn, modificationItems);
                break;
            case FUNCTION_DRIVEN:
                BiFunction<LdapOperations, Object, ?> ldapOperationFunction
                        = (BiFunction<LdapOperations, Object, ?>) body.get(FUNCTION);
                Object ldapOperationRequest = body.get(REQUEST);
                exchange.getIn().setBody(ldapOperationFunction.apply(ldapTemplate, ldapOperationRequest));
                break;
            default:
                throw new UnsupportedOperationException(
                        "Bug in the Spring-LDAP component. Despite of all assertions, you managed to call an unsupported operation '"
                                                        + operation
                                                        + "'");
        }
    }
@Test
    public void testEmptyExchange() throws Exception {
        Exchange exchange = new DefaultExchange(context);
        assertThrows(UnsupportedOperationException.class,
                () -> ldapProducer.process(exchange));
    }