Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #35755
| From | Arne Vajhøj <arne@vajhoej.dk> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Rest parameter without value |
| Date | 2016-10-14 14:49 -0400 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <ntr9b4$1v2r$1@gioia.aioe.org> (permalink) |
| References | <m3lgxr8681.fsf@saunalahti.fi> |
On 10/14/2016 8:28 AM, Jukka Lahtinen wrote:
> I have been working with java, but REST is new to me.
> Now I am working on a REST client for the first time.
> I have already managed to use a rest request with a path parameter and
> another one with query parameters.
>
> Now the request with a path parameter should in some occasions contain a
> parameter without a value.
> What I have tried looks essentially like this:
>
> String url = "http://machine/path/v3.0/{keyvalue}";
> Private javax.ws.rs.Client client; // initialized in the constructor
> ..
>
> private Object makeCall(String keyvalue, boolean b) {
> UriBuilder builder = UriBuilder.fromUri( url ).path( path ).
> resolveTemplate( "keyvalue", keyvalue );
> WebTarget target = client.target( builder );
> if (b) {
> target = target.queryParam("foo", "");
> }
> Response resp = target.request().headers(makeHeaders()).get();
> Object ret = null;
> ..
> // resp handling not shown here
> ..
> return ret;
> }
>
> Debugging this, I lookd at target after the target.queryParam call and
> noticed that target contains a ResteasyUriBuilder object uriBuilder,
> where the attribute "query" now contains "foo=".
> So this apparently will make the actual url look like this:
>
> http://machine/path/v3.0/keyvalue?foo=
>
> But I need it without the equals at the end. How do I do that?
>
> I also tried passing null to the target.queryParam call instead of the
> empty String,
> target = target.queryParam("foo", null);
> but that way target.uriBuildeer.query remains null.
The API may not support it, because it does not make much sense
in REST.
http://host/resource ~= SELECT * FROM resource
http://host/resource/value ~= SELECT * FROM resource WHERE id = value
http://host/resource?nam=val ~= SELECT * FROM resource WHERE nam=val
http://host/resource?nam ~= ????
But as fallback mechanism you can always drop the JAX-RS client classes
and revert to Java HttpURLCOnnection or Apache HttpClient with a JSON
library. That gives you full freedom to do whatever you want.
Arne
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Rest parameter without value Jukka Lahtinen <jtfjdehf@hotmail.com.invalid> - 2016-10-14 15:28 +0300
Re: Rest parameter without value Arne Vajhøj <arne@vajhoej.dk> - 2016-10-14 14:49 -0400
Re: Rest parameter without value Jukka Lahtinen <jtfjdehf@hotmail.com.invalid> - 2016-10-17 08:48 +0300
Re: Rest parameter without value Jukka Lahtinen <jtfjdehf@hotmail.com.invalid> - 2016-10-17 09:50 +0300
Re: Rest parameter without value 4ndre4 <626401fd-4bc7-4f8f-b641-563ae0f72920@626401fd-4bc7-4f8f-b641-563ae0f72920.invalid> - 2016-10-14 21:16 +0100
Re: Rest parameter without value Jukka Lahtinen <jtfjdehf@hotmail.com.invalid> - 2016-10-17 08:30 +0300
csiph-web