eclipse-lyo / lyo.client

Lyo project repository (lyo.client)
11 stars 16 forks source link

Unable to create a very simple resource via the new OSLC4J client #58

Closed berezovskyi closed 5 years ago

berezovskyi commented 5 years ago

I am trying to POST a new resource via a CreationFactory but the new client fails before even making a request. Here is the resource (serialised to Turtle via JMH from the POJO, so the problem should not be in the POJO or its annotations):

@prefix rdf:   <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix dcterms: <http://purl.org/dc/terms/> .
@prefix rdfs:  <http://www.w3.org/2000/01/rdf-schema#> .
@prefix oslc:  <http://open-services.net/ns/core#> .

<urn:uuid:17fcdedd-d90c-40a4-af00-2b365c26ac66>
        a       <http://ontology.cf.ericsson.net/ns/twins#PlanExecutionRequest> ;
        <http://ontology.cf.ericsson.net/pddl/plan>
                <http://sandbox-whc:8080/services/serviceProviders/default/service1/plans/2> .

Here is a 200 OK response when executing this request manually:

image

Here is the exception stack trace I am getting:

21:19:07.669 TRACE se.ericsson.cf.scott.sandbox.whc.xtra.clients.TwinClient - POSTing PlanExecutionRequest:
@prefix rdf:   <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix dcterms: <http://purl.org/dc/terms/> .
@prefix rdfs:  <http://www.w3.org/2000/01/rdf-schema#> .
@prefix oslc:  <http://open-services.net/ns/core#> .

<urn:uuid:fd616662-2164-4b2f-b503-551834a358ba>
        a       <http://ontology.cf.ericsson.net/ns/twins#PlanExecutionRequest> ;
        <http://ontology.cf.ericsson.net/pddl/plan>
                <http://sandbox-whc:8080/services/serviceProviders/default/service1/plans/1> .

