Page 1 of 1

About Question enthuware.ocejws.v6.2.193 :

Posted: Fri Apr 11, 2014 9:30 pm
by himaiMinh
I try /add/1999+1 in the addp(....) example.
But my result is 2000, instead of 10 (9+1)

I try /add/1999+1+1, I got an error:
javax.ws.rs.NotFoundException: Unable to extract parameter from http request for javax.ws.rs.PathParam("num") value is '1999+1'

Re: About Question enthuware.ocejws.v6.2.193 :

Posted: Sun Apr 13, 2014 3:13 am
by fjwalraven
Yes, don't spend too much time on this. The important thing to remember is that the "+" sign has a special meaning in regular expressions (regex) and regex is used in Path Strings.

In other words: you would never use a plus sign in a Path String in real life.

Regards,
Frits

Re: About Question enthuware.ocejws.v6.2.193 :

Posted: Sun Apr 13, 2014 7:32 am
by rkbansal83
Explaination for the one of the option says
Although this is a correct declaration, the "+" sign is interpreted by JAX-RS as a special regular expression character. It will add the last two numbers in the given URL: http://localhost:8080/SimpleRS/jax/rs/a ... 9a6--..469 will result in 15 (6+9)
I did not get this ? How can this type of URL having so many "+" be resolved to some method which accepts only single "+" in as mentioned its @Path declaration.

Re: About Question enthuware.ocejws.v6.2.193 :

Posted: Tue Apr 15, 2014 9:49 am
by fjwalraven
Please don't spend too much time on this. Not all application servers can handle a plus "+" in the URL (especially Glassfish goes wrong here, just try and see!)

Regards,
Frits

Re: About Question enthuware.ocejws.v6.2.193 :

Posted: Mon Nov 21, 2016 12:18 am
by johnlong
Hi

2 Questions :
1) https://jsr311.java.net/nonav/releases/ ... Param.html
It does not say here that List<T> where T is String is supported.

2) Can you have spaces in URL? Or " plus " is ignored here?
@Path("/add/{num1} plus {num2}")

Re: About Question enthuware.ocejws.v6.2.193 :

Posted: Wed Nov 23, 2016 12:19 am
by fjwalraven
1) https://jsr311.java.net/nonav/releases/ ... Param.html
It does not say here that List<T> where T is String is supported.
You can find it in the JAX-RS specs v1.1 and in the Jersey manual https://jersey.java.net/documentation/1 ... guide.html:
In general the Java type of the method parameter may:
1. Be a primitive type;
2. Have a constructor that accepts a single String argument;
3. Have a static method named valueOf or fromString that accepts a single String argument (see, for example, Integer.valueOf(String) and
java.util.UUID.fromString(String)); or
4. Be List<T>, Set<T> or SortedSet<T>, where T satisfies 2 or 3 above. The resulting collection is read-only.
2) Can you have spaces in URL? Or " plus " is ignored here?
@Path("/add/{num1} plus {num2}")
Yes, spaces are allowed, from JAX-RS v1.1:
3.4 URI Templates
The value of the annotation is automatically encoded, e.g. the following two lines are equivalent:
1 @Path("widget list/{id}")
2 @Path("widget%20list/{id}")
Regards,
Frits