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

Alexander B edited comment on DIRMINA-1185 at 12/9/24 9:20 AM:
---------------------------------------------------------------

This is the main part of the class for this scenario. We use the object of type 
_AbstractIoService _to handle other cases (like _NioSocketConnector_) in the 
code aswell on a more abstract way. But for this exception, just the code for 
NioSocketAcceptor is executed.



{code:java}
public class Sink extends IoHandlerAdapter {
  private AbstractIoService acceptor;

protected void init() {
  acceptor = new NioSocketAcceptor();
  ((NioSocketAcceptor)acceptor).setReuseAddress(true);
  acceptor.getStatistics().setThroughputCalculationInterval(1);
  acceptor.setHandler(this);
  InetSocketAddress address = new InetSocketAddress(2004);
  ((NioSocketAcceptor)acceptor).bind(address);
}

protected void dispose() {
  if (null != acceptor) {
    ((NioSocketAcceptor)acceptor).unbind();
  }
}

  // all overwritten mina methods for IoHandlerAdapter

}
{code}

The tomcat is incldude via pom.xml

{code:java}
<plugin>
        <groupId>org.apache.tomcat.maven</groupId>
        <artifactId>tomcat7-maven-plugin</artifactId>
        <version>2.1</version>
        <executions>
                <execution>
                        <id>tomcat-run</id>
                        <goals>
                                <goal>exec-war-only</goal>
                        </goals>
                        <phase>package</phase>
                        <configuration>
                                <path>/</path>
                                
<serverXml>src/main/tomcatconf/server.xml</serverXml>
                                
<attachartifactclassifier>server</attachartifactclassifier>
                                
<attachartifactclassifiertype>jar</attachartifactclassifiertype>
                        </configuration>
                </execution>
        </executions>
</plugin>
{code}

For HTTPS the user specific `<serverXml>` is included and looks like:

{code:java}
    <Service name="Catalina">
        <Connector port="8443" 
protocol="org.apache.coyote.http11.Http11NioProtocol" connectionTimeout="20000" 
maxThreads="100" scheme="https" secure="true" SSLEnabled="true" 
keystoreFile="<PathToKeystoreFile>" keystorePass="<PasswordForKeystore>" 
clientAuth="false" sslProtocol="TLS"/>

        <Engine name="Catalina" defaultHost="localhost">

            <Host name="localhost"  appBase="webapps" unpackWARs="true" 
autoDeploy="true">
                <Valve className="org.apache.catalina.valves.AccessLogValve" 
directory="logs" prefix="localhost_access_log." suffix=".txt" pattern="%h %l %u 
%t &quot;%r&quot; %s %b" />
            </Host>
        </Engine>
    </Service>


{code}


was (Author: abuechel):
This is the main part of the class for this scenario. We use the object of type 
_AbstractIoService _to handle other cases (like _NioSocketConnector_) in the 
code aswell on a more abstract way. But for this exception, just the code for 
NioSocketAcceptor is executed.



{code:java}
public class Sink extends IoHandlerAdapter {
  private AbstractIoService acceptor;

protected void init() {
  acceptor = new NioSocketAcceptor();
  ((NioSocketAcceptor)acceptor).setReuseAddress(true);
  acceptor.getStatistics().setThroughputCalculationInterval(1);
  acceptor.setHandler(this);
  InetSocketAddress address = new InetSocketAddress(2004);
  ((NioSocketAcceptor)acceptor).bind(address);
}

protected void dispose() {
  if (null != acceptor) {
    ((NioSocketAcceptor)acceptor).unbind();
  }
}

  // all overwritten mina methods for IoHandlerAdapter

}
{code}


> Question about Unbinding NioAcceptor
> ------------------------------------
>
>                 Key: DIRMINA-1185
>                 URL: https://issues.apache.org/jira/browse/DIRMINA-1185
>             Project: MINA
>          Issue Type: Bug
>          Components: Core
>    Affects Versions: 2.1.8
>            Reporter: Alexander B
>            Priority: Major
>
> Hi there,
> We have an application (Tomcat7 , Java8), which uses Mina 2.1.8. The 
> intention is to open a port (in this example 2004) and close this connection 
> object in case nobody will be connected. Then after a moment a new binding 
> should be performed on this object.
> Until today this Tomcat ran on HTTP. I have switched to HTTPS and actually I 
> did not touch any code, which includes/extends any Mina-classes. 
> In the first case (Tomcat running on HTTP), there is an instance of 
> NioSocketAcceptor, which will be `unbind()`, if there is no connection after 
> a specific time. Then a reconnect (new bind on port 2004) will be performed 
> and the same port will be opened again. This works fine.
> In the second case (Tomcat running on HTTPS with the following changes: I 
> created a keystore, integrated it into the project and adapted tomcat's 
> server.xml) after a specific time I called unbind() on the 
> NioSocketAccepter-object and then a reconnect we will performed again. In 
> this moment, the new binding crashes with the message :
> ```
> java.io.IOException: Error while binding on 0.0.0.0/0.0.0.0:2004
>         at 
> org.apache.mina.transport.socket.nio.NioSocketAcceptor.open(NioSocketAcceptor.java:301)
>         at 
> org.apache.mina.transport.socket.nio.NioSocketAcceptor.open(NioSocketAcceptor.java:52)
>         at 
> org.apache.mina.core.polling.AbstractPollingIoAcceptor$Acceptor.registerHandles(AbstractPollingIoAcceptor.java:621)
>         at 
> org.apache.mina.core.polling.AbstractPollingIoAcceptor$Acceptor.run(AbstractPollingIoAcceptor.java:518)
>         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)
> Caused by: java.net.BindException: Address already in use: bind
>         at sun.nio.ch.Net.bind0(Native Method)
>         at sun.nio.ch.Net.bind(Net.java:461)
>         at sun.nio.ch.Net.bind(Net.java:453)
>         at 
> sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:222)
>         at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:85)
>         at 
> org.apache.mina.transport.socket.nio.NioSocketAcceptor.open(NioSocketAcceptor.java:296)
>         ... 7 common frames omitted
> ```
> Do you know, if there are any issues regarding the unbinding process in Mina 
> in combination with a running Tomcat on HTTPS? Or do I have to change any 
> implementation including mina classes?



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

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@mina.apache.org
For additional commands, e-mail: dev-h...@mina.apache.org

Reply via email to