0

I'm using the following code to create WebService without configuration in web.xml like described here: How to set up JAX-RS Application using annotations only (no web.xml)?

@ApplicationPath("/host")
@Path("/merge")
public class FormProvider extends Application {


    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public String getFormByKey(@QueryParam("key") String key) {

        Form form = DB.getFormByKey(key);
        Gson gson = new GsonBuilder()
        .setPrettyPrinting()
        .create();
        String json = gson.toJson(form);

        return json;
    }
}

And using following URL to invoke WebService with parameters:

http://localhost:9081/MyRestApplication/host/merge?key=xyz123

Webservice being invoked but property key remains empty, what am I doing wrong? Thank you.

Update: It began to work. I can't explain but I just removed jax-rs library, turned-off server and then turned-on and added library (same library) back and it began to work. Before it I tried to perform clean, build, nothing helped. If somebody will be able to explain what and why did it happen, I will accept it as answer. Thank you.

Community
  • 1
  • 1
Anatoly
  • 5,056
  • 9
  • 62
  • 136

1 Answers1

0

You do not have a "key" parameter in your query. Change it to:

http://localhost:9081/MyRestApplication/host/merge?key=xyz123
olexd
  • 1,360
  • 3
  • 13
  • 26
  • Sorry, I checked with `key` and with `test` and in both cases it didn't work. Just copied here wrong code, will fix it. – Anatoly May 26 '15 at 15:19