About Question enthuware.ocejws.v6.2.193 :

Moderators: Site Manager, fjwalraven

Post Reply
himaiMinh
Posts: 358
Joined: Fri Nov 29, 2013 8:26 pm
Contact:

About Question enthuware.ocejws.v6.2.193 :

Post 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'

fjwalraven
Posts: 429
Joined: Tue Jul 24, 2012 2:43 am
Contact:

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

Post 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

rkbansal83
Posts: 33
Joined: Sat Nov 24, 2012 8:52 am
Contact:

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

Post 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.

fjwalraven
Posts: 429
Joined: Tue Jul 24, 2012 2:43 am
Contact:

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

Post 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

johnlong
Posts: 197
Joined: Mon Jun 20, 2016 5:06 pm
Contact:

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

Post 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}")

fjwalraven
Posts: 429
Joined: Tue Jul 24, 2012 2:43 am
Contact:

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

Post 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

Post Reply

Who is online

Users browsing this forum: No registered users and 22 guests