1

I receive the following error when trying to parse an atom feed. org.apache.abdera.parser.ParseException: java.lang.ArrayIndexOutOfBoundsException at org.apache.abdera.parser.stax.FOMParser.parse(FOMParser.java:128) at org.apache.abdera.util.AbstractParser.parse(AbstractParser.java:73) at testfeedreader.TestFeedReader.main(TestFeedReader.java:44) Caused by: java.lang.ArrayIndexOutOfBoundsException ....

Here is my code for the reader. I hard coded the url for testing:

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package testfeedreader;

import java.io.IOException;
import java.net.URL;
import java.util.List;

import org.apache.abdera.Abdera;
import org.apache.abdera.model.Document;
import org.apache.abdera.model.Entry;
import org.apache.abdera.model.Feed;
import org.apache.abdera.model.Category;
import org.apache.abdera.model.Link;
import org.apache.abdera.parser.ParseException;
import org.apache.abdera.parser.Parser;

/**
 *
 * @author srieger
 */
public class TestFeedReader {

    private static Abdera abdera = null;

    /**
     *
     * @return
     */
    public static synchronized Abdera getInstance() {
        if (abdera == null) {
            abdera = new Abdera();
        }
        return abdera;
    }

    public static void main(String[] args) {
        Parser parser = getInstance().getParser();

        try {
            URL url = new URL("http://connect.lmsnet.com/files/basic/anonymous/api/documents/feed");
            Document<Feed> doc = parser.parse(url.openStream(), url.toString());
            Feed feed = doc.getRoot();
            // Get the feed title
            System.out.println("Feed Title: " + feed.getTitle());

            // Get the entry items...
            for (Entry entry : feed.getEntries()) {
                System.out.println("Title: " + entry.getTitle());
                System.out.println("Unique Identifier: " + entry.getId().toString());
                System.out.println("Updated Date: " + entry.getUpdated().toString());
                System.out.println("Published Date: " + entry.getPublished());
                System.out.println("Content: " + entry.getContent());

                // Get the links
                for (Link link : (List<Link>) entry.getLinks()) {
                    System.out.println("Link: " + link.getHref());
                }               

                // Get the categories
                for (Category category : (List<Category>) entry.getCategories()) {
                    System.out.println("Category: " + category.getTerm());
                }
            }
        } catch( IOException | ParseException e )
        {
            e.printStackTrace();
        }
    }
}
Bitwyse1
  • 339
  • 3
  • 18
  • 1
    Which line in your source is 44? I guess: `Document doc = parser.parse(url.openStream(), url.toString());` I think the atom feed is malformed... – Frantisek Kossuth Feb 24 '15 at 08:52
  • Another thought: are you sure you get atom as a response? I think the code gets error page or login page from the url. – Frantisek Kossuth Feb 24 '15 at 12:11
  • If I use this URL in a browser it prompts me to login (basic auth) so the response isn't the one your code expects. – Oliver Busse Feb 24 '15 at 15:52
  • Yes Line 44 is the parser.parse(... ) line. – Bitwyse1 Feb 24 '15 at 15:58
  • Oliver, what a novel idea. LOL I didn't even think about that. The site is secured..... Once I login via a browser and use that url in the browser, I do get the feed. When I run this in NetBeans it errors. I am wondering if Netbeans would it use my same headers once I'm signed in via the browser or do I have to build in some login functionality in NetBeans? – Bitwyse1 Feb 24 '15 at 15:59
  • Netbeans or another IDE: you have to provide credentials for every application, none of them will use the credentials you used in your browser. Otherwise I wouldn't call that IDE a serious one... ;-) – Oliver Busse Feb 25 '15 at 01:09

2 Answers2

1

Based on discussion the answer is: code gets loging page as a response, therefore parsing error occurs.

Possibilities:

  1. SSO configuration - study SBT SDK documentation and use SSO to authenticate.

  2. Move your code to client side - so instead processing it in SSJS/Java in the background, use some widget and JS parsing to show required information to user. That way the call will be authenticated by user's identity in browser.

Frantisek Kossuth
  • 3,524
  • 2
  • 23
  • 42
  • actually the answer is this.http://connect.lmsnet.com/files/basic/anonymous/api/documents/feed"); change to http://connect.lmsnet.com/files/basic/api/documents/feed"); – Paul Bastide Feb 25 '15 at 13:12
  • both links pop up auth dialog to me... anyway, anonymous access probably won't show relevant data – Frantisek Kossuth Feb 25 '15 at 14:07
  • then I recommend you pass in credentials using - abdera.addCredentials(realm, null, null, new UsernamePasswordCredentials(username, password)); – Paul Bastide Feb 25 '15 at 15:30
  • i wouldn't recommend to store password in sources or ask it from users... SSO is the way to go – Frantisek Kossuth Feb 25 '15 at 15:48
  • This is so frustrating to debug. I was hoping to use netbeans to simplify debugging but I suspect it is an authorization issue. I normally let the browser handle that as my xPages application requires the basic auth and handles passing the token to the rest of my code. I'll have to go back to Domino to try and debug this. Thanks all for the suggestions. – Bitwyse1 Feb 25 '15 at 19:36
  • @Frantisek, I wasn't suggesting to store the password, I was suggesting you need credentials. – Paul Bastide Feb 25 '15 at 19:37
0

apache abdera uses org.apache.axiom lib, so use that as a dependency in pom file. you can check it using another catch block It'll throw NoClassDefFoundError. this answer for help people who are looking at this.

halfelf
  • 9,737
  • 13
  • 54
  • 63
Dhanu
  • 116
  • 2
  • 3