katharsis-project / katharsis.io

Katharsis project website
http://www.katharsis.io
15 stars 11 forks source link

Example doesn't start a service #4

Closed amaltson closed 9 years ago

amaltson commented 9 years ago

I'm trying to run the getting started example that seems to be fully implemented. After adding the shade plugin, I started the dropwizard app, but it doesn't look like any of the repositories are registered.

$ java -jar target/dropwizard-simple-example-0.9.0.jar server configuration.yml
...
INFO  [2015-06-04 02:36:28,967] io.dropwizard.jersey.DropwizardResourceConfig: The following paths were found for the configured resources:

    NONE
...

So when I make any http requests to the /projects resource, I just get a 404.

$ curl localhost:8080/projects
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>Error 404 Not Found</title>
</head>
<body><h2>HTTP ERROR 404</h2>
<p>Problem accessing /projects. Reason:
<pre>    Not Found</pre></p><hr><i><small>Powered by Jetty://</small></i><hr/>

</body>
</html>

The full start log:

$ java -jar target/dropwizard-simple-example-0.9.0.jar server configuration.yml
INFO  [2015-06-04 02:36:28,378] org.eclipse.jetty.util.log: Logging initialized @811ms
INFO  [2015-06-04 02:36:28,428] io.dropwizard.server.ServerFactory: Starting DropwizardService
INFO  [2015-06-04 02:36:28,478] org.eclipse.jetty.setuid.SetUIDListener: Opened DropwizardService@e84a8e1{HTTP/1.1}{0.0.0.0:8080}
INFO  [2015-06-04 02:36:28,480] org.eclipse.jetty.server.Server: jetty-9.2.z-SNAPSHOT
INFO  [2015-06-04 02:36:28,757] org.reflections.Reflections: Reflections took 118 ms to scan 1 urls, producing 2 keys and 2 values
INFO  [2015-06-04 02:36:28,817] org.reflections.Reflections: Reflections took 25 ms to scan 1 urls, producing 2 keys and 2 values
INFO  [2015-06-04 02:36:28,836] org.reflections.Reflections: Reflections took 17 ms to scan 1 urls, producing 3 keys and 10 values
INFO  [2015-06-04 02:36:28,967] io.dropwizard.jersey.DropwizardResourceConfig: The following paths were found for the configured resources:

    NONE

INFO  [2015-06-04 02:36:28,971] org.eclipse.jetty.server.handler.ContextHandler: Started i.d.j.MutableServletContextHandler@37c5fc56{/,null,AVAILABLE}
INFO  [2015-06-04 02:36:28,974] io.dropwizard.setup.AdminEnvironment: tasks =

    POST    /tasks/log-level (io.dropwizard.servlets.tasks.LogConfigurationTask)
    POST    /tasks/gc (io.dropwizard.servlets.tasks.GarbageCollectionTask)

WARN  [2015-06-04 02:36:28,974] io.dropwizard.setup.AdminEnvironment:
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!    THIS APPLICATION HAS NO HEALTHCHECKS. THIS MEANS YOU WILL NEVER KNOW      !
!     IF IT DIES IN PRODUCTION, WHICH MEANS YOU WILL NEVER KNOW IF YOU'RE      !
!    LETTING YOUR USERS DOWN. YOU SHOULD ADD A HEALTHCHECK FOR EACH OF YOUR    !
!         APPLICATION'S DEPENDENCIES WHICH FULLY (BUT LIGHTLY) TESTS IT.       !
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
INFO  [2015-06-04 02:36:28,978] org.eclipse.jetty.server.handler.ContextHandler: Started i.d.j.MutableServletContextHandler@63e5e5b4{/admin,null,AVAILABLE}
INFO  [2015-06-04 02:36:28,983] org.eclipse.jetty.server.ServerConnector: Started DropwizardService@e84a8e1{HTTP/1.1}{0.0.0.0:8080}
INFO  [2015-06-04 02:36:28,983] org.eclipse.jetty.server.Server: Started @1417ms
meshuga commented 9 years ago

Everything is working correctly, it's just content negotiation issue. Only requests that has appropriate Accept and Content-Type header are processed by Katharsis. So the command should be

$ curl localhost:8080/projects -H "Accept: application/vnd.api+json" -i
HTTP/1.1 200 OK
Content-Type: application/vnd.api+json
Date: Thu, 04 Jun 2015 10:24:02 GMT
Content-Length: 25

{"data":[],"included":[]}

Currently it isn't written in the documentation, I'll update it. Thanks for the issue!

amaltson commented 9 years ago

Huh, but according to the spec it should return a 415 not a 404. That's what threw me off. On Thu, Jun 4, 2015 at 6:31 AM Patryk Orwat notifications@github.com wrote:

Everything is working correctly, it's just content negotiation issue. Only requests that has appropriate Accept and Content-Type header are processed by Katharsis. So the command should be

$ curl localhost:8080/projects -H "Accept: application/vnd.api+json" -i HTTP/1.1 200 OK Content-Type: application/vnd.api+json Date: Thu, 04 Jun 2015 10:24:02 GMT Content-Length: 25

{"data":[],"included":[]}

Currently it isn't written in the documentation, I'll update it. Thanks for the issue!

— Reply to this email directly or view it on GitHub https://github.com/katharsis-project/katharsis.io/issues/4#issuecomment-108832882 .

amaltson commented 9 years ago

I just checked, it did work. I should have tried with the headers... my bad. Thanks!

I guess two things were confusing:

  1. Dropwizard doesn't find any resources.
  2. The spec says to return a 415 when the content type isn't supported.
meshuga commented 9 years ago

I just couldn't find any way to inform JAX-RS about the resources and 415 messages without relying on a concrete implementation e.g. Jersey (https://jersey.java.net/documentation/latest/resource-builder.html). I still think if it's good to maintain such an implementation or just provide Jersey and forget about other implementations such as RESTeasy, CXF, ... As for now I added a new issue about logging such information: https://github.com/katharsis-project/katharsis-core/issues/43