Page 1 of 1

About Question enthuware.ocejws.v6.2.185 :

Posted: Tue May 13, 2014 8:23 pm
by evefuji
why cannot be @Produces("text/plain")?

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

Posted: Wed May 14, 2014 12:55 am
by fjwalraven
Hi !

The Accept header of a browser sends out will have the following elements: "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"

which is read as:
1) I prefer "text/html" and "application/xhtml+xml" (q=100% or q=1.0 in this case) , but because "text/html" is mentioned first I will look for a method that has a @Produces of "text/html", if that is not available I will look for a method that has a @Produces of "application/xhtml+xml".

2) If both media types of 1) are not available, I will look for a method that produces "application/xml" (q is 90%), and if that is also not available, I will look for a method that produces all media types "*/*" (q=80%). "text/plain" will fall under the "*/*" category.

In other words if both methods are in the same resource file, JAX-RS will invoke the one that produces "text/html".

Regards,
Frits

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

Posted: Sat Nov 08, 2014 1:02 pm
by austinor
I'm copying the entire question and all 4 answer choices below:

Code: Select all

We have AddressConverter RESTful Web Service on the base URL "/SimpleRS/rs" and a root resource with a path of convert. The Web Service returns the Address on the basis of the zip code (zipCode) and the house number (houseNumber). The URL we are requesting from a browser is: 

"http://localhost:8080/SimpleRS/rs/convert?zip=5000&hnr=12"  

Which of the following methods is executed? Assume that all methods are in the same resource class.

A.
@GET 
@Produces("text/plain") 
public String getPText( @QueryParam("zip") int zipCode, @QueryParam("hnr") int houseNumber ) {
    String address = convert( zipCode, houseNumber );
    return address; 
}

B.
@GET 
@Produces("text/html") 
public String getPText( @QueryParam("zip") int zipCode, @QueryParam("hnr") int houseNumber ) {
    String address = convert( zipCode, houseNumber );
    return address; 
}

C.
@GET 
@Produces("application/json") 
public String getPText( @QueryParam("zip") int zipCode, @QueryParam("hnr") int houseNumber ) {
    String address = convert( zipCode, houseNumber );
    return address; 
}

D.
@GET 
public String getPText( @QueryParam("zip") int zipCode, @QueryParam("hnr") int houseNumber ) {
    String address = convert( zipCode, houseNumber );
    return address; 
}
I won't bother to show the correct answer here, but I'd just like to check my understanding of other aspects of the JAX-RS request processing with this question (because I think I have a hunch):

If we remove answer choice B, what would happen? (For completeness' sake, let's add "E. None of the above".)

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

Posted: Sun Nov 09, 2014 3:19 am
by fjwalraven
If we remove answer choice B, what would happen? (For completeness' sake, let's add "E. None of the above".)
Choice D would be the correct answer then.

The algorithm first checks if there is a resource method annotated with @Produces("text/html"), then @Produces("application/xhtml+xml"), @Produces("application/xml"), and finally @Produces("*/*")

The first 3 @Produces are not found, the last one @Produces("*/*") applies to any method that is annotated with @Produces("*/*") or not annotated at all (a method with @GET without a @Produces annotation).

Hence option D would be correct if option B was removed.

Regards,
Frits
n.b. no need to copy the whole question setup here.

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

Posted: Sun Nov 08, 2015 9:31 am
by ramy6_1
Hello ,

So you mean if the first option available

@GET @Produces("text/plain") public String getPText(@QueryParam("zip") int zipCode,           @QueryParam("hnr") int houseNumber) {    String address = convert(zipCode, houseNumber);    return address; }

And the same HTTP request from the browser.

Browser will return 405 Method not allowed ?

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

Posted: Sun Nov 08, 2015 2:33 pm
by fjwalraven
No, just read the explanation to this question.

Regards,
Frits

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

Posted: Mon Nov 09, 2015 9:36 am
by belenzo
Hi fjwalraven,

Mabuhay (Greetings from the Philippines)! :D
I answered this incorrectly. :(
I chose:

Code: Select all

@GET 
public String getPText(@QueryParam("zip") int zipCode, @QueryParam("hnr") int houseNumber) {    
    String address = convert(zipCode, houseNumber);    
return address; }
Please confirm, are you saying that when an ACCEPT header is not specified programmatically, the browser will have the ACCEPT header value of "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" by default? Is that what you mean?

Thanks in advanced!
- Jasper

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

Posted: Mon Nov 09, 2015 10:08 am
by fjwalraven
Hi Jasper!
Please confirm, are you saying that when an ACCEPT header is not specified programmatically, the browser will have the ACCEPT header value of "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" by default? Is that what you mean?
Yes, exactly!

Regards,
Frits

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

Posted: Tue Nov 15, 2016 7:14 pm
by sttaq0442
fjwalraven wrote:Hi Jasper!
Please confirm, are you saying that when an ACCEPT header is not specified programmatically, the browser will have the ACCEPT header value of "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" by default? Is that what you mean?
Yes, exactly!

Regards,
Frits
hmmm this is not true for all browsers. For example Chrome and Safari don't have the same accept header. See here.

So, I think the accept header should be specified in the question.

For the exam, can you confirm if it is safe to assume the header you have mentioned?

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

Posted: Wed Nov 16, 2016 1:40 am
by fjwalraven
hmmm this is not true for all browsers. For example Chrome and Safari don't have the same accept header.
True, the Accept values will differ from browser to browser but all of them will start with "text/html".

current values:
Firefox:
text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8

Chrome
text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8

IE/Edge
text/html, application/xhtml+xml, image/jxr, */*
For the exam, can you confirm if it is safe to assume the header you have mentioned?
Yes, for the exam you will be given the Accept header.

Regards,
Frits

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

Posted: Wed Nov 16, 2016 6:01 am
by sttaq0442
fjwalraven wrote:
hmmm this is not true for all browsers. For example Chrome and Safari don't have the same accept header.
True, the Accept values will differ from browser to browser but all of them will start with "text/html".

current values:
Firefox:
text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8

Chrome
text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8

IE/Edge
text/html, application/xhtml+xml, image/jxr, */*
For the exam, can you confirm if it is safe to assume the header you have mentioned?
Yes, for the exam you will be given the Accept header.

Regards,
Frits
Thanks for the clarification