You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Mohamed Morsey <mo...@gmail.com> on 2020/01/06 11:05:54 UTC

Problem with Fuseki Server in Unit Tests

Hi all,

I have a problem with getting Fuseki server working with unit tests.

What I do is the following:
1- Create and start Fuseki server via the following piece of code:




*fusekiServer = FusekiServer.create().add("/sparql",
DatasetFactory.create(ModelFactory.createDefaultModel())).port(9090).build();fusekiServer.start();*

2- Load data as follows:


*try (RDFConnection conn =
RDFConnectionFactory.connect("http://localhost:9090/sparql
<http://localhost:9090/sparql>")) {*
*conn.load(dataModel);**}*

3- I can then send SPARQL queries to that endpoint.

This works fine in runtime. However, in unit tests mode I get
"org.apache.jena.atlas.web.HttpException" exception with message "500 -
Server Error" when loading the data.
Further, if I try to send a query I get
"org.apache.jena.sparql.engine.http.QueryExceptionHTTP" exception." with
message "HTTP 500 error making the query: Server Error".

Can you please help me out with this?
Thank you!
kind regards,
Mohamed Morsey

Re: Problem with Fuseki Server in Unit Tests

Posted by Mohamed Morsey <mo...@gmail.com>.
Hi Andy,

thank you for the prompt reply.

I'm using version 3.12.0.

Currently, I managed to enable logging and checking if I can fix the
problem myself. I could not fix the problem myself, I'll get back with
further questions.

Kind regards,
Mohamed Morsey

On Mon, Jan 6, 2020 at 12:22 PM Andy Seaborne <an...@apache.org> wrote:

> Hi there,
>
> Which version are you running?
>
> What does the server log say? It logs all requests - you may need
>
>     static { FusekiLogging.setLogging(); }
>
> in your test class and make sure you haven't turned off logginbg by
> level with log4j.properties somewhere.
>
>      Andy
>
> On 06/01/2020 11:05, Mohamed Morsey wrote:
> > Hi all,
> >
> > I have a problem with getting Fuseki server working with unit tests.
> >
> > What I do is the following:
> > 1- Create and start Fuseki server via the following piece of code:
> >
> >
> >
> >
> > *fusekiServer = FusekiServer.create().add("/sparql",
> >
> DatasetFactory.create(ModelFactory.createDefaultModel())).port(9090).build();fusekiServer.start();*
> >
> > 2- Load data as follows:
> >
> >
> > *try (RDFConnection conn =
> > RDFConnectionFactory.connect("http://localhost:9090/sparql
> > <http://localhost:9090/sparql>")) {*
> > *conn.load(dataModel);**}*
> >
> > 3- I can then send SPARQL queries to that endpoint.
> >
> > This works fine in runtime. However, in unit tests mode I get
> > "org.apache.jena.atlas.web.HttpException" exception with message "500 -
> > Server Error" when loading the data.
> > Further, if I try to send a query I get
> > "org.apache.jena.sparql.engine.http.QueryExceptionHTTP" exception." with
> > message "HTTP 500 error making the query: Server Error".
> >
> > Can you please help me out with this?
> > Thank you!
> > kind regards,
> > Mohamed Morsey
> >
>

Re: Problem with Fuseki Server in Unit Tests

Posted by Andy Seaborne <an...@apache.org>.

On 07/01/2020 10:09, Mohamed Morsey wrote:
> Hi,
> 
> Yes sure.
> The conflicting dependencies were in my own project not in Fuseki.
> 
> Following dependencies were conflicting:
> 
>     1.
> 
> 
> 
> *<dependency>       <groupId>org.mortbay.jetty</groupId>
>     <artifactId>servlet-api</artifactId>       <version>2.5-20081211</version>


Thanks for the background.

Fuseki is compiled against 9.4.12.v20180830.

https://github.com/apache/jena/blob/master/jena-fuseki2/pom.xml

>      </dependency>*
>     2.
> 
> 
> 
> 
> *<dependency>         <groupId>javax.servlet</groupId>
>     <artifactId>javax.servlet-api</artifactId>         <version>3.1.0</version>
>     </dependency> *
> 
> Both of the then provide interface *javax.servlet.http.HttpServletRequest*
> but with different versions, and the older version does not have method
> *getServletContext*. Thus, I had to move the second dependency to appear
> first in the pom file. Later, I totally removed the other dependency, and
> the application worked fine.
> 
> The thing that makes me puzzled is that the correct dependency was picked
> up correctly at runtime but not in test.
> 
> Regards,
> Mohamed
> 
> 
> On Tue, Jan 7, 2020 at 10:57 AM Andy Seaborne <an...@apache.org> wrote:
> 
>>
>>
>> On 07/01/2020 08:35, Mohamed Morsey wrote:
>>> Hi Andy,
>>>
>>> thank you for help.
>>>
>>> I got it working now. It was a dependency problem. The order of
>>> dependencies in POM file caused that problem.
>>
>> Could you say some more about the details in case something similar
>> happens to someone else?
>>
>> What things were in the wrong order? For fuseki-server there is only one
>> provider of each dependency/interface. Was it something else included
>> for another part of your project?
>>
>>       Andy
>>
>>>
>>> Regards,
>>> Mohamed
>>>
>>> On Mon, Jan 6, 2020 at 6:08 PM Andy Seaborne <an...@apache.org> wrote:
>>>
>>>> I ran Fuseki and put a break point on the filter call - I get the same
>>>> stacktrace.
>>>>
>>>> So something in the test setup is interfering - "mvn dependency:tree"
>>>> may show something if it's a maven project.
>>>>
>>>> Is this openjdk for the Java JVM?
>>>>
>>>> As it works one way but not in "test" it does rather look like some
>>>> other code is providing the implementation of "HttpServletRequest"
>>>> somehow but from the information on the thread, I can't see how.
>>>>
>>>>        Andy
>>>>
>>>
>>
> 

Re: Problem with Fuseki Server in Unit Tests

Posted by Mohamed Morsey <mo...@gmail.com>.
Hi,

Yes sure.
The conflicting dependencies were in my own project not in Fuseki.

Following dependencies were conflicting:

   1.



*<dependency>       <groupId>org.mortbay.jetty</groupId>
   <artifactId>servlet-api</artifactId>       <version>2.5-20081211</version>
    </dependency>*
   2.




*<dependency>         <groupId>javax.servlet</groupId>
   <artifactId>javax.servlet-api</artifactId>         <version>3.1.0</version>
   </dependency> *

Both of the then provide interface *javax.servlet.http.HttpServletRequest*
but with different versions, and the older version does not have method
*getServletContext*. Thus, I had to move the second dependency to appear
first in the pom file. Later, I totally removed the other dependency, and
the application worked fine.

The thing that makes me puzzled is that the correct dependency was picked
up correctly at runtime but not in test.

Regards,
Mohamed


On Tue, Jan 7, 2020 at 10:57 AM Andy Seaborne <an...@apache.org> wrote:

>
>
> On 07/01/2020 08:35, Mohamed Morsey wrote:
> > Hi Andy,
> >
> > thank you for help.
> >
> > I got it working now. It was a dependency problem. The order of
> > dependencies in POM file caused that problem.
>
> Could you say some more about the details in case something similar
> happens to someone else?
>
> What things were in the wrong order? For fuseki-server there is only one
> provider of each dependency/interface. Was it something else included
> for another part of your project?
>
>      Andy
>
> >
> > Regards,
> > Mohamed
> >
> > On Mon, Jan 6, 2020 at 6:08 PM Andy Seaborne <an...@apache.org> wrote:
> >
> >> I ran Fuseki and put a break point on the filter call - I get the same
> >> stacktrace.
> >>
> >> So something in the test setup is interfering - "mvn dependency:tree"
> >> may show something if it's a maven project.
> >>
> >> Is this openjdk for the Java JVM?
> >>
> >> As it works one way but not in "test" it does rather look like some
> >> other code is providing the implementation of "HttpServletRequest"
> >> somehow but from the information on the thread, I can't see how.
> >>
> >>       Andy
> >>
> >
>

Re: Problem with Fuseki Server in Unit Tests

Posted by Andy Seaborne <an...@apache.org>.

On 07/01/2020 08:35, Mohamed Morsey wrote:
> Hi Andy,
> 
> thank you for help.
> 
> I got it working now. It was a dependency problem. The order of
> dependencies in POM file caused that problem.

Could you say some more about the details in case something similar 
happens to someone else?

What things were in the wrong order? For fuseki-server there is only one 
provider of each dependency/interface. Was it something else included 
for another part of your project?

     Andy

> 
> Regards,
> Mohamed
> 
> On Mon, Jan 6, 2020 at 6:08 PM Andy Seaborne <an...@apache.org> wrote:
> 
>> I ran Fuseki and put a break point on the filter call - I get the same
>> stacktrace.
>>
>> So something in the test setup is interfering - "mvn dependency:tree"
>> may show something if it's a maven project.
>>
>> Is this openjdk for the Java JVM?
>>
>> As it works one way but not in "test" it does rather look like some
>> other code is providing the implementation of "HttpServletRequest"
>> somehow but from the information on the thread, I can't see how.
>>
>>       Andy
>>
> 

Re: Problem with Fuseki Server in Unit Tests

Posted by Mohamed Morsey <mo...@gmail.com>.
Hi Andy,

thank you for help.

I got it working now. It was a dependency problem. The order of
dependencies in POM file caused that problem.

Regards,
Mohamed

On Mon, Jan 6, 2020 at 6:08 PM Andy Seaborne <an...@apache.org> wrote:

> I ran Fuseki and put a break point on the filter call - I get the same
> stacktrace.
>
> So something in the test setup is interfering - "mvn dependency:tree"
> may show something if it's a maven project.
>
> Is this openjdk for the Java JVM?
>
> As it works one way but not in "test" it does rather look like some
> other code is providing the implementation of "HttpServletRequest"
> somehow but from the information on the thread, I can't see how.
>
>      Andy
>

Re: Problem with Fuseki Server in Unit Tests

Posted by Andy Seaborne <an...@apache.org>.
I ran Fuseki and put a break point on the filter call - I get the same 
stacktrace.

So something in the test setup is interfering - "mvn dependency:tree" 
may show something if it's a maven project.

Is this openjdk for the Java JVM?

As it works one way but not in "test" it does rather look like some 
other code is providing the implementation of "HttpServletRequest" 
somehow but from the information on the thread, I can't see how.

     Andy

Re: Problem with Fuseki Server in Unit Tests

Posted by Mohamed Morsey <mo...@gmail.com>.
Hi,
Following is the stack trace:

java.lang.NoSuchMethodError: 'javax.servlet.ServletContext
javax.servlet.http.HttpServletRequest.getServletContext()'
at org.apache.jena.fuseki.servlets.ActionLib.actionURI(ActionLib.java:161)
~[jena-fuseki-core-3.12.0.jar:3.12.0]
at
org.apache.jena.fuseki.servlets.FusekiFilter.doFilter(FusekiFilter.java:56)
~[jena-fuseki-core-3.12.0.jar:3.12.0]
at
org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1642)
~[jetty-servlet-9.4.12.v20180830.jar:9.4.12.v20180830]
at
org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:533)
~[jetty-servlet-9.4.12.v20180830.jar:9.4.12.v20180830]
at
org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:255)
~[jetty-server-9.4.12.v20180830.jar:9.4.12.v20180830]
at
org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1340)
~[jetty-server-9.4.12.v20180830.jar:9.4.12.v20180830]
at
org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:203)
~[jetty-server-9.4.12.v20180830.jar:9.4.12.v20180830]
at
org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:473)
~[jetty-servlet-9.4.12.v20180830.jar:9.4.12.v20180830]
at
org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:201)
~[jetty-server-9.4.12.v20180830.jar:9.4.12.v20180830]
at
org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1242)
~[jetty-server-9.4.12.v20180830.jar:9.4.12.v20180830]
at
org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:144)
~[jetty-server-9.4.12.v20180830.jar:9.4.12.v20180830]
at
org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
~[jetty-server-9.4.12.v20180830.jar:9.4.12.v20180830]
at org.eclipse.jetty.server.Server.handle(Server.java:503)
~[jetty-server-9.4.12.v20180830.jar:9.4.12.v20180830]
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:364)
[jetty-server-9.4.12.v20180830.jar:9.4.12.v20180830]
at
org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:260)
[jetty-server-9.4.12.v20180830.jar:9.4.12.v20180830]
at
org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:305)
[jetty-io-9.4.12.v20180830.jar:9.4.12.v20180830]
at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:103)
[jetty-io-9.4.12.v20180830.jar:9.4.12.v20180830]
at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:118)
[jetty-io-9.4.12.v20180830.jar:9.4.12.v20180830]
at
org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:765)
[jetty-util-9.4.12.v20180830.jar:9.4.12.v20180830]
at
org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:683)
[jetty-util-9.4.12.v20180830.jar:9.4.12.v20180830]
at java.lang.Thread.run(Thread.java:834) [?:?]

