Monday, 15 April 2013

java - Dropwizard not accepting @PathParam for pojo objects -



java - Dropwizard not accepting @PathParam for pojo objects -

i using dropwizard micro service . want pass object @ receiving end .

@get @path("/run") public string runreport( @pathparam(value = "report") study report){ homecoming "report service running: status good"; }

here study simple pojo defined

@jsonignoreproperties(ignoreunknown = true) public class study { private static final long serialversionuid = -558913649l; /** hashcode temporary storage. */ private volatile integer hashcode; /** field mapping. */ private string description; }

i using dropwizard version 0.7.1

but when seek run programme eclipse . gives me error.do need add together external jar here . presumed drop-wizard everything. , when alter pathparam study simple long runs ok

error [2014-10-27 18:24:54,792] com.sun.jersey.spi.inject.errors: next errors , warnings have been detected resource and/or provider classes: severe: missing dependency method public java.lang.string com.sdata.report.resources.reportresource.runreport(com.sdata.report.resources.report) @ parameter @ index 0 exception in thread "main" javax.servlet.servletexception: com.sun.jersey.spi.container.servlet.servletcontainer- 68792330@565a8b6c==com.sun.jersey.spi.container.servlet.servletcontainer,1,false @ org.eclipse.jetty.servlet.servletholder.initservlet(servletholder.java:561) @ org.eclipse.jetty.servlet.servletholder.initialize(servletholder.java:349) @ org.eclipse.jetty.servlet.servlethandler.initialize(servlethandler.java:812) @ org.eclipse.jetty.servlet.servletcontexthandler.startcontext(servletcontexthandler.java:288) @ org.eclipse.jetty.server.handler.contexthandler.dostart(contexthandler.java:732) @ org.eclipse.jetty.util.component.abstractlifecycle.start(abstractlifecycle.java:69) @ org.eclipse.jetty.util.component.containerlifecycle.start(containerlifecycle.java:118) @ org.eclipse.jetty.util.component.containerlifecycle.dostart(containerlifecycle.java:100) @ org.eclipse.jetty.server.handler.abstracthandler.dostart(abstracthandler.java:60) @ com.codahale.metrics.jetty9.instrumentedhandler.dostart(instrumentedhandler.java:92) @ org.eclipse.jetty.util.component.abstractlifecycle.start(abstractlifecycle.java:69) @ org.eclipse.jetty.util.component.containerlifecycle.start(containerlifecycle.java:118) @ org.eclipse.jetty.util.component.containerlifecycle.dostart(containerlifecycle.java:100) @ org.eclipse.jetty.server.handler.abstracthandler.dostart(abstracthandler.java:60) @ org.eclipse.jetty.util.component.abstractlifecycle.start(abstractlifecycle.java:69) @ org.eclipse.jetty.util.component.containerlifecycle.start(containerlifecycle.java:118) @ org.eclipse.jetty.util.component.containerlifecycle.dostart(containerlifecycle.java:100) @ org.eclipse.jetty.server.handler.abstracthandler.dostart(abstracthandler.java:60) @ org.eclipse.jetty.server.handler.requestloghandler.dostart(requestloghandler.java:131) @ org.eclipse.jetty.util.component.abstractlifecycle.start(abstractlifecycle.java:69) @ org.eclipse.jetty.util.component.containerlifecycle.start(containerlifecycle.java:118) @ org.eclipse.jetty.util.component.containerlifecycle.dostart(containerlifecycle.java:100) @ org.eclipse.jetty.server.handler.abstracthandler.dostart(abstracthandler.java:60) @ org.eclipse.jetty.server.handler.statisticshandler.dostart(statisticshandler.java:233) @ org.eclipse.jetty.util.component.abstractlifecycle.start(abstractlifecycle.java:69) @ org.eclipse.jetty.util.component.containerlifecycle.start(containerlifecycle.java:118) @ org.eclipse.jetty.server.server.start(server.java:342) @ org.eclipse.jetty.util.component.containerlifecycle.dostart(containerlifecycle.java:100) @ org.eclipse.jetty.server.handler.abstracthandler.dostart(abstracthandler.java:60) @ org.eclipse.jetty.server.server.dostart(server.java:290) @ org.eclipse.jetty.util.component.abstractlifecycle.start(abstractlifecycle.java:69) @ io.dropwizard.cli.servercommand.run(servercommand.java:43) @ io.dropwizard.cli.environmentcommand.run(environmentcommand.java:43) @ io.dropwizard.cli.configuredcommand.run(configuredcommand.java:76) @ io.dropwizard.cli.cli.run(cli.java:70) @ io.dropwizard.application.run(application.java:72) @ com.sdata.report.reportapplication.main(reportapplication.java:12) caused by: com.sun.jersey.spi.inject.errors$errormessagesexception @ com.sun.jersey.spi.inject.errors.processerrormessages(errors.java:170) @ com.sun.jersey.spi.inject.errors.postprocess(errors.java:136) @ com.sun.jersey.spi.inject.errors.processwitherrors(errors.java:199) @ com.sun.jersey.server.impl.application.webapplicationimpl.initiate(webapplicationimpl.java:795) @ com.sun.jersey.server.impl.application.webapplicationimpl.initiate(webapplicationimpl.java:790) @ com.sun.jersey.spi.container.servlet.servletcontainer.initiate(servletcontainer.java:491) @ @ com.sun.jersey.spi.container.servlet.webcomponent.load(webcomponent.java:605) @ com.sun.jersey.spi.container.servlet.webcomponent.init(webcomponent.java:207) @ com.sun.jersey.spi.container.servlet.servletcontainer.init(servletcontainer.java:376) @ com.sun.jersey.spi.container.servlet.servletcontainer.init(servletcontainer.java:559) @ javax.servlet.genericservlet.init(genericservlet.java:244) @ org.eclipse.jetty.servlet.servletholder.initservlet(servletholder.java:540) ... 36 more warn [2014-10-27 18:24:54,795] /: unavailable

back basics. query parameter item after question mark in url, separated "&" symbol e.g.

yourwebsite.com/run?report=1&reportname=dogs

here 2 query params, report , reportname. should never have send complex object in request (what happens if paste address bar). can tell, query params easy parse long , string. no complex objects query params.

a path parameter item within url e.g.

yourwebsite.com/run/1

here there 1 path param, "1". it's path param because it's part of actual path, it's not info provided in query params (which optional).

you should send complex object (like report) in request post or set telling server update , providing multiple values.

so, you've explained pass object receiving end. this, should best alter @get annotation @post, path can remain same. not include complex object query param. instead, should posted json. dropwizard should deserialization, providing property names match up. endpoint can so:

@post @path("/run") public string runreport(report report) { // }

an illustration request perform post yourwebsite.com/run json like:

{ serialversionuid: 1, hashcode: 1, description: "xxx" }

also note, properties in study class should annotated @jsonproperty deserialized. if isn't clear, leave comment , can seek help.

java dropwizard

No comments:

Post a Comment