I'm trying to create a RESTful web API with Dropwizard. I believe that I have the database connected and running properly. However whenever I try to perform a GET request for a specific item I run into an error message:
ERROR [2015-07-08 21:55:23,867]
io.dropwizard.jersey.errors.LoggingExceptionMapper: Error handling a
request: 084335cfa9b38151
! groovy.lang.MissingMethodException: No signature of method: static
edu.oregonstate.mist.catalogapitest.db.CourseDAO.findByCrn() is
applicable for argument types: (java.lang.Integer) values: [12345]
Not exactly sure, but I think it may be a Jetty issue rather than a Dropwizard problem.
Below I have included the code which I believe the problem may be.
CourseDAO.groovy
package edu.oregonstate.mist.catalogapitest.db
import edu.oregonstate.mist.catalogapitest.core.Course
import edu.oregonstate.mist.catalogapitest.mapper.CourseMapper
import org.skife.jdbi.v2.sqlobject.SqlUpdate
import org.skife.jdbi.v2.sqlobject.SqlQuery
import org.skife.jdbi.v2.sqlobject.Bind
import org.skife.jdbi.v2.sqlobject.customizers.RegisterMapper
@RegisterMapper(CourseMapper)
public interface CourseDAO extends Closeable {
@SqlQuery("""
SELECT *
FROM COURSES
WHERE CRN = :crn
""")
List<Course> findByCrn(@Bind("crn") Integer crn)
@SqlQuery("""
SELECT *
FROM COURSES
WHERE COURSENAME = :courseName
""")
List<Course> findByCourseName(@Bind("courseName") String courseName)
void close()
}
CourseResource.groovy
package edu.oregonstate.mist.catalogapitest.resources
import edu.oregonstate.mist.catalogapitest.core.Course
import edu.oregonstate.mist.catalogapitest.db.CourseDAO
import io.dropwizard.jersey.params.IntParam
import com.google.common.base.Optional
import javassist.NotFoundException
import org.eclipse.jetty.server.Response
import javax.validation.constraints.NotNull
import javax.ws.rs.Consumes
import javax.ws.rs.GET
import javax.ws.rs.POST
import javax.ws.rs.Path
import javax.ws.rs.PathParam
import javax.ws.rs.Produces
import javax.ws.rs.QueryParam
import javax.ws.rs.WebApplicationException
import javax.ws.rs.core.MediaType
@Path("/course")
@Produces(MediaType.APPLICATION_JSON)
class CourseResource {
private final CourseDAO courseDAO
public CourseResource(CourseDAO courseDAO) {
this.courseDAO = courseDAO
}
@GET
@Path('{crn}')
public List<Course> getByCrn(@PathParam('crn') IntParam crn) {
println(crn.get())
final List<Course> courses = CourseDAO.findByCrn(crn.get())
if (courses.isEmpty()) {
throw new WebApplicationException(404)
}
return courses
}
@GET
@Path('/name/{courseName}')
public List<Course> getByCourseName(@PathParam('courseName') String courseName) {
println(courseName)
final List<Course> courses = CourseDAO.findByCourseName(courseName)
if (courses.isEmpty()) {
throw new WebApplicationException(404)
}
return courses
}
}
And finally, here is a link to my repo for full reference: https://github.com/osu-mist/catalog-api-test
Thanks!
In your resource, you're trying to call static methods
In place of
final List<Course> courses = CourseDAO.findByCrn(crn.get())
You need
final List<Course> courses = courseDAO.findByCrn(crn.get())
(With a small c
in courseDAO
)