Regards,
Mohamed

On Mon, Jan 6, 2020 at 5:17 PM Andy Seaborne <an...@apache.org> wrote:

>
>
> On 06/01/2020 15:28, Mohamed Morsey wrote:
> > Hi An,
> >
> > now I did some investigation for the problem and now I get exception
> > "java.lang.NoSuchMethodError: 'javax.servlet.ServletContext
> > javax.servlet.http.HttpServletRequest.getServletContext()". This
> exception
> > indicates that there is a problem with dependency "*javax.servlet-api*".
> >
> > This dependency is added to the pom already and it is the same version
> used
> > by Fuseki which is "3.1.0".
> >
> > Do you have a clue  on how this problem can be resolved?
>
> What is the stacktrace for this?
>
> javax.servlet.http.HttpServletRequest is an interface - there needs to
> be an implementation at runtime. It should come from Eclipse Jetty for
> FusekiServer.
>
> NoSuchMethodError means that the runtime does not have the method but
> the compile time did.
>
> There are quite a few reasons this java Error is thrown.
>
> It can be because there are multiple jars containing the same classes on
> the runtime classpath as well as no suitable jar at runtime.
>
>      Andy
>
> >
> > Thank you!
> > Regards,
> > Mohamed
> >
> > On Mon, Jan 6, 2020 at 12:22 PM Andy Seaborne <an...@apache.org> wrote:
> >
> >> Hi there,
> >>
> >> Which version are you running?
> >>
> >> What does the server log say? It logs all requests - you may need
> >>
> >>      static { FusekiLogging.setLogging(); }
> >>
> >> in your test class and make sure you haven't turned off logginbg by
> >> level with log4j.properties somewhere.
> >>
> >>       Andy
> >>
> >> On 06/01/2020 11:05, Mohamed Morsey wrote:
> >>> Hi all,
> >>>
> >>> I have a problem with getting Fuseki server working with unit tests.
> >>>
> >>> What I do is the following:
> >>> 1- Create and start Fuseki server via the following piece of code:
> >>>
> >>>
> >>>
> >>>
> >>> *fusekiServer = FusekiServer.create().add("/sparql",
> >>>
> >>
> DatasetFactory.create(ModelFactory.createDefaultModel())).port(9090).build();fusekiServer.start();*
> >>>
> >>> 2- Load data as follows:
> >>>
> >>>
> >>> *try (RDFConnection conn =
> >>> RDFConnectionFactory.connect("http://localhost:9090/sparql
> >>> <http://localhost:9090/sparql>")) {*
> >>> *conn.load(dataModel);**}*
> >>>
> >>> 3- I can then send SPARQL queries to that endpoint.
> >>>
> >>> This works fine in runtime. However, in unit tests mode I get
> >>> "org.apache.jena.atlas.web.HttpException" exception with message "500 -
> >>> Server Error" when loading the data.
> >>> Further, if I try to send a query I get
> >>> "org.apache.jena.sparql.engine.http.QueryExceptionHTTP" exception."
> with
> >>> message "HTTP 500 error making the query: Server Error".
> >>>
> >>> Can you please help me out with this?
> >>> Thank you!
> >>> kind regards,
> >>> Mohamed Morsey
> >>>
> >>
> >
>

Re: Problem with Fuseki Server in Unit Tests

Posted by Andy Seaborne <an...@apache.org>.

On 06/01/2020 15:28, Mohamed Morsey wrote:
> Hi An,
> 
> now I did some investigation for the problem and now I get exception
> "java.lang.NoSuchMethodError: 'javax.servlet.ServletContext
> javax.servlet.http.HttpServletRequest.getServletContext()". This exception
> indicates that there is a problem with dependency "*javax.servlet-api*".
> 
> This dependency is added to the pom already and it is the same version used
> by Fuseki which is "3.1.0".
> 
> Do you have a clue  on how this problem can be resolved?

What is the stacktrace for this?

javax.servlet.http.HttpServletRequest is an interface - there needs to 
be an implementation at runtime. It should come from Eclipse Jetty for 
FusekiServer.

NoSuchMethodError means that the runtime does not have the method but 
the compile time did.

There are quite a few reasons this java Error is thrown.

It can be because there are multiple jars containing the same classes on 
the runtime classpath as well as no suitable jar at runtime.

     Andy

> 
> Thank you!
> Regards,
> Mohamed
> 
> On Mon, Jan 6, 2020 at 12:22 PM Andy Seaborne <an...@apache.org> wrote:
> 
>> Hi there,
>>
>> Which version are you running?
>>
>> What does the server log say? It logs all requests - you may need
>>
>>      static { FusekiLogging.setLogging(); }
>>
>> in your test class and make sure you haven't turned off logginbg by
>> level with log4j.properties somewhere.
>>
>>       Andy
>>
>> On 06/01/2020 11:05, Mohamed Morsey wrote:
>>> Hi all,
>>>
>>> I have a problem with getting Fuseki server working with unit tests.
>>>
>>> What I do is the following:
>>> 1- Create and start Fuseki server via the following piece of code:
>>>
>>>
>>>
>>>
>>> *fusekiServer = FusekiServer.create().add("/sparql",
>>>
>> DatasetFactory.create(ModelFactory.createDefaultModel())).port(9090).build();fusekiServer.start();*
>>>
>>> 2- Load data as follows:
>>>
>>>
>>> *try (RDFConnection conn =
>>> RDFConnectionFactory.connect("http://localhost:9090/sparql
>>> <http://localhost:9090/sparql>")) {*
>>> *conn.load(dataModel);**}*
>>>
>>> 3- I can then send SPARQL queries to that endpoint.
>>>
>>> This works fine in runtime. However, in unit tests mode I get
>>> "org.apache.jena.atlas.web.HttpException" exception with message "500 -
>>> Server Error" when loading the data.
>>> Further, if I try to send a query I get
>>> "org.apache.jena.sparql.engine.http.QueryExceptionHTTP" exception." with
>>> message "HTTP 500 error making the query: Server Error".
>>>
>>> Can you please help me out with this?
>>> Thank you!
>>> kind regards,
>>> Mohamed Morsey
>>>
>>
> 

Re: Problem with Fuseki Server in Unit Tests

Posted by Mohamed Morsey <mo...@gmail.com>.
Hi An,

now I did some investigation for the problem and now I get exception
"java.lang.NoSuchMethodError: 'javax.servlet.ServletContext
javax.servlet.http.HttpServletRequest.getServletContext()". This exception
indicates that there is a problem with dependency "*javax.servlet-api*".

This dependency is added to the pom already and it is the same version used
by Fuseki which is "3.1.0".

Do you have a clue  on how this problem can be resolved?

Thank you!
Regards,
Mohamed

On Mon, Jan 6, 2020 at 12:22 PM Andy Seaborne <an...@apache.org> wrote:

> Hi there,
>
> Which version are you running?
>
> What does the server log say? It logs all requests - you may need
>
>     static { FusekiLogging.setLogging(); }
>
> in your test class and make sure you haven't turned off logginbg by
> level with log4j.properties somewhere.
>
>      Andy
>
> On 06/01/2020 11:05, Mohamed Morsey wrote:
> > Hi all,
> >
> > I have a problem with getting Fuseki server working with unit tests.
> >
> > What I do is the following:
> > 1- Create and start Fuseki server via the following piece of code:
> >
> >
> >
> >
> > *fusekiServer = FusekiServer.create().add("/sparql",
> >
> DatasetFactory.create(ModelFactory.createDefaultModel())).port(9090).build();fusekiServer.start();*
> >
> > 2- Load data as follows:
> >
> >
> > *try (RDFConnection conn =
> > RDFConnectionFactory.connect("http://localhost:9090/sparql
> > <http://localhost:9090/sparql>")) {*
> > *conn.load(dataModel);**}*
> >
> > 3- I can then send SPARQL queries to that endpoint.
> >
> > This works fine in runtime. However, in unit tests mode I get
> > "org.apache.jena.atlas.web.HttpException" exception with message "500 -
> > Server Error" when loading the data.
> > Further, if I try to send a query I get
> > "org.apache.jena.sparql.engine.http.QueryExceptionHTTP" exception." with
> > message "HTTP 500 error making the query: Server Error".
> >
> > Can you please help me out with this?
> > Thank you!
> > kind regards,
> > Mohamed Morsey
> >
>

Re: Problem with Fuseki Server in Unit Tests

Posted by Andy Seaborne <an...@apache.org>.
Hi there,

Which version are you running?

What does the server log say? It logs all requests - you may need

    static { FusekiLogging.setLogging(); }

in your test class and make sure you haven't turned off logginbg by 
level with log4j.properties somewhere.

     Andy

On 06/01/2020 11:05, Mohamed Morsey wrote:
> Hi all,
> 
> I have a problem with getting Fuseki server working with unit tests.
> 
> What I do is the following:
> 1- Create and start Fuseki server via the following piece of code:
> 
> 
> 
> 
> *fusekiServer = FusekiServer.create().add("/sparql",
> DatasetFactory.create(ModelFactory.createDefaultModel())).port(9090).build();fusekiServer.start();*
> 
> 2- Load data as follows:
> 
> 
> *try (RDFConnection conn =
> RDFConnectionFactory.connect("http://localhost:9090/sparql
> <http://localhost:9090/sparql>")) {*
> *conn.load(dataModel);**}*
> 
> 3- I can then send SPARQL queries to that endpoint.
> 
> This works fine in runtime. However, in unit tests mode I get
> "org.apache.jena.atlas.web.HttpException" exception with message "500 -
> Server Error" when loading the data.
> Further, if I try to send a query I get
> "org.apache.jena.sparql.engine.http.QueryExceptionHTTP" exception." with
> message "HTTP 500 error making the query: Server Error".
> 
> Can you please help me out with this?
> Thank you!
> kind regards,
> Mohamed Morsey
>