21:19:07.717 DEBUG org.jvnet.hk2.logger - Created ServiceLocator ServiceLocatorImpl(__HK2_Generated_1,2,2021468806)
21:19:07.818 INFO org.glassfish.jersey.process.internal.ExecutorProviders - Selected ExecutorServiceProvider implementation [org.glassfish.jersey.client.DefaultClientAsyncExecutorProvider] to be used for injection of executor qualified by [org.glassfish.jersey.client.ClientAsyncExecutor] annotation.
21:19:07.825 INFO org.glassfish.jersey.client.internal.HttpUrlConnector - Restricted headers are not enabled using [sun.net.http.allowRestrictedHeaders] system property (setting only takes effect on connections created after the property has been set/changed).
21:19:08.059 TRACE org.eclipse.lyo.oslc4j.provider.jena.AbstractOslcRdfXmlProvider - Using 'Turtle' writer for 'text/turtle' Accept media type
21:19:08.061 DEBUG org.eclipse.lyo.oslc4j.provider.jena.JenaModelHelper - An empty reified statement was stripped from the model
21:19:08.078 TRACE org.eclipse.lyo.oslc4j.provider.jena.AbstractOslcRdfXmlProvider - Using 'Turtle' writer for 'text/turtle' Accept media type
21:19:08.083 DEBUG org.eclipse.lyo.oslc4j.provider.jena.JenaModelHelper - An empty reified statement was stripped from the model
21:19:08.089 TRACE sun.net.www.protocol.http.HttpURLConnection - ProxySelector Request for http://sandbox-twin:8081/services/twins/robot/rb-2/planExecutionRequests/create
21:19:08.104 WARN org.eclipse.lyo.oslc4j.provider.jena.AbstractOslcRdfXmlProvider - OSLC015: An error occurred serializing the resource
org.apache.jena.atlas.RuntimeIOException: java.net.ConnectException: Connection refused (Connection refused)
    at org.apache.jena.atlas.io.IO.exception(IO.java:233)
    at org.apache.jena.atlas.io.IO.flush(IO.java:250)
    at org.apache.jena.atlas.io.BufferingWriter.flush(BufferingWriter.java:153)
    at org.apache.jena.atlas.io.IO.flush(IO.java:250)
    at org.apache.jena.atlas.io.IndentedWriter.flush(IndentedWriter.java:217)
    at org.apache.jena.riot.writer.TurtleWriterBase.output$(TurtleWriterBase.java:55)
    at org.apache.jena.riot.writer.TurtleWriterBase.write(TurtleWriterBase.java:48)
    at org.apache.jena.riot.adapters.RDFWriterRIOT.write(RDFWriterRIOT.java:91)
    at org.eclipse.lyo.oslc4j.provider.jena.AbstractOslcRdfXmlProvider.writeObjectsTo(AbstractOslcRdfXmlProvider.java:159)
    at org.eclipse.lyo.oslc4j.provider.jena.AbstractOslcRdfXmlProvider.writeTo(AbstractOslcRdfXmlProvider.java:127)
    at org.eclipse.lyo.oslc4j.provider.jena.OslcRdfXmlProvider.writeTo(OslcRdfXmlProvider.java:237)
    at org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor.invokeWriteTo(WriterInterceptorExecutor.java:265)
    at org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor.aroundWriteTo(WriterInterceptorExecutor.java:250)
    at org.glassfish.jersey.message.internal.WriterInterceptorExecutor.proceed(WriterInterceptorExecutor.java:162)
    at org.glassfish.jersey.message.internal.MessageBodyFactory.writeTo(MessageBodyFactory.java:1130)
    at org.glassfish.jersey.client.ClientRequest.doWriteEntity(ClientRequest.java:517)
    at org.glassfish.jersey.client.ClientRequest.writeEntity(ClientRequest.java:499)
    at org.glassfish.jersey.client.internal.HttpUrlConnector._apply(HttpUrlConnector.java:393)
    at org.glassfish.jersey.client.internal.HttpUrlConnector.apply(HttpUrlConnector.java:285)
    at org.glassfish.jersey.client.ClientRuntime.invoke(ClientRuntime.java:252)
    at org.glassfish.jersey.client.JerseyInvocation$1.call(JerseyInvocation.java:684)
    at org.glassfish.jersey.client.JerseyInvocation$1.call(JerseyInvocation.java:681)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:228)
    at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:444)
    at org.glassfish.jersey.client.JerseyInvocation.invoke(JerseyInvocation.java:681)
    at org.glassfish.jersey.client.JerseyInvocation$Builder.method(JerseyInvocation.java:437)
    at org.glassfish.jersey.client.JerseyInvocation$Builder.post(JerseyInvocation.java:343)
    at org.eclipse.lyo.oslc4j.client.OslcClient.createResource(OslcClient.java:273)
    at org.eclipse.lyo.oslc4j.client.OslcClient.createResource(OslcClient.java:257)
    at se.ericsson.cf.scott.sandbox.whc.xtra.clients.TwinClient.requestPlanExecution(TwinClient.kt:32)
    at se.ericsson.cf.scott.sandbox.whc.xtra.managers.PlanningManager.tryRegisterPlan(PlanningManager.kt:116)
    at se.ericsson.cf.scott.sandbox.whc.xtra.managers.PlanningManager.planForTwin(PlanningManager.kt:53)
    at se.ericsson.cf.scott.sandbox.whc.xtra.managers.PlanningManager.access$planForTwin(PlanningManager.kt:25)
    at se.ericsson.cf.scott.sandbox.whc.xtra.managers.PlanningManager$planForEachTwin$1.accept(PlanningManager.kt:45)
    at se.ericsson.cf.scott.sandbox.whc.xtra.managers.PlanningManager$planForEachTwin$1.accept(PlanningManager.kt:25)
    at java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:184)
    at java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:948)
    at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
    at java.util.stream.ForEachOps$ForEachTask.compute(ForEachOps.java:291)
    at java.util.concurrent.CountedCompleter.exec(CountedCompleter.java:731)
    at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
    at java.util.concurrent.ForkJoinTask.doInvoke(ForkJoinTask.java:401)
    at java.util.concurrent.ForkJoinTask.invoke(ForkJoinTask.java:734)
    at java.util.stream.ForEachOps$ForEachOp.evaluateParallel(ForEachOps.java:160)
    at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateParallel(ForEachOps.java:174)
    at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:233)
    at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:418)
    at java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:583)
    at se.ericsson.cf.scott.sandbox.whc.xtra.managers.PlanningManager.planForEachTwin(PlanningManager.kt:44)
    at se.ericsson.cf.scott.sandbox.whc.xtra.services.AdminResource.triggerPlanning(AdminResource.kt:59)
    at se.ericsson.cf.scott.sandbox.whc.xtra.services.AdminResource$plan$1.invoke(AdminResource.kt:39)
    at se.ericsson.cf.scott.sandbox.whc.xtra.services.AdminResource$plan$1.invoke(AdminResource.kt:23)
    at se.ericsson.cf.scott.sandbox.whc.xtra.services.AdminResource$runAsync$1.run(AdminResource.kt:48)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
