JAX RS – 22 – Server Response Code

Merhaba Arkadaslar
Bu bolumde HTTP Response kodlarini inceleyecegiz.
Basarili/Successful HTTP respsonse code’lari [200,399] arasinda bir degere sahiptir.

HTTPResponseResource.java

//imports
@Path(value = "/http-response")
public class HTTPResponseResource {

	@GET
	@Path("/response200")
	public String response200() {
		String message = "response200 is called.";
		return message;
	}
}

Ornegimizi calistirdigimizda , Chrome’da Network sekmesinde Status Code 200 olarak gorebiliriz.
Response Code 200 “OK” anlamina gelmektedir.

Ornegimizi calistiralim ;

http://localhost:8080/injavawetrust.jersey.tutorial/http-response/response200
http://localhost:8080/injavawetrust.resteasy.tutorial/http-response/response200

response200

Eger donus null ya da void olursa Response Code 204 olacaktir. Response Code 204 “No Content” anlamina gelmektedir. 204 Response Code bir error code degildir.

HTTPResponseResource.java

	@GET
	@Path("/responseNull")
	// HTTP Response Code : 204
	public String responseNull() {
		System.out.println("responseNull is called.");
		return null;
	}

Ornegimizi calistiralim ;

http://localhost:8080/injavawetrust.resteasy.tutorial/http-response/responseNull
http://localhost:8080/injavawetrust.jersey.tutorial/http-response/responseNull

responsenull

void return type , delete ve update metotlari icin uygun olacaktir.

HTTPResponseResource.java

	@DELETE
	@Path("/person/{id}")
	// HTTP Response Code : 204
	// Send HTTP DELETE

	// void return type is meaningful for delete , update methods.

	public void delete(@PathParam("id") int id) {
		System.out.println("Person is deleted...");
	}

Ornegimizi calistirdigimizda, burada HTTP DELETE methodu kullandigimiza dikkat edelim.

http://localhost:8080/injavawetrust.jersey.tutorial/http-response/person/1
http://localhost:8080/injavawetrust.resteasy.tutorial/http-response/person/1

response-204

Standard HTPP Error Response Code’lari [400-599] araliginda deger almaktadir.
Eger aranan resource server’da bulunamazsa geriye Response Code 404 donecektir.
Response Code 404 , “Not Found” anlamina gelmektedir.

Eger ilgili resource beklediginden farkli bir HTTP Method Type ile gidersek bu durumda Response Code 405 , “Method Not Allowed” cevap olarak donecektir.

Bu durum Jersey icin gecerlidir ,  RESTEasy icin exception firlatilir.

javax.ws.rs.NotAllowedException: RESTEASY003650: 
No resource method found for GET, return 405 with Allow header

HTTPResponseResource.java

	
	@POST
	@Path("/response405")
	// send with HTTP GET

	// RESTEasy
	// javax.ws.rs.NotAllowedException: RESTEASY003650: No resource method found
	// for GET, return 405 with Allow header
	
	// Jersey
	// HTTP Response Code : 405
	// HTTP Status 405 - Method Not Allowed
	public String response405() {
		String message = "response405 is called.";
		return message;
	}

Ornegimizi calistirdigimizda ;

http://localhost:8080/injavawetrust.jersey.tutorial/http-response/response405
http://localhost:8080/injavawetrust.resteasy.tutorial/http-response/response405

response-405

Github kaynak kodlar / source folder
injavawetrust.resteasy
injavawetrust.jersey

Yazimi burada sonlandiriyorum.
Herkese Bol Javali Gunler dilerim.
Be an oracle man , import java.*;
Levent Erguder
OCP, Java SE 6 Programmer
OCE, Java EE 6 Web Component Developer

Print Friendly

Leave a Reply

Your email address will not be published. Required fields are marked *