I am still having some trouble with creating a put method. Using the
dropwizard-example from github, in my Person.java class I have an update
sql statement "@NamedQuery(
name = "com.example.helloworld.core.Person.update",
query = "UPDATE Person p SET p.start=:start, p.end=:end where
p.id=:id"
)"
and in my PersonDAO.java class, I have a method called update " * public
List<Person> update(Long id, Person person) {*
* return
list(namedQuery("com.example.helloworld.core.Person.update").setLong("id",id)*
*
.setInteger("start",person.getStart())*
*
.setInteger("end",person.getEnd()));*
* }*"
and under PersonResource.java, I have the@put Method,
* @PUT*
* @UnitOfWork*
* public List<Person> updatePerson(@PathParam("personId") LongParam
personId,Person person) {*
* return peopleDAO.update(personId.get(),person);*
* }*
*when i test my put method, I get this error INFO [16:05:33.430] [dw-49 -
PUT /people/2] o.h.e.i.StatisticalLoggingSessionEventListener - Session
Metrics {*
* 60159 nanoseconds spent acquiring 1 JDBC connections;*
* 0 nanoseconds spent releasing 0 JDBC connections;*
* 0 nanoseconds spent preparing 0 JDBC statements;*
* 0 nanoseconds spent executing 0 JDBC statements;*
* 0 nanoseconds spent executing 0 JDBC batches;*
* 0 nanoseconds spent performing 0 L2C puts;*
* 0 nanoseconds spent performing 0 L2C hits;*
* 0 nanoseconds spent performing 0 L2C misses;*
* 0 nanoseconds spent executing 0 flushes (flushing a total of 0
entities and 0 collections);*
* 0 nanoseconds spent executing 0 partial-flushes (flushing a total of 0
entities and 0 collections)*
*} *
*ERROR [16:05:33.431] [dw-49 - PUT /people/2]
i.d.j.e.LoggingExceptionMapper - Error handling a request:
e27fe462c112d5ca *
*java.lang.NullPointerException: null*
* at com.example.helloworld.db.PersonDAO.update(PersonDAO.java:27)*
* at
com.example.helloworld.resources.PersonResource.updatePerson(PersonResource.java:46)*
* at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)*
* at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)*
* at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)*
Am I doing something incorrectly? I looked at other examples and emulate
what they did. Essentially i want to implement a put method in the
dropwizard example in github.
On Mon, Sep 26, 2016 at 6:20 PM, Evan Meagher <[email protected]>
wrote:
> If the resource method arguments and return type are the same, then yes.
>
> On Mon, Sep 26, 2016 at 1:36 PM, Ervin Wu <[email protected]> wrote:
>
>> Hey Evan,
>>
>> Thanks for your response! I have a quick clarification, does that mean I
>> can reuse the POST code and just change the POST method to PUT method?
>>
>> On Mon, Sep 26, 2016 at 4:18 PM, Evan Meagher <[email protected]>
>> wrote:
>>
>>> Hello Ervin,
>>>
>>> PUT endpoints can be implemented in the same way as POST endpoints,
>>> except that you use the @PUT annotation. See Jersey documentation for
>>> details: https://jersey.java.net/documentation/latest/jaxrs-
>>> resources.html#d0e2083
>>>
>>> On Mon, Sep 26, 2016 at 1:12 PM, <[email protected]> wrote:
>>>
>>>> I am currently using your dropwizard-example (latest version) as a
>>>> guide for my project. I was curious on how to send put requests, so that
>>>> the resource gets updated in the database. I was trying to created an
>>>> update method in the PersonDAO class but was having trouble finding
>>>> documentation on how to do so. I have a @POST request in
>>>> PERSONRESOURCE.java, which calls the update method for the database. I
>>>> couldn't find a lot of documentation on creating PUT requests and updating
>>>> the database. There are any tips that you may suggest?
>>>>
>>>> --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "dropwizard-user" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>> an email to [email protected].
>>>> For more options, visit https://groups.google.com/d/optout.
>>>>
>>>
>>>
>>>
>>> --
>>> Evan Meagher
>>>
>>> --
>>> You received this message because you are subscribed to a topic in the
>>> Google Groups "dropwizard-user" group.
>>> To unsubscribe from this topic, visit https://groups.google.com/d/to
>>> pic/dropwizard-user/T0AP1tH7svk/unsubscribe.
>>> To unsubscribe from this group and all its topics, send an email to
>>> [email protected].
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>>
>> --
>> Thanks,
>> Ervin Wu
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "dropwizard-user" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> --
> Evan Meagher
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "dropwizard-user" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/
> topic/dropwizard-user/T0AP1tH7svk/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> [email protected].
> For more options, visit https://groups.google.com/d/optout.
>
--
Thanks,
Ervin Wu
--
You received this message because you are subscribed to the Google Groups
"dropwizard-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.