Search code examples
tomcatjakarta-eenetbeanssesame

Sesame API call throwing an IOException


I am writing a program in Java to consume the services of Sesame but when I call Login:

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {        
     try {

    URL sesameurl = new URL("http://localhost:8080/openrdf-sesame");
    SesameService service = Sesame.getService(sesameurl);         
        service.login("username", "password");
        service.getRepositoryList();            
               } 
    catch (UnknownRepositoryException ex) {
        Logger.getLogger(Sparqlquery.class.getName()).log(Level.SEVERE, null, ex);
    } catch (ConfigurationException ex) {
        Logger.getLogger(Sparqlquery.class.getName()).log(Level.SEVERE, null, ex);
    }        catch (AccessDeniedException ex) {
        Logger.getLogger(Sparqlquery.class.getName()).log(Level.SEVERE, null, ex);
    }      
    PrintWriter write = response.getWriter();         
} 

it throws the following error:

HTTP Status 500 -

type Exception report

message

descriptionThe server encountered an internal error () that prevented it from fulfilling this request.

exception

java.io.IOException: http://localhost:8080/openrdf-sesame/servlets/login: Not Found

note The full stack traces of the exception and its root causes are available in the GlassFish Server Open Source Edition 3.1.1 logs. GlassFish Server Open Source Edition 3.1.1


Solution

  • I am not sure where you got this code example from, but the classes SesameService, Sparqlquery, or UnknownRepositoryException do not exist in Sesame 2.

    You are either using a very old version of Sesame (1.x, which is no longer supported and has not been since at least 2007), or you are using some third-party wrapper library.

    Make sure you are using a recent version of Sesame (latest stable release can be found on the website).

    The correct/current way to connect to a Sesame Server is as follows:

     // connect to the server
     String serverUrl = "http://localhost:8080/openrdf-sesame";
     RepositoryManager manager = RepositoryProvider.getRepositoryManager(serverUrl);
    
     // get a list of the ids of all existing repositories
     List<String> ids = manager.getRepositoryIDs();
    
     // open a repository with a known identifier, e.g. "test"
     Repository rep = manager.getRepository("test");
    

    And so on. For further details on how to work with Sesame, see the documentation available on the Sesame website, in particular the tutorial, the chapter "Programming with Sesame", and the API Javadoc.