Caused by: java.net.ConnectException: Connection refused (Connection refused)
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
    at java.net.Socket.connect(Socket.java:589)
    at sun.net.NetworkClient.doConnect(NetworkClient.java:175)
    at sun.net.www.http.HttpClient.openServer(HttpClient.java:463)
    at sun.net.www.http.HttpClient.openServer(HttpClient.java:558)
    at sun.net.www.http.HttpClient.<init>(HttpClient.java:242)
    at sun.net.www.http.HttpClient.New(HttpClient.java:339)
    at sun.net.www.http.HttpClient.New(HttpClient.java:357)
    at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:1220)
    at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1156)
    at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:1050)
    at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:984)
    at sun.net.www.protocol.http.HttpURLConnection.getOutputStream0(HttpURLConnection.java:1334)
    at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1309)
    at org.glassfish.jersey.client.internal.HttpUrlConnector$4.getOutputStream(HttpUrlConnector.java:390)
    at org.glassfish.jersey.message.internal.CommittingOutputStream.commitStream(CommittingOutputStream.java:200)
    at org.glassfish.jersey.message.internal.CommittingOutputStream.commitStream(CommittingOutputStream.java:194)
    at org.glassfish.jersey.message.internal.CommittingOutputStream.write(CommittingOutputStream.java:228)
    at org.glassfish.jersey.message.internal.WriterInterceptorExecutor$UnCloseableOutputStream.write(WriterInterceptorExecutor.java:299)
    at sun.nio.cs.StreamEncoder.writeBytes(StreamEncoder.java:221)
    at sun.nio.cs.StreamEncoder.implFlushBuffer(StreamEncoder.java:291)
    at sun.nio.cs.StreamEncoder.implFlush(StreamEncoder.java:295)
    at sun.nio.cs.StreamEncoder.flush(StreamEncoder.java:141)
    at java.io.OutputStreamWriter.flush(OutputStreamWriter.java:229)
    ... 61 more
berezovskyi commented 5 years ago

This all makes very little sense to me. @jamsden @jadelkhoury did you have anything like that before? I am really at loss here because this is supposed to be a very simple request, a very simple POJO just a single Link property. And it's the first time I encounter the org.apache.jena.atlas.RuntimeIOException.

berezovskyi commented 5 years ago

Here is a "new" stack trace, cleaned up by the patch from https://github.com/eclipse/lyo.core/pull/93

21:43:18.132 ERROR se.ericsson.cf.scott.sandbox.whc.xtra.managers.PlanningManager - Unexpected exception while creating a plan for Twin 'rb-1':
javax.ws.rs.ProcessingException: java.net.ConnectException: Connection refused (Connection refused)
    at org.glassfish.jersey.client.ClientRuntime.invoke(ClientRuntime.java:261)
    at org.glassfish.jersey.client.JerseyInvocation$1.call(JerseyInvocation.java:684)
    at org.glassfish.jersey.client.JerseyInvocation$1.call(JerseyInvocation.java:681)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:228)
    at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:444)
    at org.glassfish.jersey.client.JerseyInvocation.invoke(JerseyInvocation.java:681)
    at org.glassfish.jersey.client.JerseyInvocation$Builder.method(JerseyInvocation.java:437)
    at org.glassfish.jersey.client.JerseyInvocation$Builder.post(JerseyInvocation.java:343)
    at org.eclipse.lyo.oslc4j.client.OslcClient.createResource(OslcClient.java:273)
    at org.eclipse.lyo.oslc4j.client.OslcClient.createResource(OslcClient.java:257)
    at se.ericsson.cf.scott.sandbox.whc.xtra.clients.TwinClient.requestPlanExecution(TwinClient.kt:32)
    at se.ericsson.cf.scott.sandbox.whc.xtra.managers.PlanningManager.tryRegisterPlan(PlanningManager.kt:116)
    at se.ericsson.cf.scott.sandbox.whc.xtra.managers.PlanningManager.planForTwin(PlanningManager.kt:53)
    at se.ericsson.cf.scott.sandbox.whc.xtra.managers.PlanningManager.access$planForTwin(PlanningManager.kt:25)
    at se.ericsson.cf.scott.sandbox.whc.xtra.managers.PlanningManager$planForEachTwin$1.accept(PlanningManager.kt:45)
    at se.ericsson.cf.scott.sandbox.whc.xtra.managers.PlanningManager$planForEachTwin$1.accept(PlanningManager.kt:25)
    at java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:184)
    at java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:948)
    at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
    at java.util.stream.ForEachOps$ForEachTask.compute(ForEachOps.java:291)
    at java.util.concurrent.CountedCompleter.exec(CountedCompleter.java:731)
    at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
    at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
    at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
    at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
