You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@directory.apache.org by "Emmanuel Lécharny (Jira)" <ji...@apache.org> on 2022/07/26 17:18:00 UTC

[jira] [Commented] (DIRAPI-383) LdapNetworkConnection.unbind throws IOException

    [ https://issues.apache.org/jira/browse/DIRAPI-383?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17571549#comment-17571549 ] 

Emmanuel Lécharny commented on DIRAPI-383:
------------------------------------------

It works for me when using Apache Directory Server:

 

{nooformat}
{noformat}
connection start
MessageType : BIND_RESPONSE
Message ID : 2
    BindResponse
        Ldap Result
            Result code : (SUCCESS) success
            Matched Dn : ''
            Diagnostic message : ''bind result SUCCESS
bind completed
search start
search result SUCCESS
search completed
unbind completed
connection close
 {noformat}

Which is the remte server you are using ?

> LdapNetworkConnection.unbind throws IOException
> -----------------------------------------------
>
>                 Key: DIRAPI-383
>                 URL: https://issues.apache.org/jira/browse/DIRAPI-383
>             Project: Directory Client API
>          Issue Type: Question
>    Affects Versions: 2.1.0
>            Reporter: Aliaksei Volkau
>            Priority: Major
>
> When trying to call LdapNetworkConnection.unbind catch the exception *IOException: An existing connection was forcibly closed by the remote host.*
> Code:
> LdapConnectionConfig connectionConfig = new LdapConnectionConfig();
> connectionConfig.setLdapHost(//host);
> connectionConfig.setLdapPort(//port);
> connectionConfig.setName(//dn);
> DefaultLdapConnectionFactory connectionFactory = new DefaultLdapConnectionFactory(connectionConfig);
> connectionFactory.setTimeOut(30_000);
> GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
> poolConfig.setLifo(false);
> poolConfig.setMinIdle(1);
> poolConfig.setMaxIdle(1);
> poolConfig.setMaxTotal(1);
> poolConfig.setMinEvictableIdleTimeMillis(1000 * 60 * 30L);
> poolConfig.setNumTestsPerEvictionRun(3);
> poolConfig.setSoftMinEvictableIdleTimeMillis(-1L);
> poolConfig.setTestOnBorrow(false);
> poolConfig.setTestOnReturn(false);
> poolConfig.setTimeBetweenEvictionRunsMillis(-1L);
> poolConfig.setBlockWhenExhausted(true);
> LdapConnectionPool connectionPool = new LdapConnectionPool(new DefaultPoolableLdapConnectionFactory(connectionFactory), poolConfig);
> try {
>     try (LdapConnection ldapConnection = connectionPool.getConnection()) {
>         System.out.println("connection start");
>         BindRequest bindRequest = new BindRequestImpl();
>         bindRequest.setSimple(true);
>         bindRequest.setName(//login);
>         bindRequest.setCredentials(//password);
>         BindResponse bindResponse = ldapConnection.bind(bindRequest);
>         System.out.println(bindResponse);
>         boolean okBind = false;
>         if (bindResponse != null && bindResponse.getLdapResult() != null && bindResponse.getLdapResult().getResultCode() != null) {
>             System.out.println("bind result " + bindResponse.getLdapResult().getResultCode());
>             if (bindResponse.getLdapResult().getResultCode() == ResultCodeEnum.SUCCESS) {
>                 okBind = true;
>                 System.out.println("bind completed");
>             }
>         }
>         if (okBind) {
>             try {
>                 SearchRequest searchRequest = new SearchRequestImpl();
>                 searchRequest.setBase(new Dn(//dn));
>                 searchRequest.setFilter("(sAMAccountName=//login)");
>                 searchRequest.setScope(SearchScope.SUBTREE);
>                 searchRequest.addAttributes("*");
>                 try (SearchCursor searchCursor = ldapConnection.search(searchRequest)) {
>                     System.out.println("search start");
>                     while (searchCursor.next()) {
>                         if (searchCursor.isEntry()) {
>                             Entry resultEntry = ((SearchResultEntry) searchCursor.get()).getEntry();
>                             System.out.println(resultEntry);
>                         }
>                     }
>                     if (searchCursor.getSearchResultDone() != null && searchCursor.getSearchResultDone().getLdapResult() != null && searchCursor.getSearchResultDone().getLdapResult().getResultCode() != null) {
>                         System.out.println("search result " + searchCursor.getSearchResultDone().getLdapResult().getResultCode());
>                         if (searchCursor.getSearchResultDone().getLdapResult().getResultCode() == ResultCodeEnum.SUCCESS) {
>                             System.out.println("search completed");
>                         }
>                     }
>                 }
>             } catch (LdapException e) {
>                 e.printStackTrace();
>                 System.out.println(e.getMessage());
>             }
>             if (ldapConnection.isConnected()) {
>                 ldapConnection.unBind();
>                 System.out.println("unbind completed");
>             }
>         }
>     } catch (LdapException e) {
>         e.printStackTrace();
>             } finally {
>         System.out.println("connection close");
>     }
>         } catch (Exception e) {
>     System.out.println("exception " + e.getClass().getSimpleName());
>     e.printStackTrace();
> }
> Result:
> connection start
> MessageType : BIND_RESPONSE
> Message ID : 2
>     BindResponse
>         Ldap Result
>             Result code : (SUCCESS) success
>             Matched Dn : ''
>             Diagnostic message : ''
> bind result SUCCESS
> bind completed
> search start
> search result SUCCESS
> search completed
> [NioProcessor-1] WARN org.apache.directory.ldap.client.api.LdapNetworkConnection - An existing connection was forcibly closed by the remote host
> java.io.IOException: An existing connection was forcibly closed by the remote host
>     at sun.nio.ch.SocketDispatcher.read0(Native Method)
>     at sun.nio.ch.SocketDispatcher.read(SocketDispatcher.java:43)
>     at sun.nio.ch.IOUtil.readIntoNativeBuffer(IOUtil.java:223)
>     at sun.nio.ch.IOUtil.read(IOUtil.java:197)
>     at sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:380)
>     at org.apache.mina.transport.socket.nio.NioProcessor.read(NioProcessor.java:378)
>     at org.apache.mina.transport.socket.nio.NioProcessor.read(NioProcessor.java:47)
>     at org.apache.mina.core.polling.AbstractPollingIoProcessor.read(AbstractPollingIoProcessor.java:519)
>     at org.apache.mina.core.polling.AbstractPollingIoProcessor.access$1200(AbstractPollingIoProcessor.java:68)
>     at org.apache.mina.core.polling.AbstractPollingIoProcessor$Processor.process(AbstractPollingIoProcessor.java:1224)
>     at org.apache.mina.core.polling.AbstractPollingIoProcessor$Processor.process(AbstractPollingIoProcessor.java:1213)
>     at org.apache.mina.core.polling.AbstractPollingIoProcessor$Processor.run(AbstractPollingIoProcessor.java:683)
>     at org.apache.mina.util.NamePreservingRunnable.run(NamePreservingRunnable.java:64)
>     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
>     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
>     at java.lang.Thread.run(Thread.java:748)
> unbind completed
> connection close



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@directory.apache.org
For additional commands, e-mail: dev-help@directory.apache.org