Java & commons.net.nntp -> Listnewsgroups not working

Pagina: 1
Acties:

Onderwerpen


Acties:
  • 0 Henk 'm!

  • BSeB
  • Registratie: Juni 2001
  • Laatst online: 15-08 13:07
Ik probeer dit weekend een simpel programma te maken waarmee ik alle nieuwsgroepen op mijn nieuwsserver kan bekijken. Helaas krijg ik dit niet voor elkaar.

Heb dit voor 2 verschillende server geprobeerd. Bij de tweede lukt het wel en bij de eerste lukt dit niet:

"reader.xsnews.nl" -> niet wekend
"freenews.netfront.net" -> werkend

Nu vraag ik mij af hoe dit komt en of dit te corrigeren is.

De functionaliteiten zitten in de package van apache:

- org.apache.commons.net.nntp

Ik heb de test example gebruikt voor mijn test:

Java:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package examples.nntp;

import java.io.IOException;
import org.apache.commons.net.nntp.NNTPClient;
import org.apache.commons.net.nntp.NewsgroupInfo;

/***
 * This is a trivial example using the NNTP package to approximate the
 * Unix newsgroups command.  It merely connects to the specified news
 * server and issues fetches the list of newsgroups stored by the server.
 * On servers that store a lot of newsgroups, this command can take a very
 * long time (listing upwards of 30,000 groups).
 * <p>
 ***/

public final class ListNewsgroups
{

    public final static void main(String[] args)
    {
        NNTPClient client;
        NewsgroupInfo[] list;

        if (args.length < 1)
        {
            System.err.println("Usage: newsgroups newsserver");
            System.exit(1);
        }

        client = new NNTPClient();

        try
        {
            client.connect(args[0]);

            list = client.listNewsgroups();

            if (list != null)
            {
                for (int i = 0; i < list.length; i++)
                    System.out.println(list[i].getNewsgroup());
            }
            else
            {
                System.err.println("LIST command failed.");
                System.err.println("Server reply: " + client.getReplyString());
            }
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
        finally
        {
            try
            {
                if (client.isConnected())
                    client.disconnect();
            }
            catch (IOException e)
            {
                System.err.println("Error disconnecting from server.");
                e.printStackTrace();
                System.exit(1);
            }
        }

    }

}


Voordat ik nu verder ga zou ik graag dit probleem oplossen, maar ik kan niet zo goed vinden waar dit probleem zit. Het lijkt erop dat mijn nieuwsserver xsnews niet het commando verstaat. Of dit niet toestaat?

Acties:
  • 0 Henk 'm!

  • Jegorex
  • Registratie: April 2004
  • Laatst online: 03-09 23:24
this command can take a very long time (listing upwards of 30,000 groups).
Kan het zijn dat die eerste niet lijkt te werken omdat hij nog steeds aan het laden is?

Acties:
  • 0 Henk 'm!

  • BSeB
  • Registratie: Juni 2001
  • Laatst online: 15-08 13:07
Uhm, dat zou theoretisch kunnen, maar dan zou ik de timeout moeten verlengen om te kijken of het da opgelost zou zijn.
Kan ik dadelijk wel is proberen.

Java:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
public final class ListNewsgroups
{
    public final static void main(String[] args)
    {
        NNTPClient client;
        NewsgroupInfo[] list;
        Integer Timeout = null;

        if (args.length < 1)
        {
            System.err.println("Usage: newsgroups newsserver");
            System.exit(1);
        }

        client = new NNTPClient();
        
        try
        {           
            if (args[4] == "SSL")
            {
                client.setSocketFactory(SSLSocketFactory.getDefault());
            } 
            else 
            {
                //factory = createSocket(host, port);
            }
        
            client.connect(args[0],Integer.parseInt(args[3]));
    
            // AUTHINFO USER/AUTHINFO PASS
            boolean success = client.authenticate(args[1], args[2]);
            if (success) {
                System.out.println("Authentication succeeded");
            } else {
                System.out.println("Authentication failed, error =" + client.getReplyString());
            }
            Timeout = 100000;
            client.setSoTimeout(Timeout);
            
            list = client.listNewsgroups();
            
            if (list != null)
            {
                for (int i = 0; i < list.length; i++)
                    System.out.println(list[i].getNewsgroup());
            }
            else
            {
                System.err.println("LIST command failed.");
                System.err.println("Server reply: " + client.getReplyString());
            }
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
        finally
        {
            try
            {
                if (client.isConnected())
                    client.disconnect();
            }
            catch (IOException e)
            {
                System.err.println("Error disconnecting from server.");
                e.printStackTrace();
                System.exit(1);
            }
        }
    }
}


Dit geeft als resultaat:

code:
1
2
3
4
5
6
Authentication succeeded
org.apache.commons.net.MalformedServerReplyException:  000000000000000 000000000000000 y
    at org.apache.commons.net.nntp.NNTPClient.__readNewsgroupListing(NNTPClient.java:255)
    at org.apache.commons.net.nntp.NNTPClient.listNewsgroups(NNTPClient.java:930)
    at ListNewsgroups.main(ListNewsgroups.java:77)
    at Testing_NNTP.main(Testing_NNTP.java:24)


En nu met protocol command listener:

code:
1
2
3
4
5
6
7
8
9
10
11
12
13
201 reader.xsnews.nl (frontend-E07-05) Server Ready - support@xsnews.nl
AUTHINFO USER ********
381 PASS required
AUTHINFO PASS *********
281 Ok
Authentication succeeded
LIST
215 Newsgroups in form "group high low flags".
org.apache.commons.net.MalformedServerReplyException:  000000000000000 000000000000000 y
    at org.apache.commons.net.nntp.NNTPClient.__readNewsgroupListing(NNTPClient.java:255)
    at org.apache.commons.net.nntp.NNTPClient.listNewsgroups(NNTPClient.java:930)
    at ListNewsgroups.main(ListNewsgroups.java:59)
    at Testing_NNTP.main(Testing_NNTP.java:24)


Geen success met de volgende code ipv soltimeout:

Java:
1
2
Timeout = 1000000;
        client.setDefaultTimeout(Timeout);


Heb zojuist via de commandline (telnet) getest en dit werkt gewoon. Heb momenteel dus geen idee wat het probleem is. Misschien dat iemand hier het nog snapt?

[ Voor 103% gewijzigd door BSeB op 13-03-2011 21:20 ]


Acties:
  • 0 Henk 'm!

  • BSeB
  • Registratie: Juni 2001
  • Laatst online: 15-08 13:07
Niemand die me hiermee zou kunnen helpen?

Ah finally I have found the answer :(

https://issues.apache.org/jira/browse/NET-276

[ Voor 52% gewijzigd door BSeB op 14-03-2011 15:05 ]