Caused by: java.lang.IllegalStateException: java.net.ConnectException: Connection refused (Connection refused)
    at org.eclipse.lyo.oslc4j.provider.jena.AbstractOslcRdfXmlProvider.writeObjectsTo(AbstractOslcRdfXmlProvider.java:166)
    at org.eclipse.lyo.oslc4j.provider.jena.AbstractOslcRdfXmlProvider.writeTo(AbstractOslcRdfXmlProvider.java:127)
    at org.eclipse.lyo.oslc4j.provider.jena.OslcRdfXmlProvider.writeTo(OslcRdfXmlProvider.java:237)
    at org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor.invokeWriteTo(WriterInterceptorExecutor.java:265)
    at org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor.aroundWriteTo(WriterInterceptorExecutor.java:250)
    at org.glassfish.jersey.message.internal.WriterInterceptorExecutor.proceed(WriterInterceptorExecutor.java:162)
    at org.glassfish.jersey.message.internal.MessageBodyFactory.writeTo(MessageBodyFactory.java:1130)
    at org.glassfish.jersey.client.ClientRequest.doWriteEntity(ClientRequest.java:517)
    at org.glassfish.jersey.client.ClientRequest.writeEntity(ClientRequest.java:499)
    at org.glassfish.jersey.client.internal.HttpUrlConnector._apply(HttpUrlConnector.java:393)
    at org.glassfish.jersey.client.internal.HttpUrlConnector.apply(HttpUrlConnector.java:285)
    at org.glassfish.jersey.client.ClientRuntime.invoke(ClientRuntime.java:252)
    ... 26 more
Caused by: java.net.ConnectException: Connection refused (Connection refused)
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
    at java.net.Socket.connect(Socket.java:589)
    at sun.net.NetworkClient.doConnect(NetworkClient.java:175)
    at sun.net.www.http.HttpClient.openServer(HttpClient.java:463)
    at sun.net.www.http.HttpClient.openServer(HttpClient.java:558)
    at sun.net.www.http.HttpClient.<init>(HttpClient.java:242)
    at sun.net.www.http.HttpClient.New(HttpClient.java:339)
    at sun.net.www.http.HttpClient.New(HttpClient.java:357)
    at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:1220)
    at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1156)
    at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:1050)
    at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:984)
    at sun.net.www.protocol.http.HttpURLConnection.getOutputStream0(HttpURLConnection.java:1334)
    at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1309)
    at org.glassfish.jersey.client.internal.HttpUrlConnector$4.getOutputStream(HttpUrlConnector.java:390)
    at org.glassfish.jersey.message.internal.CommittingOutputStream.commitStream(CommittingOutputStream.java:200)
    at org.glassfish.jersey.message.internal.CommittingOutputStream.commitStream(CommittingOutputStream.java:194)
    at org.glassfish.jersey.message.internal.CommittingOutputStream.write(CommittingOutputStream.java:213)
    at org.glassfish.jersey.message.internal.WriterInterceptorExecutor$UnCloseableOutputStream.write(WriterInterceptorExecutor.java:294)
    at org.eclipse.lyo.oslc4j.provider.jena.AbstractOslcRdfXmlProvider.writeObjectsTo(AbstractOslcRdfXmlProvider.java:157)
    ... 37 more
berezovskyi commented 5 years ago

Apologies, problem solved. The second trace had less noise and I went to double-check the URI and it turned out to be wrong (Docker vs host network addressing issues).

But now I think it might be a very common problem and we shall catch java.net.ConnectException separately and either throw it directly or wrap it in something like OslcClientConnectionException

jadelkhoury commented 5 years ago

@berezovskyi should get some sleep before debugging such simple exceptions. won't fix.