tags:

views:

952

answers:

4

I have a simple WS that is a @PUT and takes in an object

@Path("test")
public class Test {

    @PUT
    @Path("{nid}"}
    @Consumes("application/xml")
    @Produces({"application/xml", "application/json"})
    public WolResponse callWol(@PathParam("nid") WolRequest nid) {
        WolResponse response = new WolResponse();
        response.setResult(result);
        response.setMessage(nid.getId());

        return response;
    }

and my client side code is...

WebResource wr = client.resource(myurl);
WolResponse resp = wr.accept("application/xml").put(WolResponse.class, wolRequest);

I am trying to pass an instance of WolRequest into the @PUT Webservice. I am constantly getting 405 errors trying to do this..

How can I pass an object from the client to the server via Jersey ? Do I use a query param or the request ?

Both my POJOs (WolRequest and WolResponse) have the XMlRootElement tag defined so i can produce and consume xml..

A: 

anyone ? id really appreciate any insight

matchan
please don't *bump* questions like this.
skaffman
A: 

405 is "method not allowed". Do you need to configure your web server to allow PUT?

Licky Lindsay
A: 

I think the usage of the @PathParam is not correct here. A @PathParam is can basically be a String (see its javadoc for more info).

You can 1) use the @PathParam as a String parameter or 2) don't define WolRequest as a @PathParam.

1)

@Path("test")
public class Test {

    @PUT
    @Path("{nid}"}
    @Consumes("application/xml")
    @Produces({"application/xml", "application/json"})
    public WolResponse callWol(@PathParam("nid") String nid) {
        WolResponse response = new WolResponse();
        response.setResult(result);
        response.setMessage(nid);

        return response;
    }

This will accept urls like: "text/12", 12 will then be the String nid. It doesn't look like this will help what you are trying to do.

or

2)

@Path("test")
public class Test {

    @PUT
    @Consumes("application/xml")
    @Produces({"application/xml", "application/json"})
    public WolResponse callWol(WolRequest nid) {
        WolResponse response = new WolResponse();
        response.setResult(result);
        response.setMessage(nid.getId());

        return response;
    }

Your client code can be like you specified, only the url for PUT is: "test". Perhaps you need a combination of both one @PathParam for your id and one "normal" parameter to get your request data.

I hope this helps.

PD
A: 

Hey,

Check this link http://www.vogella.de/articles/REST/article.html

As per the code sample of method putTodo of class TodoResource , your code should be like this.

@Path("test") public class Test {

@PUT
@Consumes("application/xml")
@Produces({"application/xml", "application/json"})
public WolResponse callWol(JAXBElement<WolRequest> nid) {
    WolResponse response = new WolResponse();
    response.setResult(result);
    response.setMessage(nid.getValue().getId());

    return response;
}

Hope this will solve your problem.

Cheers

carbontrans