Example usage for org.apache.commons.net.nntp NNTPClient setDefaultPort

List of usage examples for org.apache.commons.net.nntp NNTPClient setDefaultPort

Introduction

In this page you can find the example usage for org.apache.commons.net.nntp NNTPClient setDefaultPort.

Prototype

public void setDefaultPort(int port) 

Source Link

Document

Sets the default port the SocketClient should connect to when a port is not specified.

Usage

From source file:org.ossmeter.platform.communicationchannel.nntp.local.NntpUtil.java

public static NNTPClient connectToNntpServer(NntpNewsGroup newsgroup) {

    NNTPClient client = new NNTPClient();
    client.setDefaultPort(newsgroup.getPort());
    String serverUrl = newsgroup.getUrl().substring(0, newsgroup.getUrl().lastIndexOf("/"));
    try {/*from   www . ja  va2  s.c  o  m*/
        client.connect(serverUrl);
        if (newsgroup.getAuthenticationRequired()) {
            client.authenticate(newsgroup.getUsername(), newsgroup.getPassword());
        }
    } catch (SocketException e) {
        // TODO Auto-generated catch block
        System.err.println("SocketException while connecting to NNTP server: '" + newsgroup.getUrl() + "': "
                + e.getMessage());
        //           System.exit(1);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        System.err.println(
                "IOException while connecting to NNTP server: '" + newsgroup.getUrl() + "': " + e.getMessage());
        //           System.exit(1);
    }
    return client;
}

From source file:org.ossmeter.platform.communicationchannel.nntp.NntpUtil.java

public static NNTPClient connectToNntpServer(NntpNewsGroup newsgroup) {

    NNTPClient client = new NNTPClient();
    client.setDefaultPort(newsgroup.getPort());
    String serverUrl = newsgroup.getUrl();

    if (serverUrl.endsWith("/")) {
        serverUrl = newsgroup.getUrl().substring(0, newsgroup.getUrl().lastIndexOf("/"));
    }//from  www  . ja  v a  2  s .c  om

    try {
        client.connect(serverUrl);
        if (newsgroup.getAuthenticationRequired()) {
            client.authenticate(newsgroup.getUsername(), newsgroup.getPassword());
        }
    } catch (SocketException e) {
        // TODO Auto-generated catch block
        System.err.println("SocketException while connecting to NNTP server: '" + newsgroup.getUrl() + "': "
                + e.getMessage());
        e.printStackTrace();
        //           System.exit(1);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        System.err.println(
                "IOException while connecting to NNTP server: '" + newsgroup.getUrl() + "': " + e.getMessage());
        e.printStackTrace();
        //           System.exit(1);
    }
    return client;
}