About Question enthuware.ocejws.v6.2.185 :
Moderators: Site Manager, fjwalraven
-
- Posts: 21
- Joined: Fri Apr 11, 2014 8:57 pm
- Contact:
About Question enthuware.ocejws.v6.2.185 :
why cannot be @Produces("text/plain")?
-
- Posts: 429
- Joined: Tue Jul 24, 2012 2:43 am
- Contact:
Re: About Question enthuware.ocejws.v6.2.185 :
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
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
-
- Posts: 41
- Joined: Mon Oct 27, 2014 11:35 pm
- Contact:
Re: About Question enthuware.ocejws.v6.2.185 :
I'm copying the entire question and all 4 answer choices below:
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".)
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;
}
If we remove answer choice B, what would happen? (For completeness' sake, let's add "E. None of the above".)
-
- Posts: 429
- Joined: Tue Jul 24, 2012 2:43 am
- Contact:
Re: About Question enthuware.ocejws.v6.2.185 :
Choice D would be the correct answer then.If we remove answer choice B, what would happen? (For completeness' sake, let's add "E. None of the above".)
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.
-
- Posts: 124
- Joined: Wed Feb 12, 2014 2:44 am
- Contact:
Re: About Question enthuware.ocejws.v6.2.185 :
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 ?
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 ?
-
- Posts: 429
- Joined: Tue Jul 24, 2012 2:43 am
- Contact:
Re: About Question enthuware.ocejws.v6.2.185 :
No, just read the explanation to this question.
Regards,
Frits
Regards,
Frits
-
- Posts: 1
- Joined: Mon Nov 09, 2015 9:21 am
- Contact:
Re: About Question enthuware.ocejws.v6.2.185 :
Hi fjwalraven,
Mabuhay (Greetings from the Philippines)!
I answered this incorrectly.
I chose:
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
Mabuhay (Greetings from the Philippines)!
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; }
Thanks in advanced!
- Jasper
-
- Posts: 429
- Joined: Tue Jul 24, 2012 2:43 am
- Contact:
Re: About Question enthuware.ocejws.v6.2.185 :
Hi Jasper!
Regards,
Frits
Yes, exactly!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?
Regards,
Frits
-
- Posts: 27
- Joined: Tue Nov 15, 2016 11:20 am
- Contact:
Re: About Question enthuware.ocejws.v6.2.185 :
hmmm this is not true for all browsers. For example Chrome and Safari don't have the same accept header. See here.fjwalraven wrote:Hi Jasper!
Yes, exactly!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?
Regards,
Frits
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?
-
- Posts: 429
- Joined: Tue Jul 24, 2012 2:43 am
- Contact:
Re: About Question enthuware.ocejws.v6.2.185 :
True, the Accept values will differ from browser to browser but all of them will start with "text/html".hmmm this is not true for all browsers. For example Chrome and Safari don't have the same accept header.
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, */*
Yes, for the exam you will be given the Accept header.For the exam, can you confirm if it is safe to assume the header you have mentioned?
Regards,
Frits
-
- Posts: 27
- Joined: Tue Nov 15, 2016 11:20 am
- Contact:
Re: About Question enthuware.ocejws.v6.2.185 :
Thanks for the clarificationfjwalraven wrote:True, the Accept values will differ from browser to browser but all of them will start with "text/html".hmmm this is not true for all browsers. For example Chrome and Safari don't have the same accept header.
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, */*
Yes, for the exam you will be given the Accept header.For the exam, can you confirm if it is safe to assume the header you have mentioned?
Regards,
Frits
Who is online
Users browsing this forum: No registered users and 3 guests